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 .waitToClick(selectors.ticketService.addServiceButton) .wait(selectors.ticketService.firstAddDescriptionButton) .evaluate(selector => { return document.querySelector(selector).disabled; }, selectors.ticketService.firstAddDescriptionButton); expect(result).toBeTruthy(); }); 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.firstDescriptionAutocomplete); 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 description to open the dialog', async() => { const result = await nightmare .waitToClick(selectors.ticketService.firstAddDescriptionButton) .waitForClassPresent('vn-ticket-service > vn-dialog', 'shown') .isVisible(selectors.ticketService.newDescriptionInput); expect(result).toBeTruthy(); }); it('should receive an error if description is empty on submit', async() => { const result = await nightmare .waitToClick(selectors.ticketService.saveDescriptionButton) .waitForLastSnackbar(); expect(result).toEqual(`Name can't be empty`); }); it('should create a new description then add price then create the service', async() => { const result = await nightmare .write(selectors.ticketService.newDescriptionInput, 'accurate description') .waitToClick(selectors.ticketService.saveDescriptionButton) .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.firstDescriptionAutocomplete} input`, 'value'); expect(result).toEqual('accurate description'); }); 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 wasn't sucessfully removed`, async() => { const result = await nightmare .reloadSection('ticket.card.service') .waitForNumberOfElements(selectors.ticketService.serviceLine, 0) .countElement(selectors.ticketService.serviceLine); expect(result).toEqual(0); }); }); });