import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; describe('Ticket services path', () => { let browser; let page; const invoicedTicketId = '1'; afterAll(async() => { await browser.close(); }); describe('as employee', () => { it('should log in as employee, search for an invoice and get to services', async() => { browser = await getBrowser(); page = browser.page; await page.loginAndModule('employee', 'ticket'); await page.accessToSearchResult(invoicedTicketId); await page.accessToSection('ticket.card.service'); }); it('should find the add descripton button disabled for this user role', async() => { await page.waitForClassPresent(selectors.ticketService.firstAddServiceTypeButton, 'disabled'); await page.waitToClick(selectors.ticketService.addServiceButton); await page.wait(selectors.ticketService.firstAddServiceTypeButton); const result = await page.isDisabled(selectors.ticketService.firstAddServiceTypeButton); expect(result).toBeTruthy(); }, 15000); it('should receive an error if you attempt to save a service without access rights', async() => { await page.clearInput(selectors.ticketService.firstPrice); await page.write(selectors.ticketService.firstPrice, '999'); await page.waitToClick(selectors.ticketService.saveServiceButton); const result = await page.waitForLastSnackbar(); expect(result).toEqual(`The current ticket can't be modified`); }); }); describe('as administrative', () => { let editableTicketId = '16'; it('should navigate to the services of a target ticket', async() => { await page.loginAndModule('administrative', 'ticket'); await page.accessToSearchResult(editableTicketId); await page.accessToSection('ticket.card.service'); let url = await page.expectURL('/service'); expect(url).toBe(true); }); it('should click on the add button to prepare the form to create a new service', async() => { await page.waitForContentLoaded(); await page.waitToClick(selectors.ticketService.addServiceButton); const result = await page .isVisible(selectors.ticketService.firstServiceType); expect(result).toBeTruthy(); }); it('should receive an error if you attempt to save it with empty fields', async() => { await page.waitToClick(selectors.ticketService.saveServiceButton); const result = await page.waitForLastSnackbar(); expect(result).toEqual(`can't be blank`); }); it('should click on the add new service type to open the dialog', async() => { await page.waitToClick(selectors.ticketService.firstAddServiceTypeButton); await page.wait('.vn-dialog.shown'); const result = await page.isVisible(selectors.ticketService.newServiceTypeName); expect(result).toBeTruthy(); }); it('should receive an error if service type is empty on submit', async() => { await page.waitToClick(selectors.ticketService.saveServiceTypeButton); const result = await page.waitForLastSnackbar(); expect(result).toEqual(`Name can't be empty`); }); it('should create a new service type then add price then create the service', async() => { await page.write(selectors.ticketService.newServiceTypeName, 'Documentos'); await page.autocompleteSearch(selectors.ticketService.newServiceTypeExpense, 'Retencion'); await page.waitToClick(selectors.ticketService.saveServiceTypeButton); await page.write(selectors.ticketService.firstPrice, '999'); await page.waitFor(1000); // time needed for the button to be clickable await page.waitToClick(selectors.ticketService.saveServiceButton); const result = await page.waitForLastSnackbar(); expect(result).toEqual('Data saved!'); }); it('should confirm the service description was created correctly', async() => { await page.reloadSection('ticket.card.service'); const result = await page .waitToGetProperty(selectors.ticketService.firstServiceType, 'value'); expect(result).toEqual('Documentos'); }); it('should confirm the service quantity was created correctly', async() => { const result = await page .waitToGetProperty(selectors.ticketService.firstQuantity, 'value'); expect(result).toEqual('1'); }); it('should confirm the service price was created correctly', async() => { const result = await page .waitToGetProperty(selectors.ticketService.firstPrice, 'value'); expect(result).toEqual('999'); }); it('should confirm the service VAT was created correctly', async() => { const result = await page .waitToGetProperty(selectors.ticketService.firstVatType, 'value'); expect(result).toEqual('General VAT'); }); it('should delete the service', async() => { await page.waitToClick(selectors.ticketService.fistDeleteServiceButton); await page.waitForNumberOfElements(selectors.ticketService.serviceLine, 0); await page.waitFor(1000); // without this wait it fails to click the save button await page.waitToClick(selectors.ticketService.saveServiceButton); const result = await page.waitForLastSnackbar(); expect(result).toEqual('Data saved!'); }); it(`should confirm the service was removed`, async() => { await page.reloadSection('ticket.card.service'); await page.waitForNumberOfElements(selectors.ticketService.serviceLine, 0); const result = await page.countElement(selectors.ticketService.serviceLine); expect(result).toEqual(0); }); }); });