salix/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js

317 lines
14 KiB
JavaScript

import selectors from '../../helpers/selectors.js';
import createNightmare from '../../helpers/nightmare';
describe('Client Edit fiscalData path', () => {
const nightmare = createNightmare();
describe('as employee', () => {
beforeAll(() => {
nightmare
.loginAndModule('employee', 'client')
.accessToSearchResult('Bruce Banner')
.accessToSection('client.card.address.index');
});
// Confirms all addresses have EQtax false for future propagation test step 1
it(`should click on the 1st edit icon to check EQtax isnt checked`, async() => {
const result = await nightmare
.waitToClick(selectors.clientAddresses.firstEditAddress)
.checkboxState(selectors.clientAddresses.equalizationTaxCheckbox);
expect(result).toBe('unchecked');
});
// Confirms all addresses have EQtax false for future propagation test step 2
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.secondEditAddress)
.checkboxState(selectors.clientAddresses.equalizationTaxCheckbox);
expect(result).toBe('unchecked');
});
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
.wait(selectors.clientFiscalData.verifiedDataCheckbox)
.isDisabled(selectors.clientFiscalData.verifiedDataCheckbox);
expect(result).toBeTruthy();
});
});
describe('as administrative', () => {
beforeAll(() => {
nightmare
.loginAndModule('administrative', 'client')
.accessToSearchResult('Bruce Banner')
.accessToSection('client.card.fiscalData');
});
it(`should edit the fiscal data but fail as the fiscal id ain't valid`, async() => {
const result = await nightmare
.wait(selectors.clientFiscalData.socialNameInput)
.clearInput(selectors.clientFiscalData.socialNameInput)
.write(selectors.clientFiscalData.socialNameInput, 'SMASH')
.clearInput(selectors.clientFiscalData.fiscalIdInput)
.write(selectors.clientFiscalData.fiscalIdInput, 'INVALID!')
.clearInput(selectors.clientFiscalData.addressInput)
.write(selectors.clientFiscalData.addressInput, 'Somewhere edited')
.autocompleteSearch(selectors.clientFiscalData.countryAutocomplete, 'España')
.autocompleteSearch(selectors.clientFiscalData.provinceAutocomplete, 'Province one')
.clearInput(selectors.clientFiscalData.cityInput)
.write(selectors.clientFiscalData.cityInput, 'Valencia')
.clearInput(selectors.clientFiscalData.postcodeInput)
.write(selectors.clientFiscalData.postcodeInput, '46000')
.waitToClick(selectors.clientFiscalData.activeCheckbox)
.waitToClick(selectors.clientFiscalData.frozenCheckbox)
.waitToClick(selectors.clientFiscalData.hasToInvoiceCheckbox)
.waitToClick(selectors.clientFiscalData.viesCheckbox)
.waitToClick(selectors.clientFiscalData.invoiceByMailCheckbox)
.waitToClick(selectors.clientFiscalData.invoiceByAddressCheckbox)
.waitToClick(selectors.clientFiscalData.equalizationTaxCheckbox)
.waitToClick(selectors.clientFiscalData.verifiedDataCheckbox)
.waitToClick(selectors.clientFiscalData.saveButton)
.waitForLastSnackbar();
expect(result).toEqual('Invalid Tax number');
});
it(`should edit the fiscal this time with a valid fiscal id`, async() => {
const result = await nightmare
.clearInput(selectors.clientFiscalData.fiscalIdInput)
.write(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');
});
it('should receive an error if the fiscal id contains A or B at the beginning', async() => {
const result = await nightmare
.waitToClick(selectors.clientFiscalData.viesCheckbox)
.clearInput(selectors.clientFiscalData.fiscalIdInput)
.write(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)
.write(selectors.clientFiscalData.fiscalIdInput, '94980061C')
.waitToClick(selectors.clientFiscalData.saveButton)
.waitForLastSnackbar();
expect(result).toEqual('Data saved!');
});
// 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.firstEditAddress)
.waitForWatcherData(selectors.clientAddresses.watcher)
.checkboxState(selectors.clientAddresses.equalizationTaxCheckbox);
expect(result).toBe('checked');
});
// 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.secondEditAddress)
.waitForWatcherData(selectors.clientAddresses.watcher)
.checkboxState(selectors.clientAddresses.equalizationTaxCheckbox);
expect(result).toBe('checked');
});
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.viesCheckbox)
.waitToClick(selectors.clientFiscalData.equalizationTaxCheckbox)
.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).toContain('46000');
});
it('should confirm the city have been autocompleted', async() => {
const result = await nightmare
.waitToGetProperty(`${selectors.clientFiscalData.cityInput}`, 'value');
expect(result).toEqual('Valencia');
});
it(`should confirm the province have been autocompleted`, async() => {
const result = await nightmare
.waitToGetProperty(`${selectors.clientFiscalData.provinceAutocomplete} input`, 'value');
expect(result).toEqual('Province one');
});
it('should confirm the country have been autocompleted', async() => {
const result = await nightmare
.waitToGetProperty(`${selectors.clientFiscalData.countryAutocomplete} input`, 'value');
expect(result).toEqual('España');
});
it('should confirm active checkbox is unchecked', async() => {
const result = await nightmare
.checkboxState(selectors.clientFiscalData.activeCheckbox);
expect(result).toBe('unchecked');
});
it('should confirm frozen checkbox is checked', async() => {
const result = await nightmare
.checkboxState(selectors.clientFiscalData.frozenCheckbox);
expect(result).toBe('checked');
});
it('should confirm Has to invoice checkbox is unchecked', async() => {
const result = await nightmare
.checkboxState(selectors.clientFiscalData.hasToInvoiceCheckbox);
expect(result).toBe('unchecked');
});
it('should confirm Vies checkbox is checked', async() => {
const result = await nightmare
.checkboxState(selectors.clientFiscalData.viesCheckbox);
expect(result).toBe('checked');
});
it('should confirm Invoice by mail checkbox is unchecked', async() => {
const result = await nightmare
.checkboxState(selectors.clientFiscalData.invoiceByMailCheckbox);
expect(result).toBe('unchecked');
});
it('should confirm invoice by address checkbox is unchecked', async() => {
const result = await nightmare
.checkboxState(selectors.clientFiscalData.invoiceByAddressCheckbox);
expect(result).toBe('unchecked');
});
it('should confirm Equalization tax checkbox is unchecked', async() => {
const result = await nightmare
.checkboxState(selectors.clientFiscalData.equalizationTaxCheckbox);
expect(result).toBe('unchecked');
});
it('should confirm Verified data checkbox is checked', async() => {
const result = await nightmare
.checkboxState(selectors.clientFiscalData.verifiedDataCheckbox);
expect(result).toBe('checked');
});
// 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.firstEditAddress)
.waitForTextInInput(selectors.clientAddresses.cityInput, 'Silla')
.waitToClick(selectors.clientAddresses.equalizationTaxCheckbox)
.waitToClick(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)
.waitForWatcherData(selectors.clientFiscalData.watcher)
.checkboxState(selectors.clientFiscalData.invoiceByAddressCheckbox);
expect(result).toBe('checked');
});
});
});