import selectors from '../../helpers/selectors.js'; import createNightmare from '../../helpers/nightmare'; describe('Client add address notes path', () => { const nightmare = createNightmare(); beforeAll(() => { nightmare .loginAndModule('employee', 'client'); }); it('should search for the user Petter Parker', async () => { const resultCount = await nightmare .wait(selectors.clientsIndex.searchClientInput) .type(selectors.clientsIndex.searchClientInput, 'Petter Parker') .click(selectors.clientsIndex.searchButton) .waitForNumberOfElements(selectors.clientsIndex.searchResult, 1) .countElement(selectors.clientsIndex.searchResult); expect(resultCount).toEqual(1); }); it(`should click on the search result to access to the client addresses`, async () => { const url = await nightmare .waitForTextInElement(selectors.clientsIndex.searchResult, 'Petter Parker') .waitToClick(selectors.clientsIndex.searchResult) .waitToClick(selectors.clientAddresses.addressesButton) .waitForURL('address/index') .parsedUrl(); expect(url.hash).toContain('address/index'); }); it(`should click on the edit icon of the default address`, async () => { const url = await nightmare .waitForTextInElement(selectors.clientAddresses.defaultAddress, '20 Ingram Street') .waitToClick(selectors.clientAddresses.firstEditButton) .waitForURL('/edit') .parsedUrl(); expect(url.hash).toContain('/edit'); }); it('should not save a description without observation type', async () => { const result = await nightmare .waitToClick(selectors.clientAddresses.addObservationButton) .wait(selectors.clientAddresses.firstObservationDescriptionInput) .type(selectors.clientAddresses.firstObservationDescriptionInput, 'first description') .waitToClick(selectors.clientAddresses.saveButton) .waitForLastSnackbar(); expect(result).toEqual('Observation type cannot be blank'); }); it('should not save an observation type without description', async () => { const result = await nightmare .clearInput(selectors.clientAddresses.firstObservationDescriptionInput) .waitToClick(selectors.clientAddresses.firstObservationTypeSelect) .waitToClick(selectors.clientAddresses.firstObservationTypeSelectOptionOne) .waitToClick(selectors.clientAddresses.saveButton) .waitForLastSnackbar(); expect(result).toEqual('Some fields are invalid'); }); it('should create two new observations', async () => { const result = await 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(); expect(result).toEqual('Data saved!'); }); });