import selectors from '../../helpers/selectors'; import getBrowser from '../../helpers/puppeteer'; describe('User config', () => { let browser; let page; beforeAll(async() => { browser = await getBrowser(); page = browser.page; }); afterAll(async() => { await browser.close(); }); describe('as salesPerson', () => { it('should login', async() => { await page.login('salesPerson'); }); it('should now open the user config form to check the settings', async() => { await page.waitToClick(selectors.globalItems.userMenuButton); await page.waitForContentLoaded(); let expectedLocalWarehouse = await page .expectPropertyValue(selectors.globalItems.userLocalWarehouse, 'value', ''); let expectedLocalBank = await page .expectPropertyValue(selectors.globalItems.userLocalBank, 'value', ''); let expectedLocalCompany = await page .expectPropertyValue(selectors.globalItems.userLocalCompany, 'value', ''); let userWarehouse = await page .waitToGetProperty(selectors.globalItems.userWarehouse, 'value'); let userCompany = await page .waitToGetProperty(selectors.globalItems.userCompany, 'value'); expect(expectedLocalWarehouse).toBeTruthy(); expect(expectedLocalBank).toBeTruthy(); expect(expectedLocalCompany).toBeTruthy(); expect(userWarehouse).toEqual('Warehouse Three'); expect(userCompany).toEqual('VNH'); }); }); describe('as employee', () => { it('should log in', async() => { await page.login('employee'); }); it('should open the user config form to check the settings', async() => { await page.waitToClick(selectors.globalItems.userMenuButton); let expectedLocalWarehouse = await page .expectPropertyValue(selectors.globalItems.userLocalWarehouse, 'value', ''); let expectedLocalBank = await page .expectPropertyValue(selectors.globalItems.userLocalBank, 'value', ''); let expectedLocalCompany = await page .expectPropertyValue(selectors.globalItems.userLocalCompany, 'value', ''); let userWarehouse = await page .waitToGetProperty(selectors.globalItems.userWarehouse, 'value'); let userCompany = await page .waitToGetProperty(selectors.globalItems.userCompany, 'value'); expect(expectedLocalWarehouse).toBeTruthy(); expect(expectedLocalBank).toBeTruthy(); expect(expectedLocalCompany).toBeTruthy(); expect(userWarehouse).toEqual('Warehouse One'); expect(userCompany).toEqual('CCs'); }); it('should now edit the user config data', async() => { await page.autocompleteSearch(selectors.globalItems.userLocalWarehouse, 'Warehouse Four'); await page.autocompleteSearch(selectors.globalItems.userLocalBank, 'Pay on receipt'); await page.autocompleteSearch(selectors.globalItems.userLocalCompany, 'VNL'); const message = await page.waitForSnackbar(); expect(message.type).toBe('success'); }); }); describe('as salesPerson 2nd run', () => { it('should log in once more', async() => { await page.login('salesPerson'); }); it('should again open the user config form to check the local settings', async() => { await page.waitToClick(selectors.globalItems.userMenuButton); let userLocalWarehouse = await page .waitToGetProperty(selectors.globalItems.userLocalWarehouse, 'value'); let userLocalBank = await page .waitToGetProperty(selectors.globalItems.userLocalBank, 'value'); let userLocalCompany = await page .waitToGetProperty(selectors.globalItems.userLocalCompany, 'value'); let userWarehouse = await page .waitToGetProperty(selectors.globalItems.userWarehouse, 'value'); let userCompany = await page .waitToGetProperty(selectors.globalItems.userCompany, 'value'); expect(userLocalWarehouse).toContain('Warehouse Four'); expect(userLocalBank).toContain('Pay on receipt'); expect(userLocalCompany).toContain('VNL'); expect(userWarehouse).toEqual('Warehouse Three'); expect(userCompany).toEqual('VNH'); }); it('should now clear the local settings', async() => { await page.clearInput(selectors.globalItems.userConfigFirstAutocomplete); await page.clearInput(selectors.globalItems.userConfigSecondAutocomplete); await page.clearInput(selectors.globalItems.userConfigThirdAutocomplete); const message = await page.waitForSnackbar(); expect(message.type).toBe('success'); }); }); });