salix/e2e/paths/02-client-module/02_edit_basic_data.spec.js

137 lines
5.9 KiB
JavaScript

import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
describe('Client Edit basicData path', () => {
let page;
beforeAll(async() => {
page = await openPage();
await page.loginAndModule('employee', 'client');
await page.accessToSearchResult('Bruce Wayne');
await page.accessToSection('client.card.basicData');
});
afterAll(async() => {
page.close();
});
describe('as employee', () => {
it('should not be able to change the salesPerson', async() => {
await page.wait(selectors.clientBasicData.nameInput);
const result = await page.evaluate(selector => {
return document.querySelector(selector).disabled;
}, `${selectors.clientBasicData.salesPersonAutocomplete} input`);
expect(result).toBeTruthy();
});
it('should edit the client basic data but leave salesPerson untainted', async() => {
await page.clearInput(selectors.clientBasicData.nameInput);
await page.write(selectors.clientBasicData.nameInput, 'Ptonomy Wallace');
await page.clearInput(selectors.clientBasicData.contactInput);
await page.write(selectors.clientBasicData.contactInput, 'David Haller');
await page.clearInput(selectors.clientBasicData.emailInput);
await page.write(selectors.clientBasicData.emailInput, 'PWallace@verdnatura.es');
await page.autocompleteSearch(selectors.clientBasicData.channelAutocomplete, 'Rumors on the streets');
await page.waitToClick(selectors.clientBasicData.saveButton);
const result = await page.waitForLastSnackbar();
expect(result).toEqual('Data saved!');
});
it('should confirm the name have been edited', async() => {
await page.reloadSection('client.card.basicData');
const result = await page.waitToGetProperty(`${selectors.clientBasicData.nameInput} input`, 'value');
expect(result).toEqual('Ptonomy Wallace');
});
it('should confirm the contact name have been edited', async() => {
const result = await page
.waitToGetProperty(`${selectors.clientBasicData.contactInput} input`, 'value');
expect(result).toEqual('David Haller');
});
it('should confirm the email have been edited', async() => {
const result = await page
.waitToGetProperty(`${selectors.clientBasicData.emailInput} input`, 'value');
expect(result).toEqual('PWallace@verdnatura.es');
});
it('should confirm the channel have been selected', async() => {
const result = await page
.waitToGetProperty(`${selectors.clientBasicData.channelAutocomplete} input`, 'value');
expect(result).toEqual('Rumors on the streets');
});
});
describe('as salesAssistant', () => {
beforeAll(async() => {
await page.loginAndModule('salesASsistant', 'client');
await page.accessToSearchResult('Ptonomy Wallace');
await page.accessToSection('client.card.basicData');
});
it('should be able to change the salesPerson', async() => {
await page.wait(selectors.clientBasicData.nameInput);
const result = await page.evaluate(selector => {
return document.querySelector(selector).disabled;
}, `${selectors.clientBasicData.salesPersonAutocomplete} input`);
expect(result).toBeFalsy();
});
it('should edit the client basic data including salesPerson', async() => {
await page.clearInput(selectors.clientBasicData.nameInput);
await page.write(selectors.clientBasicData.nameInput, 'Ororo Munroe');
await page.clearInput(selectors.clientBasicData.contactInput);
await page.write(selectors.clientBasicData.contactInput, 'Black Panther');
await page.clearInput(selectors.clientBasicData.emailInput);
await page.write(selectors.clientBasicData.emailInput, 'Storm@verdnatura.es');
await page.autocompleteSearch(selectors.clientBasicData.salesPersonAutocomplete, 'replenisherNick');
await page.autocompleteSearch(selectors.clientBasicData.channelAutocomplete, 'Metropolis newspaper');
await page.waitToClick(selectors.clientBasicData.saveButton);
const result = await page.waitForLastSnackbar();
expect(result).toEqual('Data saved!');
});
it('should now confirm the name have been edited', async() => {
await page.reloadSection('client.card.basicData');
const result = await page.waitToGetProperty(`${selectors.clientBasicData.nameInput} input`, 'value');
expect(result).toEqual('Ororo Munroe');
});
it('should now confirm the contact name have been edited', async() => {
const result = await page
.waitToGetProperty(`${selectors.clientBasicData.contactInput} input`, 'value');
expect(result).toEqual('Black Panther');
});
it('should now confirm the email have been edited', async() => {
const result = await page
.waitToGetProperty(`${selectors.clientBasicData.emailInput} input`, 'value');
expect(result).toEqual('Storm@verdnatura.es');
});
it('should confirm the sales person have been selected', async() => {
const result = await page
.waitToGetProperty(`${selectors.clientBasicData.salesPersonAutocomplete} input`, 'value');
expect(result).toEqual('replenisherNick');
});
it('should now confirm the channel have been selected', async() => {
const result = await page
.waitToGetProperty(`${selectors.clientBasicData.channelAutocomplete} input`, 'value');
expect(result).toEqual('Metropolis newspaper');
});
});
});