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.clientAutocomplete, 'Tony Stark'); await page.autocompleteSearch(selectors.orderBasicData.addressAutocomplete, '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.observationInput, {visible: true}); await page.waitForURL('basic-data'); const url = await page.parsedUrl(); expect(url.hash).toEqual(`#!/order/${orderId}/basic-data`); }); it('should not be able to change anything', async() => { await page.type(selectors.orderBasicData.observationInput, '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); await page.waitForURL('#!/order/create'); const url = await page.parsedUrl(); expect(url.hash).toContain('#!/order/create'); }); it('should now create a new one', async() => { await page.autocompleteSearch(selectors.createOrderView.clientAutocomplete, 'Jessica Jones'); await page.datePicker(selectors.createOrderView.landedDatePicker, 0, today); await page.autocompleteSearch(selectors.createOrderView.agencyAutocomplete, 'Other agency'); await page.waitToClick(selectors.createOrderView.createButton); await page.waitForURL('/catalog'); const url = await page.parsedUrl(); expect(url.hash).toContain('/catalog'); }); it('should navigate to the basic data section of the new order', async() => { await page.accessToSection('order.card.basicData'); await page.wait(selectors.orderBasicData.observationInput); const url = await page.parsedUrl(); expect(url.hash).toContain('/basic-data'); }); it('should be able to modify all the properties', async() => { await page.autocompleteSearch(selectors.orderBasicData.clientAutocomplete, 'Tony Stark'); await page.autocompleteSearch(selectors.orderBasicData.addressAutocomplete, 'Tony Stark'); await page.autocompleteSearch(selectors.orderBasicData.agencyAutocomplete, 'Silla247'); await page.type(selectors.orderBasicData.observationInput, '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.clientAutocomplete, 'value'); expect(result).toEqual('104: Tony Stark'); }); it('should now confirm the agency have been edited', async() => { const result = await page .waitToGetProperty(selectors.orderBasicData.agencyAutocomplete, 'value'); expect(result).toEqual('7: Silla247'); }); it('should now confirm the observations have been edited', async() => { const result = await page .waitToGetProperty(selectors.orderBasicData.observationInput, 'value'); expect(result).toEqual('my observation'); }); }); });