import selectors from '../../helpers/selectors.js'; import createNightmare from '../../helpers/helpers'; describe('Add address path', () => { const nightmare = createNightmare(); beforeAll(() => { return nightmare .waitForLogin('developer'); }); it('should click on the Clients button of the top bar menu', () => { 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('#!/clients'); }); }); it('should search for the user Bruce Banner', () => { return nightmare .wait(selectors.clientsIndex.searchResult) .type(selectors.clientsIndex.searchClientInput, 'Bruce Banner') .click(selectors.clientsIndex.searchButton) .waitForNumberOfElements(selectors.clientsIndex.searchResult, 1) .countSearchResults(selectors.clientsIndex.searchResult) .then(result => { expect(result).toEqual(1); }); }); it(`should click on the search result to access to the client addresses`, () => { return nightmare .waitForTextInElement(selectors.clientsIndex.searchResult, 'Bruce Banner') .waitToClick(selectors.clientsIndex.searchResult) .waitToClick(selectors.clientAddresses.addressesButton) .waitForURL('addresses/list') .url() .then(url => { expect(url).toContain('addresses/list'); }); }); it(`should click on the add new address button to access to the new address form`, () => { return nightmare .waitToClick(selectors.clientAddresses.createAddress) .waitForURL('addresses/create') .url() .then(url => { expect(url).toContain('addresses/create'); }); }); it('should check the default checkbox then receive an error after clicking save button as the form is empty', () => { return nightmare .waitToClick(selectors.clientAddresses.defaultCheckboxInput) .waitToClick(selectors.clientFiscalData.saveButton) .waitForSnackbar() .then(result => { expect(result).toContain('Some fields are invalid'); }); }); it('should receive an error when clicking the save button having all the form fields empty but consignee', () => { return nightmare .type(selectors.clientAddresses.consigneeInput, 'Bruce Bunner') .click(selectors.createClientView.createButton) .waitForSnackbar() .then(result => { expect(result).toContain('Some fields are invalid'); }); }); it('should receive an error when clicking the save button having all the form fields empty but Street', () => { return nightmare .clearInput(selectors.clientAddresses.consigneeInput) .type(selectors.clientAddresses.streetAddressInput, '320 Park Avenue New York') .click(selectors.createClientView.createButton) .waitForSnackbar() .then(result => { expect(result).toContain('Some fields are invalid'); }); }); it('should receive an error when clicking the save button having all the form fields empty but postcode', () => { return nightmare .clearInput(selectors.clientAddresses.streetAddressInput) .type(selectors.clientAddresses.postcodeInput, '10022') .click(selectors.createClientView.createButton) .waitForSnackbar() .then(result => { expect(result).toContain('Some fields are invalid'); }); }); it('should receive an error when clicking the save button having all the form fields empty but city', () => { return nightmare .clearInput(selectors.clientAddresses.postcodeInput) .type(selectors.clientAddresses.cityInput, 'New York') .click(selectors.createClientView.createButton) .waitForSnackbar() .then(result => { expect(result).toContain('Some fields are invalid'); }); }); it('should receive an error when clicking the save button having all the form fields empty but province', () => { return nightmare .clearInput(selectors.clientAddresses.cityInput) .waitToClick(selectors.clientAddresses.provinceInput) .waitToClick(selectors.clientAddresses.provinceSecondOption) .click(selectors.createClientView.createButton) .waitForSnackbar() .then(result => { expect(result).toContain('Some fields are invalid'); }); }); it('should receive an error when clicking the save button having all the form fields empty but province and agency', () => { return nightmare .waitToClick(selectors.clientAddresses.agencyInput) .waitToClick(selectors.clientAddresses.agenctySecondOption) .click(selectors.createClientView.createButton) .waitForSnackbar() .then(result => { expect(result).toContain('Some fields are invalid'); }); }); it('should receive an error when clicking the save button having all the form fields empty but province, agency and phone', () => { return nightmare .type(selectors.clientAddresses.phoneInput, '999887744') .click(selectors.createClientView.createButton) .waitForSnackbar() .then(result => { expect(result).toContain('Some fields are invalid'); }); }); it('should receive an error when clicking the save button having all the form fields empty but province, agency and mobile', () => { return nightmare .clearInput(selectors.clientAddresses.phoneInput) .type(selectors.clientAddresses.mobileInput, '999887744') .click(selectors.createClientView.createButton) .waitForSnackbar() .then(result => { expect(result).toContain('Some fields are invalid'); }); }); it(`should create a new address with all it's data`, () => { return nightmare .type(selectors.clientAddresses.consigneeInput, 'Bruce Bunner') .type(selectors.clientAddresses.streetAddressInput, '320 Park Avenue New York') .type(selectors.clientAddresses.postcodeInput, '10022') .type(selectors.clientAddresses.cityInput, 'New York') .type(selectors.clientAddresses.phoneInput, '999887744') .click(selectors.clientAddresses.saveButton) .waitForSnackbar() .then(result => { expect(result).toContain('Data saved!'); }); }); it(`should click on the addresses button confirm the new address exists and it's the default one`, () => { return nightmare .waitToClick(selectors.clientAddresses.addressesButton) .wait(selectors.clientAddresses.defaultAddress) .getInnerText(selectors.clientAddresses.defaultAddress) .then(result => { expect(result).toContain('320 Park Avenue New York'); }); }); it(`should click on the make default icon of the second address then confirm it is the default one now`, () => { return nightmare .waitToClick(selectors.clientAddresses.secondMakeDefaultStar) .waitForTextInElement(selectors.clientAddresses.defaultAddress, 'Somewhere in Thailand') .getInnerText(selectors.clientAddresses.defaultAddress) .then(result => { expect(result).toContain('Somewhere in Thailand'); }); }); it(`should click on the edit icon of the default address`, () => { return nightmare .waitForTextInElement(selectors.clientAddresses.defaultAddress, 'Somewhere in Thailand') .waitToClick(selectors.clientAddresses.firstEditButton) .waitForURL('/edit') .url() .then(result => { expect(result).toContain('/edit'); }); }); it(`should click on the active checkbox and receive an error to save it becouse it is the default address`, () => { return nightmare .waitToClick(selectors.clientAddresses.activeCheckbox) .waitToClick(selectors.clientAddresses.saveButton) .waitForSnackbar() .then(result => { expect(result).toContain('Some fields are invalid'); }); }); });