import selectors from '../../helpers/selectors.js'; import createNightmare from '../../helpers/nightmare'; describe('User config', () => { const nightmare = createNightmare(); describe('as salesPerson', () => { beforeAll(() => { nightmare .waitForLogin('salesPerson'); }); it('should now open the user config form to check the settings', async() => { let userLocalWarehouse = await nightmare .waitToClick(selectors.globalItems.userMenuButton) .getProperty(`${selectors.globalItems.userLocalWarehouse} input`, 'value'); let userLocalBank = await nightmare .getProperty(`${selectors.globalItems.userLocalBank} input`, 'value'); let userLocalCompany = await nightmare .getProperty(`${selectors.globalItems.userLocalCompany} input`, 'value'); let userWarehouse = await nightmare .waitToGetProperty(`${selectors.globalItems.userWarehouse} input`, 'value'); let userCompany = await nightmare .waitToGetProperty(`${selectors.globalItems.userCompany} input`, 'value'); expect(userLocalWarehouse).toEqual(''); expect(userLocalBank).toEqual(''); expect(userLocalCompany).toEqual(''); expect(userWarehouse).toEqual('Warehouse Three'); expect(userCompany).toEqual('VNH'); }); }); describe('as employee', () => { beforeAll(() => { nightmare .waitForLogin('employee'); }); it('should open the user config form to check the settings', async() => { let userLocalWarehouse = await nightmare .waitToClick(selectors.globalItems.userMenuButton) .getProperty(`${selectors.globalItems.userLocalWarehouse} input`, 'value'); let userLocalBank = await nightmare .getProperty(`${selectors.globalItems.userLocalBank} input`, 'value'); let userLocalCompany = await nightmare .getProperty(`${selectors.globalItems.userLocalCompany} input`, 'value'); let userWarehouse = await nightmare .waitToGetProperty(`${selectors.globalItems.userWarehouse} input`, 'value'); let userCompany = await nightmare .waitToGetProperty(`${selectors.globalItems.userCompany} input`, 'value'); expect(userLocalWarehouse).toEqual(''); expect(userLocalBank).toEqual(''); expect(userLocalCompany).toEqual(''); expect(userWarehouse).toEqual('Warehouse Two'); expect(userCompany).toEqual('CCs'); }); it('should now edit the user config data', async() => { let result = await nightmare .autocompleteSearch(selectors.globalItems.userLocalWarehouse, 'Warehouse Four') .autocompleteSearch(selectors.globalItems.userLocalBank, 'Pay on receipt') .autocompleteSearch(selectors.globalItems.userLocalCompany, 'VNL') .waitForLastSnackbar(); expect(result).toEqual('Data saved!'); }); }); describe('as salesPerson 2nd run', () => { beforeAll(() => { nightmare .waitForLogin('salesPerson'); }); it('should again open the user config form to check the local settings', async() => { let userLocalWarehouse = await nightmare .waitToClick(selectors.globalItems.userMenuButton) .waitToGetProperty(`${selectors.globalItems.userLocalWarehouse} input`, 'value'); let userLocalBank = await nightmare .waitToGetProperty(`${selectors.globalItems.userLocalBank} input`, 'value'); let userLocalCompany = await nightmare .waitToGetProperty(`${selectors.globalItems.userLocalCompany} input`, 'value'); let userWarehouse = await nightmare .waitToGetProperty(`${selectors.globalItems.userWarehouse} input`, 'value'); let userCompany = await nightmare .waitToGetProperty(`${selectors.globalItems.userCompany} input`, '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() => { let result = await nightmare .waitToClick(selectors.globalItems.userMenuButton) .waitToClick(selectors.globalItems.userConfigFirstAutocompleteClear) .waitToClick(selectors.globalItems.userConfigSecondAutocompleteClear) .waitToClick(selectors.globalItems.userConfigThirdAutocompleteClear) .waitForLastSnackbar(); expect(result).toEqual('Data saved!'); }); }); });