import selectors from '../../helpers/selectors.js'; import createNightmare from '../../helpers/nightmare'; describe('Client Edit fiscalData path', () => { const nightmare = createNightmare(); describe('as employee', () => { beforeAll(() => { nightmare .waitForLogin('employee'); }); it('should click on the Clients button of the top bar menu', async () => { const url = await nightmare .waitToClick(selectors.globalItems.applicationsMenuButton) .wait(selectors.globalItems.applicationsMenuVisible) .waitToClick(selectors.globalItems.clientsButton) .wait(selectors.clientsIndex.createClientButton) .parsedUrl(); expect(url.hash).toEqual('#!/client/index'); }); it('should search for the user Bruce Banner', async () => { const resultCount = await nightmare .wait(selectors.clientsIndex.searchClientInput) .type(selectors.clientsIndex.searchClientInput, 'Bruce Banner') .click(selectors.clientsIndex.searchButton) .waitForNumberOfElements(selectors.clientsIndex.searchResult, 1) .countElement(selectors.clientsIndex.searchResult); expect(resultCount).toEqual(1); }); // Confirms all addresses have EQtax false for future propagation test step 1 it(`should click on the search result to access to the client's addresses`, async () => { const url = await nightmare .waitForTextInElement(selectors.clientsIndex.searchResult, 'Bruce Banner') .waitToClick(selectors.clientsIndex.searchResult) .waitToClick(selectors.clientAddresses.addressesButton) .waitForURL('/address/index') .parsedUrl(); expect(url.hash).toContain('/address/index'); }); // Confirms all addresses have EQtax false for future propagation test step 2 it(`should click on the 1st edit icon to check EQtax isnt checked`, async () => { const result = await nightmare .waitToClick(selectors.clientAddresses.firstEditButton) .wait(selectors.clientAddresses.equalizationTaxCheckboxLabel) .evaluate(selector => { return document.querySelector(selector).checked; }, selectors.clientAddresses.equalizationTaxCheckboxLabel); expect(result).toBeFalsy(); }); // Confirms all addresses have EQtax false for future propagation test step 3 it(`should go back to addresses then select the second one and confirm the EQtax isnt checked`, async () => { const result = await nightmare .waitToClick(selectors.clientAddresses.addressesButton) .waitToClick(selectors.clientAddresses.secondEditButton) .wait(selectors.clientAddresses.equalizationTaxCheckboxLabel) .evaluate(selector => { return document.querySelector(selector).checked; }, selectors.clientAddresses.equalizationTaxCheckboxLabel); expect(result).toBeFalsy(); }); it(`should click on the fiscal data button`, async () => { const url = await nightmare .waitToClick(selectors.clientFiscalData.fiscalDataButton) .waitForURL('fiscal-data') .parsedUrl(); expect(url.hash).toContain('fiscal-data'); }); it('should not be able to edit the verified data checkbox', async () => { const result = await nightmare .evaluate(selector => { return document.querySelector(selector).disabled; }, selectors.clientFiscalData.verifiedDataCheckboxInput); expect(result).toBeTruthy(); }); }); describe('as administrative', () => { beforeAll(() => { nightmare .waitForLogin('administrative'); }); it('should now click on the Clients button of the top bar menu', async () => { const url = await nightmare .waitToClick(selectors.globalItems.applicationsMenuButton) .wait(selectors.globalItems.applicationsMenuVisible) .waitToClick(selectors.globalItems.clientsButton) .wait(selectors.clientsIndex.createClientButton) .parsedUrl(); expect(url.hash).toEqual('#!/client/index'); }); it('should now search for the user Bruce Banner', async () => { const resultCount = await nightmare .wait(selectors.clientsIndex.searchClientInput) .type(selectors.clientsIndex.searchClientInput, 'Bruce Banner') .click(selectors.clientsIndex.searchButton) .waitForNumberOfElements(selectors.clientsIndex.searchResult, 1) .countElement(selectors.clientsIndex.searchResult); expect(resultCount).toEqual(1); }); it(`should access to the client fiscal data`, async () => { const url = await nightmare .waitForTextInElement(selectors.clientsIndex.searchResult, 'Bruce Banner') .waitToClick(selectors.clientsIndex.searchResult) .waitToClick(selectors.clientFiscalData.fiscalDataButton) .waitForURL('fiscal-data') .parsedUrl(); expect(url.hash).toContain('fiscal-data'); }); it('should receive an error if VIES and EQtax are being ticked together', async () => { const result = await nightmare .wait(selectors.clientFiscalData.socialNameInput) .clearInput(selectors.clientFiscalData.socialNameInput) .type(selectors.clientFiscalData.socialNameInput, 'SMASH!') .clearInput(selectors.clientFiscalData.fiscalIdInput) .type(selectors.clientFiscalData.fiscalIdInput, '94980061C') .clearInput(selectors.clientFiscalData.addressInput) .type(selectors.clientFiscalData.addressInput, 'Somewhere edited') .clearInput(selectors.clientFiscalData.postcodeInput) .type(selectors.clientFiscalData.postcodeInput, '12345') .clearInput(selectors.clientFiscalData.cityInput) .type(selectors.clientFiscalData.cityInput, 'N/A') .waitToClick(selectors.clientFiscalData.countryInput) .waitToClick(selectors.clientFiscalData.countryThirdOption) .waitToClick(selectors.clientFiscalData.provinceInput) .waitToClick(selectors.clientFiscalData.provinceFifthOption) .waitToClick(selectors.clientFiscalData.activeCheckboxLabel) .waitToClick(selectors.clientFiscalData.frozenCheckboxLabel) .waitToClick(selectors.clientFiscalData.hasToInvoiceCheckboxLabel) .waitToClick(selectors.clientFiscalData.viesCheckboxInput) .waitToClick(selectors.clientFiscalData.invoiceByMailCheckboxLabel) .waitToClick(selectors.clientFiscalData.invoiceByAddressCheckboxInput) .waitToClick(selectors.clientFiscalData.equalizationTaxCheckboxLabel) .waitToClick(selectors.clientFiscalData.verifiedDataCheckboxInput) .waitToClick(selectors.clientFiscalData.saveButton) .waitForLastSnackbar(); expect(result).toEqual('Cannot check VIES and Equalization Tax'); }); it('should receive an error if the fiscal id contains A or B at the beginning', async () => { const result = await nightmare .waitToClick(selectors.clientFiscalData.viesCheckboxInput) .clearInput(selectors.clientFiscalData.fiscalIdInput) .type(selectors.clientFiscalData.fiscalIdInput, 'A94980061C') .waitToClick(selectors.clientFiscalData.saveButton) .waitForLastSnackbar(); expect(result).toEqual('Cannot check Equalization Tax in this NIF/CIF'); }); it('should finally edit the fixcal data correctly as VIES isnt checked and fiscal id is valid for EQtax', async () => { const result = await nightmare .clearInput(selectors.clientFiscalData.fiscalIdInput) .type(selectors.clientFiscalData.fiscalIdInput, '94980061C') .waitToClick(selectors.clientFiscalData.saveButton) .waitForLastSnackbar(); expect(result).toEqual('Data saved!'); }); it('should propagate the Equalization tax', async () => { const result = await nightmare .waitToClick(selectors.clientFiscalData.acceptPropagationButton) .waitForLastSnackbar(); expect(result).toEqual('Equivalent tax spreaded'); }); // confirm all addresses have now EQtax checked step 1 it(`should click on the addresses button to access to the client's addresses`, async () => { const url = await nightmare .waitToClick(selectors.clientAddresses.addressesButton) .waitForURL('/address/index') .parsedUrl(); expect(url.hash).toContain('/address/index'); }); // confirm all addresses have now EQtax checked step 2 it(`should click on the 1st edit icon to confirm EQtax is checked`, async () => { const result = await nightmare .waitToClick(selectors.clientAddresses.firstEditButton) .wait(selectors.clientAddresses.equalizationTaxCheckboxLabel) .evaluate(selector => { return document.querySelector(selector).checked; }, selectors.clientAddresses.equalizationTaxCheckboxLabel); expect(result).toBeTruthy(); }); // confirm all addresses have now EQtax checked step 3 it(`should go back to addresses then select the second one and confirm the EQtax is checked`, async () => { const result = await nightmare .waitToClick(selectors.clientAddresses.addressesButton) .waitToClick(selectors.clientAddresses.secondEditButton) .wait(selectors.clientAddresses.equalizationTaxCheckboxLabel) .evaluate(selector => { return document.querySelector(selector).checked; }, selectors.clientAddresses.equalizationTaxCheckboxLabel); expect(result).toBeTruthy(); }); it('should navigate back to fiscal data and uncheck EQtax then check VIES', async () => { const result = await nightmare .waitToClick(selectors.clientFiscalData.fiscalDataButton) .waitToClick(selectors.clientFiscalData.viesCheckboxInput) .waitToClick(selectors.clientFiscalData.equalizationTaxCheckboxLabel) .waitToClick(selectors.clientFiscalData.saveButton) .waitForLastSnackbar(); expect(result).toEqual('Data saved!'); }); it('should propagate the Equalization tax changes', async () => { const result = await nightmare .waitToClick(selectors.clientFiscalData.acceptPropagationButton) .waitForLastSnackbar(); expect(result).toEqual('Equivalent tax spreaded'); }); it('should confirm its name have been edited', async () => { const result = await nightmare .waitToClick(selectors.clientFiscalData.fiscalDataButton) .waitToGetProperty(selectors.clientFiscalData.socialNameInput, 'value'); expect(result).toEqual('SMASH!'); }); it('should confirm the fiscal id have been edited', async () => { const result = await nightmare .waitToGetProperty(selectors.clientFiscalData.fiscalIdInput, 'value'); expect(result).toEqual('94980061C'); }); it('should confirm the address have been edited', async () => { const result = await nightmare .waitToGetProperty(selectors.clientFiscalData.addressInput, 'value'); expect(result).toEqual('Somewhere edited'); }); it('should confirm the postcode have been edited', async () => { const result = await nightmare .waitToGetProperty(selectors.clientFiscalData.postcodeInput, 'value'); expect(result).toEqual('12345'); }); it('should confirm the city have been edited', async () => { const result = await nightmare .waitToGetProperty(selectors.clientFiscalData.cityInput, 'value'); expect(result).toEqual('N/A'); }); it(`should confirm the country have been selected`, async () => { const result = await nightmare .waitToGetProperty(selectors.clientFiscalData.countryInput, 'value'); expect(result).toEqual('Francia'); }); it(`should confirm the province have been selected`, async () => { const result = await nightmare .waitToGetProperty(selectors.clientFiscalData.provinceInput, 'value'); expect(result).toEqual('Province two'); }); it('should confirm active checkbox is unchecked', async () => { const result = await nightmare .evaluate(selector => { return document.querySelector(selector).checked; }, selectors.clientFiscalData.activeCheckboxLabel); expect(result).toBeFalsy(); }); it('should confirm frozen checkbox is unchecked', async () => { const result = await nightmare .evaluate(selector => { return document.querySelector(selector).checked; }, selectors.clientFiscalData.frozenCheckboxLabel); expect(result).toBeFalsy(); }); it('should confirm Has to invoice checkbox is unchecked', async () => { const result = await nightmare .evaluate(selector => { return document.querySelector(selector).checked; }, selectors.clientFiscalData.hasToInvoiceCheckboxLabel); expect(result).toBeFalsy(); }); it('should confirm Vies checkbox is checked', async () => { const result = await nightmare .evaluate(selector => { return document.querySelector(selector).checked; }, selectors.clientFiscalData.viesCheckboxInput); expect(result).toBeTruthy(); }); it('should confirm Invoice by mail checkbox is unchecked', async () => { const result = await nightmare .evaluate(selector => { return document.querySelector(selector).checked; }, selectors.clientFiscalData.invoiceByMailCheckboxLabel); expect(result).toBeFalsy(); }); it('should confirm invoice by address checkbox is unchecked', async () => { const result = await nightmare .evaluate(selector => { return document.querySelector(selector).checked; }, selectors.clientFiscalData.invoiceByAddressCheckboxInput); expect(result).toBeFalsy(); }); it('should confirm Equalization tax checkbox is unchecked', async () => { const result = await nightmare .evaluate(selector => { return document.querySelector(selector).checked; }, selectors.clientFiscalData.equalizationTaxCheckboxLabel); expect(result).toBeFalsy(); }); it('should confirm Verified data checkbox is checked', async () => { const result = await nightmare .evaluate(selector => { return document.querySelector(selector).checked; }, selectors.clientFiscalData.verifiedDataCheckboxInput); expect(result).toBeTruthy(); }); // confirm invoice by address checkbox gets checked if the EQtax differs between addresses step 1 it(`should click on the addresses button to access to the client's addresses`, async () => { const url = await nightmare .waitToClick(selectors.clientAddresses.addressesButton) .waitForURL('/address/index') .parsedUrl(); expect(url.hash).toContain('/address/index'); }); // confirm invoice by address checkbox gets checked if the EQtax differs between addresses step 2 it(`should click on the 1st edit icon to access the address details and uncheck EQtax checkbox`, async () => { const result = await nightmare .waitToClick(selectors.clientAddresses.firstEditButton) .waitToClick(selectors.clientAddresses.equalizationTaxCheckboxLabel) .click(selectors.clientAddresses.saveButton) .waitForLastSnackbar(); expect(result).toEqual('Data saved!'); }); // confirm invoice by address checkbox gets checked if the EQtax differs between addresses step 3 it('should navigate back to fiscal data to confirm invoice by address is now checked', async () => { const result = await nightmare .waitToClick(selectors.clientFiscalData.fiscalDataButton) .wait(selectors.clientFiscalData.invoiceByAddressCheckboxInput) .evaluate(selector => { return document.querySelector(selector).checked; }, selectors.clientFiscalData.invoiceByAddressCheckboxInput); expect(result).toBeTruthy(); }); }); });