import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; describe('Travel descriptor path', () => { let browser; let page; beforeAll(async() => { browser = await getBrowser(); page = browser.page; await page.loginAndModule('buyer', 'travel'); await page.accessToSearchResult('1'); await page.waitForState('travel.card.summary'); }); afterAll(async() => { await browser.close(); }); it('should click the descriptor button to navigate to the travel index showing all travels with current agency', async() => { await page.waitToClick(selectors.travelDescriptor.filterByAgencyButton); await page.waitForState('travel.index'); const result = await page.countElement(selectors.travelIndex.anySearchResult); expect(result).toBeGreaterThanOrEqual(7); }); it('should navigate to the first search result', async() => { await page.waitToClick(selectors.travelIndex.firstSearchResult); await page.waitForState('travel.card.summary'); const state = await page.getState(); expect(state).toBe('travel.card.summary'); }); it('should be redirected to the create entry view', async() => { await page.waitToClick(selectors.travelDescriptor.dotMenu); await page.waitToClick(selectors.travelDescriptor.dotMenuAddEntry); await page.waitForState('entry.create'); const state = await page.getState(); expect(state).toBe('entry.create'); }); it('should check some data was imported from the travel', async() => { const travel = await page.waitToGetProperty(selectors.entryCreate.travel, 'value'); const campany = await page.waitToGetProperty(selectors.entryCreate.company, 'value'); expect(travel).toContain('Warehouse'); expect(campany).toContain('VNL'); }); it('should navigate back to the travel index', async() => { await page.waitToClick('.cancel'); await page.waitToClick(selectors.globalItems.homeButton); await page.selectModule('travel'); await page.waitForState('travel.index'); const state = await page.getState(); expect(state).toBe('travel.index'); }); it('should click on the add entry button of the third result to be redirected to create entry', async() => { await page.keyboard.press('Enter'); await page.waitToClick(selectors.travelIndex.firstTravelAddEntryButton); await page.waitForState('entry.create'); const state = await page.getState(); expect(state).toBe('entry.create'); }); it('should check again some data was imported from the travel', async() => { const travel = await page.waitToGetProperty(selectors.entryCreate.travel, 'value'); const campany = await page.waitToGetProperty(selectors.entryCreate.company, 'value'); expect(travel).toContain('Warehouse'); expect(campany).toContain('VNL'); }); it('should navigate to the travel summary of a given travel', async() => { await page.waitToClick('.cancel'); await page.waitToClick(selectors.globalItems.homeButton); await page.selectModule('travel'); await page.accessToSearchResult('3'); await page.waitForState('travel.card.summary'); const state = await page.getState(); expect(state).toBe('travel.card.summary'); }); it('should be redirected to the create travel when using the clone option of the dot menu', async() => { await page.waitToClick(selectors.travelDescriptor.dotMenu); await page.waitToClick(selectors.travelDescriptor.dotMenuClone); await page.respondToDialog('accept'); await page.waitForState('travel.create'); const state = await page.getState(); expect(state).toBe('travel.create'); }); it('should edit the data to clone and then get redirected to the cloned travel basic data', async() => { await page.clearInput(selectors.travelCreate.reference); await page.write(selectors.travelCreate.reference, 'reference'); await page.autocompleteSearch(selectors.travelCreate.agency, 'entanglement'); await page.pickDate(selectors.travelCreate.shipped); await page.pickDate(selectors.travelCreate.landed); await page.autocompleteSearch(selectors.travelCreate.warehouseOut, 'warehouse one'); await page.autocompleteSearch(selectors.travelCreate.warehouseIn, 'warehouse two'); await page.waitToClick(selectors.travelCreate.saveButton); await page.waitForState('travel.card.basicData'); const message = await page.waitForSnackbar(); expect(message.text).toContain('Data saved!'); }); it('should update the landed date to a future date to enable cloneWithEntries', async() => { const nextMonth = Date.vnNew(); nextMonth.setMonth(nextMonth.getMonth() + 1); await page.pickDate(selectors.travelBasicData.deliveryDate, nextMonth); await page.waitToClick(selectors.travelBasicData.save); await page.waitForState('travel.card.basicData'); const message = await page.waitForSnackbar(); expect(message.text).toContain('Data saved!'); }); it('should navigate to the summary and then clone the travel and its entries using the descriptor menu to get redirected to the cloned travel basic data', async() => { await page.waitToClick('vn-icon[icon="launch"]'); await page.waitForState('travel.card.summary'); await page.waitForTimeout(1000); await page.waitToClick(selectors.travelDescriptor.dotMenu); await page.waitToClick(selectors.travelDescriptor.dotMenuCloneWithEntries); await page.waitToClick(selectors.travelDescriptor.acceptClonation); await page.waitForState('travel.card.basicData'); }); });