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

237 lines
13 KiB
JavaScript

import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client Edit fiscalData path', () => {
let browser;
let page;
beforeAll(async() => {
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('employee', 'client');
await page.accessToSearchResult('Bruce Banner');
await page.accessToSection('client.card.address.index');
});
afterAll(async() => {
await browser.close();
});
describe('as employee', () => {
// 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() => {
await page.waitToClick(selectors.clientAddresses.firstEditAddress);
const result = await page.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() => {
await page.waitToClick(selectors.clientAddresses.addressesButton);
await page.waitToClick(selectors.clientAddresses.secondEditAddress);
const result = await page.checkboxState(selectors.clientAddresses.equalizationTaxCheckbox);
expect(result).toBe('unchecked');
});
it(`should click on the fiscal data button`, async() => {
await page.waitToClick(selectors.clientFiscalData.fiscalDataButton);
await page.waitForState('client.card.fiscalData');
});
it('should not be able to edit the verified data checkbox', async() => {
await page.waitForSelector(selectors.clientFiscalData.verifiedDataCheckbox);
const result = await page.isDisabled(selectors.clientFiscalData.verifiedDataCheckbox);
expect(result).toBeTruthy();
});
});
describe('as administrative', () => {
beforeAll(async() => {
await page.loginAndModule('administrative', 'client');
await page.accessToSearchResult('Bruce Banner');
await page.accessToSection('client.card.fiscalData');
});
it(`should edit the fiscal data but fail as the fiscal id ain't valid`, async() => {
await page.waitForSelector(selectors.clientFiscalData.socialName);
await page.clearInput(selectors.clientFiscalData.socialName);
await page.write(selectors.clientFiscalData.socialName, 'SMASH');
await page.clearInput(selectors.clientFiscalData.fiscalId);
await page.write(selectors.clientFiscalData.fiscalId, 'INVALID!');
await page.clearInput(selectors.clientFiscalData.address);
await page.write(selectors.clientFiscalData.address, 'SOMEWHERE EDITED');
await page.autocompleteSearch(selectors.clientFiscalData.country, 'España');
await page.autocompleteSearch(selectors.clientFiscalData.province, 'Province one');
await page.clearInput(selectors.clientFiscalData.city);
await page.write(selectors.clientFiscalData.city, 'Valencia');
await page.autocompleteSearch(selectors.clientFiscalData.sageTax, 'operaciones no sujetas');
await page.autocompleteSearch(selectors.clientFiscalData.sageTransaction, 'regularización de inversiones');
await page.clearInput(selectors.clientFiscalData.postcode);
await page.write(selectors.clientFiscalData.postcode, '46000');
await page.waitToClick(selectors.clientFiscalData.activeCheckbox);
await page.waitToClick(selectors.clientFiscalData.frozenCheckbox);
await page.waitToClick(selectors.clientFiscalData.hasToInvoiceCheckbox);
await page.waitToClick(selectors.clientFiscalData.viesCheckbox);
await page.waitToClick(selectors.clientFiscalData.notifyByMailCheckbox);
await page.waitToClick(selectors.clientFiscalData.invoiceByAddressCheckbox);
await page.waitToClick(selectors.clientFiscalData.equalizationTaxCheckbox);
await page.waitToClick(selectors.clientFiscalData.verifiedDataCheckbox);
await page.waitToClick(selectors.clientFiscalData.saveButton);
await page.waitToClick(selectors.globalItems.acceptButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain('Invalid Tax number');
});
it(`should edit the fiscal this time with a valid fiscal id`, async() => {
await page.clearInput(selectors.clientFiscalData.fiscalId);
await page.write(selectors.clientFiscalData.fiscalId, '94980061C');
await page.waitToClick(selectors.clientFiscalData.saveButton);
await page.waitToClick(selectors.globalItems.acceptButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain('Data saved!');
});
it('should propagate the Equalization tax', async() => {
await page.waitToClick(selectors.globalItems.acceptButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain('Equivalent tax spreaded');
});
it('should receive an error if the fiscal id contains A or B at the beginning', async() => {
await page.waitToClick(selectors.clientFiscalData.viesCheckbox);
await page.clearInput(selectors.clientFiscalData.fiscalId);
await page.write(selectors.clientFiscalData.fiscalId, 'A94980061C');
await page.waitToClick(selectors.clientFiscalData.saveButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain('Cannot check Equalization Tax in this NIF/CIF');
});
it('should edit the fiscal data correctly as VIES isnt checked and fiscal id is valid for EQtax', async() => {
await page.clearInput(selectors.clientFiscalData.fiscalId);
await page.write(selectors.clientFiscalData.fiscalId, '94980061C');
await page.waitToClick(selectors.clientFiscalData.saveButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain('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() => {
await page.waitToClick(selectors.clientAddresses.addressesButton);
await page.waitForState('client.card.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() => {
await page.waitToClick(selectors.clientAddresses.firstEditAddress);
await page.waitForWatcherData(selectors.clientAddresses.watcher);
const result = await page.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() => {
await page.waitToClick(selectors.clientAddresses.addressesButton);
await page.waitToClick(selectors.clientAddresses.secondEditAddress);
await page.waitForWatcherData(selectors.clientAddresses.watcher);
const result = await page.checkboxState(selectors.clientAddresses.equalizationTaxCheckbox);
expect(result).toBe('checked');
});
it('should navigate back to fiscal data and uncheck EQtax then check VIES', async() => {
await page.waitToClick(selectors.clientFiscalData.fiscalDataButton);
await page.waitToClick(selectors.clientFiscalData.viesCheckbox);
await page.waitToClick(selectors.clientFiscalData.invoiceByAddressCheckbox);
await page.waitToClick(selectors.clientFiscalData.equalizationTaxCheckbox);
await page.waitToClick(selectors.clientFiscalData.saveButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain('Data saved!');
});
it('should propagate the Equalization tax changes', async() => {
await page.waitToClick(selectors.globalItems.acceptButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain('Equivalent tax spreaded');
});
it('should confirm its name have been edited', async() => {
await page.waitToClick(selectors.clientFiscalData.fiscalDataButton);
const result = await page.waitToGetProperty(selectors.clientFiscalData.socialName, 'value');
expect(result).toEqual('SMASH');
});
it('should confirm the fiscal data have been edited', async() => {
const fiscalId = await page.waitToGetProperty(selectors.clientFiscalData.fiscalId, 'value');
const address = await page.waitToGetProperty(selectors.clientFiscalData.address, 'value');
const postcode = await page.waitToGetProperty(selectors.clientFiscalData.postcode, 'value');
const sageTax = await page.waitToGetProperty(selectors.clientFiscalData.sageTax, 'value');
const sageTransaction = await page.waitToGetProperty(selectors.clientFiscalData.sageTransaction, 'value');
const city = await page.waitToGetProperty(selectors.clientFiscalData.city, 'value');
const province = await page.waitToGetProperty(selectors.clientFiscalData.province, 'value');
const country = await page.waitToGetProperty(selectors.clientFiscalData.country, 'value');
const active = await page.checkboxState(selectors.clientFiscalData.activeCheckbox);
const frozen = await page.checkboxState(selectors.clientFiscalData.frozenCheckbox);
const hasToInvoice = await page.checkboxState(selectors.clientFiscalData.hasToInvoiceCheckbox);
const vies = await page.checkboxState(selectors.clientFiscalData.viesCheckbox);
const notifyByMail = await page.checkboxState(selectors.clientFiscalData.notifyByMailCheckbox);
const invoiceByAddress = await page.checkboxState(selectors.clientFiscalData.invoiceByAddressCheckbox);
const equalizationTax = await page.checkboxState(selectors.clientFiscalData.equalizationTaxCheckbox);
const verifiedData = await page.checkboxState(selectors.clientFiscalData.verifiedDataCheckbox);
expect(fiscalId).toEqual('94980061C');
expect(address).toEqual('SOMEWHERE EDITED');
expect(postcode).toContain('46000');
expect(sageTax).toEqual('Operaciones no sujetas');
expect(sageTransaction).toEqual('Regularización de inversiones');
expect(city).toEqual('Valencia');
expect(province).toContain('Province one');
expect(country).toEqual('España');
expect(active).toBe('unchecked');
expect(frozen).toBe('checked');
expect(hasToInvoice).toBe('unchecked');
expect(vies).toBe('checked');
expect(notifyByMail).toBe('unchecked');
expect(invoiceByAddress).toBe('checked');
expect(equalizationTax).toBe('unchecked');
expect(verifiedData).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() => {
await page.waitToClick(selectors.clientAddresses.addressesButton);
await page.waitForState('client.card.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() => {
await page.waitToClick(selectors.clientAddresses.firstEditAddress);
await page.waitForTextInField(selectors.clientAddresses.city, 'Gotham');
await page.waitToClick(selectors.clientAddresses.equalizationTaxCheckbox);
await page.waitToClick(selectors.clientAddresses.saveButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain('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() => {
await page.waitToClick(selectors.clientFiscalData.fiscalDataButton);
await page.waitForWatcherData(selectors.clientFiscalData.watcher);
const result = await page.checkboxState(selectors.clientFiscalData.invoiceByAddressCheckbox);
expect(result).toBe('checked');
});
});
});