import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; describe('Order edit basic data path', () => { let browser; let page; const today = new Date().getDate(); beforeAll(async() => { browser = await getBrowser(); page = browser.page; await page.loginAndModule('employee', 'order'); await page.accessToSearchResult('1'); await page.accessToSection('order.card.basicData'); }); afterAll(async() => { await browser.close(); }); describe('when confirmed order', () => { it('should not be able to change the client', async() => { await page.autocompleteSearch(selectors.orderBasicData.client, 'Tony Stark'); await page.autocompleteSearch(selectors.orderBasicData.address, 'Tony Stark'); await page.waitToClick(selectors.orderBasicData.saveButton); const result = await page.waitForLastSnackbar(); expect(result).toEqual(`You can't make changes on the basic data of an confirmed order or with rows`); }, 15000); }); describe('when order with rows', () => { it('should now navigate to order index', async() => { const orderId = '16'; await page.waitToClick(selectors.orderDescriptor.returnToModuleIndexButton); await page.waitToClick(selectors.orderDescriptor.acceptNavigationButton); await page.waitForContentLoaded(); await page.accessToSearchResult(orderId); await page.accessToSection('order.card.basicData'); await page.waitForContentLoaded(); await page.waitForSelector(selectors.orderBasicData.observation, {visible: true}); let url = await page.expectURL(`#!/order/${orderId}/basic-data`); expect(url).toBe(true); }); it('should not be able to change anything', async() => { await page.waitForContentLoaded(); await page.write(selectors.orderBasicData.observation, 'observation'); await page.waitToClick(selectors.orderBasicData.saveButton); const result = await page.waitForLastSnackbar(); expect(result).toEqual(`You can't make changes on the basic data of an confirmed order or with rows`); }); }); describe('when new order', () => { it('should navigate to the order index and click the new order button', async() => { await page.waitToClick(selectors.globalItems.returnToModuleIndexButton); await page.waitToClick(selectors.orderBasicData.acceptButton); await page.waitForContentLoaded(); await page.waitToClick(selectors.ordersIndex.createOrderButton); let url = await page.expectURL('#!/order/create'); expect(url).toBe(true); }); it('should now create a new one', async() => { await page.autocompleteSearch(selectors.createOrderView.client, 'Jessica Jones'); await page.datePicker(selectors.createOrderView.landedDatePicker, 0, today); await page.autocompleteSearch(selectors.createOrderView.agency, 'Other agency'); await page.waitToClick(selectors.createOrderView.createButton); let url = await page.expectURL('/catalog'); expect(url).toBe(true); }); it('should navigate to the basic data section of the new order', async() => { await page.accessToSection('order.card.basicData'); let url = await page.expectURL('/basic-data'); expect(url).toBe(true); }); it('should be able to modify all the properties', async() => { await page.autocompleteSearch(selectors.orderBasicData.client, 'Tony Stark'); await page.autocompleteSearch(selectors.orderBasicData.address, 'Tony Stark'); await page.autocompleteSearch(selectors.orderBasicData.agency, 'Silla247'); await page.write(selectors.orderBasicData.observation, 'my observation'); await page.waitToClick(selectors.orderBasicData.saveButton); const result = await page.waitForLastSnackbar(); expect(result).toEqual('Data saved!'); }); it('should now confirm the client have been edited', async() => { await page.reloadSection('order.card.basicData'); const result = await page .waitToGetProperty(selectors.orderBasicData.client, 'value'); expect(result).toEqual('104: Tony Stark'); }); it('should now confirm the agency have been edited', async() => { const result = await page .waitToGetProperty(selectors.orderBasicData.agency, 'value'); expect(result).toEqual('7: Silla247'); }); it('should now confirm the observations have been edited', async() => { const result = await page .waitToGetProperty(selectors.orderBasicData.observation, 'value'); expect(result).toEqual('my observation'); }); }); });