import selectors from '../../helpers/selectors.js'; import createNightmare from '../../helpers/nightmare'; describe('Ticket Create new tracking state path', () => { const nightmare = createNightmare(); describe('as production', () => { beforeAll(() => { return nightmare .loginAndModule('production', 'ticket') .accessToSearchResult('1') .accessToSection('ticket.card.tracking.index'); }); it('should access to the create state view by clicking the create floating button', async() => { let url = await nightmare .clickIfVisible(selectors.ticketTracking.createStateButton) .wait(selectors.createStateView.stateAutocomplete) .parsedUrl(); expect(url.hash).toContain('tracking/edit'); }); it(`should attempt create a new state but receive an error if state is empty`, async() => { let result = await nightmare .waitToClick(selectors.createStateView.saveStateButton) .waitForLastSnackbar(); expect(result).toEqual('State cannot be blank'); }); it(`should create a new state`, async() => { let result = await nightmare .autocompleteSearch(selectors.createStateView.stateAutocomplete, '¿Fecha?') .waitToClick(selectors.createStateView.saveStateButton) .waitForLastSnackbar(); expect(result).toEqual('Data saved!'); }); }); describe('as salesPerson', () => { beforeAll(() => { return nightmare .loginAndModule('salesPerson', 'ticket') .accessToSearchResult('1') .accessToSection('ticket.card.tracking.index'); }); it('should now access to the create state view by clicking the create floating button', async() => { let url = await nightmare .waitToClick(selectors.ticketTracking.createStateButton) .wait(selectors.createStateView.stateAutocomplete) .parsedUrl(); expect(url.hash).toContain('tracking/edit'); }); it(`should attemp to create an state for which salesPerson doesn't have permissions`, async() => { let result = await nightmare .autocompleteSearch(selectors.createStateView.stateAutocomplete, 'Encajado') .waitToClick(selectors.createStateView.saveStateButton) .waitForLastSnackbar(); expect(result).toEqual(`You don't have enough privileges`); }); it(`should make sure the worker gets autocomplete uppon selecting the assigned state`, async() => { let result = await nightmare .autocompleteSearch(selectors.createStateView.stateAutocomplete, 'asignado') .waitToGetProperty(`${selectors.createStateView.workerAutocomplete} input`, 'value'); expect(result).toEqual('salesPersonNick'); }); it(`should succesfully create a valid state`, async() => { let result = await nightmare .waitToClick(selectors.createStateView.saveStateButton) .waitForLastSnackbar(); expect(result).toEqual('Data saved!'); }); }); });