import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; describe('Ticket create path', () => { let browser; let page; let nextMonth = Date.vnNew(); nextMonth.setMonth(nextMonth.getMonth() + 1); beforeAll(async() => { browser = await getBrowser(); page = browser.page; await page.loginAndModule('employee', 'ticket'); }); afterAll(async() => { await browser.close(); }); it('should open the new ticket form', async() => { await page.waitToClick(selectors.ticketsIndex.newTicketButton); await page.waitForState('ticket.create'); }); it('should succeed to create a ticket', async() => { await page.autocompleteSearch(selectors.createTicketView.client, 'Clark Kent'); await page.pickDate(selectors.createTicketView.deliveryDate, nextMonth); await page.autocompleteSearch(selectors.createTicketView.warehouse, 'Warehouse Two'); await page.autocompleteSearch(selectors.createTicketView.agency, 'Gotham247'); await page.waitToClick(selectors.createTicketView.createButton); const message = await page.waitForSnackbar(); expect(message.text).toContain('Data saved!'); }); it('should check the url is now the summary of the ticket', async() => { await page.waitForState('ticket.card.summary'); }); it('should again open the new ticket form', async() => { await page.waitToClick(selectors.globalItems.returnToModuleIndexButton); await page.waitToClick(selectors.ticketsIndex.newTicketButton); await page.waitForState('ticket.create'); }); it('should succeed to create another ticket for the same client', async() => { await page.autocompleteSearch(selectors.createTicketView.client, 'Clark Kent'); await page.pickDate(selectors.createTicketView.deliveryDate, nextMonth); await page.autocompleteSearch(selectors.createTicketView.warehouse, 'Warehouse One'); await page.autocompleteSearch(selectors.createTicketView.agency, 'Gotham247'); await page.waitToClick(selectors.createTicketView.createButton); const message = await page.waitForSnackbar(); expect(message.text).toContain('Data saved!'); }); it('should check the url is now the summary of the created ticket', async() => { await page.waitForState('ticket.card.summary'); }); it('should delete the current ticket', async() => { await page.waitToClick(selectors.ticketDescriptor.moreMenu); await page.waitToClick(selectors.ticketDescriptor.moreMenuDeleteTicket); await page.waitToClick(selectors.ticketDescriptor.acceptDialog); const message = await page.waitForSnackbar(); expect(message.text).toContain('Ticket deleted. You can undo this action within the first hour'); }); });