import selectors from '../../helpers/selectors.js'; import createNightmare from '../../helpers/nightmare'; describe('Ticket services path', () => { const nightmare = createNightmare(); const invoicedTicketId = 1; describe('as employee', () => { beforeAll(() => { nightmare .loginAndModule('employee', 'ticket') .accessToSearchResult(invoicedTicketId) .accessToSection('ticket.card.service'); }); it('should find the add descripton button disabled for this user role', async() => { const result = await nightmare .waitForClassPresent(selectors.ticketService.firstAddServiceTypeButton, 'disabled') .waitToClick(selectors.ticketService.addServiceButton) .wait(selectors.ticketService.firstAddServiceTypeButton) .isDisabled(selectors.ticketService.firstAddServiceTypeButton); expect(result).toBeTruthy(); }, 100000); it('should receive an error if you attempt to save a service without access rights', async() => { const result = await nightmare .clearInput(selectors.ticketService.firstPriceInput) .write(selectors.ticketService.firstPriceInput, 999) .waitToClick(selectors.ticketService.saveServiceButton) .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() => { const url = await nightmare .loginAndModule('administrative', 'ticket') .accessToSearchResult(editableTicketId) .accessToSection('ticket.card.service') .waitForURL('/service') .parsedUrl(); expect(url.hash).toContain('/service'); }); it('should click on the add button to prepare the form to create a new service', async() => { const result = await nightmare .waitToClick(selectors.ticketService.addServiceButton) .isVisible(selectors.ticketService.firstServiceTypeAutocomplete); expect(result).toBeTruthy(); }); it('should receive an error if you attempt to save it with empty fields', async() => { const result = await nightmare .waitToClick(selectors.ticketService.saveServiceButton) .waitForLastSnackbar(); expect(result).toEqual(`can't be blank`); }); it('should click on the add new service type to open the dialog', async() => { const result = await nightmare .waitToClick(selectors.ticketService.firstAddServiceTypeButton) .wait('.vn-dialog.shown') .isVisible(selectors.ticketService.newServiceTypeNameInput); expect(result).toBeTruthy(); }); it('should receive an error if service type is empty on submit', async() => { const result = await nightmare .waitToClick(selectors.ticketService.saveServiceTypeButton) .waitForLastSnackbar(); expect(result).toEqual(`Name can't be empty`); }); it('should create a new service type then add price then create the service', async() => { const result = await nightmare .write(selectors.ticketService.newServiceTypeNameInput, 'Documentos') .autocompleteSearch(selectors.ticketService.newServiceTypeExpenseAutocomplete, 'Retencion') .waitToClick(selectors.ticketService.saveServiceTypeButton) .write(selectors.ticketService.firstPriceInput, 999) .waitToClick(selectors.ticketService.saveServiceButton) .waitForLastSnackbar(); expect(result).toEqual('Data saved!'); }); it('should confirm the service description was created correctly', async() => { const result = await nightmare .reloadSection('ticket.card.service') .waitToGetProperty(`${selectors.ticketService.firstServiceTypeAutocomplete} input`, 'value'); expect(result).toEqual('Documentos'); }); it('should confirm the service quantity was created correctly', async() => { const result = await nightmare .waitToGetProperty(selectors.ticketService.firstQuantityInput, 'value'); expect(result).toEqual('1'); }); it('should confirm the service price was created correctly', async() => { const result = await nightmare .waitToGetProperty(selectors.ticketService.firstPriceInput, 'value'); expect(result).toEqual('999'); }); it('should confirm the service VAT was created correctly', async() => { const result = await nightmare .waitToGetProperty(`${selectors.ticketService.firstVatTypeAutocomplete} input`, 'value'); expect(result).toEqual('General VAT'); }); it('should delete the service', async() => { const result = await nightmare .waitToClick(selectors.ticketService.fistDeleteServiceButton) .waitForNumberOfElements(selectors.ticketService.serviceLine, 0) .waitToClick(selectors.ticketService.saveServiceButton) .waitForLastSnackbar(); expect(result).toEqual('Data saved!'); }); it(`should confirm the service was removed`, async() => { const result = await nightmare .reloadSection('ticket.card.service') .waitForNumberOfElements(selectors.ticketService.serviceLine, 0) .countElement(selectors.ticketService.serviceLine); expect(result).toEqual(0); }); }); });