import selectors from '../../helpers/selectors.js'; import createNightmare from '../../helpers/helpers'; describe('Client add address notes path', () => { const nightmare = createNightmare(); beforeAll(() => { return nightmare .waitForLogin('employee'); }); it('should click on the Clients button of the top bar menu', done => { return nightmare .waitToClick(selectors.globalItems.applicationsMenuButton) .wait(selectors.globalItems.applicationsMenuVisible) .waitToClick(selectors.globalItems.clientsButton) .wait(selectors.clientsIndex.createClientButton) .parsedUrl() .then(url => { expect(url.hash).toEqual('#!/client/index'); done(); }).catch(done.fail); }); it('should search for the user Petter Parker', done => { return nightmare .wait(selectors.clientsIndex.searchResult) .type(selectors.clientsIndex.searchClientInput, 'Petter Parker') .click(selectors.clientsIndex.searchButton) .waitForNumberOfElements(selectors.clientsIndex.searchResult, 1) .countElement(selectors.clientsIndex.searchResult) .then(result => { expect(result).toEqual(1); done(); }).catch(done.fail); }); it(`should click on the search result to access to the client addresses`, done => { return nightmare .waitForTextInElement(selectors.clientsIndex.searchResult, 'Petter Parker') .waitToClick(selectors.clientsIndex.searchResult) .waitToClick(selectors.clientAddresses.addressesButton) .waitForURL('address/index') .url() .then(url => { expect(url).toContain('address/index'); done(); }).catch(done.fail); }); it(`should click on the edit icon of the default address`, done => { return nightmare .waitForTextInElement(selectors.clientAddresses.defaultAddress, '20 Ingram Street') .waitToClick(selectors.clientAddresses.firstEditButton) .waitForURL('/edit') .url() .then(result => { expect(result).toContain('/edit'); done(); }).catch(done.fail); }); it('should not save a description without observation type', done => { return nightmare .waitToClick(selectors.clientAddresses.addObservationButton) .wait(selectors.clientAddresses.firstObservationDescriptionInput) .type(selectors.clientAddresses.firstObservationDescriptionInput, 'first description') .waitToClick(selectors.clientAddresses.saveButton) .waitForLastSnackbar() .then(result => { expect(result).toEqual('Observation type cannot be blank'); done(); }).catch(done.fail); }); it('should not save an observation type without description', done => { return nightmare .clearInput(selectors.clientAddresses.firstObservationDescriptionInput) .waitToClick(selectors.clientAddresses.firstObservationTypeSelect) .waitToClick(selectors.clientAddresses.firstObservationTypeSelectOptionOne) .waitToClick(selectors.clientAddresses.saveButton) .waitForLastSnackbar() .then(result => { expect(result).toEqual('Some fields are invalid'); done(); }).catch(done.fail); }); it('should create two new observations', done => { return nightmare .type(selectors.clientAddresses.firstObservationDescriptionInput, 'first description') .waitToClick(selectors.clientAddresses.addObservationButton) .waitToClick(selectors.clientAddresses.secondObservationTypeSelect) .waitToClick(selectors.clientAddresses.secondObservationTypeSelectOptionTwo) .type(selectors.clientAddresses.secondObservationDescriptionInput, 'second description') .waitToClick(selectors.clientAddresses.saveButton) .waitForLastSnackbar() .then(result => { expect(result).toEqual('Data saved!'); done(); }).catch(done.fail); }); });