salix/e2e/paths/02-client/14_balance.spec.js

118 lines
4.7 KiB
JavaScript

import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
fdescribe('Client balance path', () => {
let browser;
let page;
beforeAll(async() => {
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('administrative', 'client');
await page.accessToSearchResult('Petter Parker');
});
afterAll(async() => {
await browser.close();
});
it('should now edit the local user config data', async() => {
await page.waitToClick(selectors.globalItems.userMenuButton);
await page.autocompleteSearch(selectors.globalItems.userLocalCompany, 'CCs');
const message = await page.waitForSnackbar();
expect(message.type).toBe('success');
});
it('should access to the balance section to check the data shown matches the local settings', async() => {
await page.accessToSection('client.card.balance.index');
let result = await page.waitToGetProperty(selectors.clientBalance.company, 'value');
expect(result).toEqual('CCs');
});
it('should now clear the user local settings', async() => {
await page.waitToClick(selectors.globalItems.userMenuButton);
await page.clearInput(selectors.globalItems.userConfigThirdAutocomplete);
const message = await page.waitForSnackbar();
expect(message.type).toBe('success');
});
it('should click the new payment button', async() => {
await page.closePopup();
await page.reloadSection('client.card.balance.index');
await page.waitForState('client.card.balance.index');
});
it('should create a new payment that clears the debt', async() => {
await page.waitToClick(selectors.clientBalance.newPaymentButton);
await page.autocompleteSearch(selectors.clientBalance.newPaymentBank, 'Pay on receipt');
await page.waitToClick(selectors.clientBalance.saveButton);
const message = await page.waitForSnackbar();
expect(message.type).toBe('success');
});
it('should check balance is now 0 and the company is now VNL becouse the user local settings were removed', async() => {
await page.waitForSpinnerLoad();
let company = await page
.waitToGetProperty(selectors.clientBalance.company, 'value');
let firstBalanceLine = await page
.waitToGetProperty(selectors.clientBalance.firstBalanceLine, 'innerText');
expect(company).toEqual('VNL');
expect(firstBalanceLine).toContain('0.00');
});
it('should create a new payment that sets the balance to positive value', async() => {
await page.waitToClick(selectors.clientBalance.newPaymentButton);
await page.overwrite(selectors.clientBalance.newPaymentAmount, '100');
await page.waitToClick(selectors.clientBalance.saveButton);
const message = await page.waitForSnackbar();
expect(message.type).toBe('success');
});
it('should check balance is now -100', async() => {
let result = await page
.waitToGetProperty(selectors.clientBalance.firstBalanceLine, 'innerText');
expect(result).toContain('-€100.00');
});
it('should create a new payment that sets the balance back to the original negative value', async() => {
await page.waitToClick(selectors.clientBalance.newPaymentButton);
await page.overwrite(selectors.clientBalance.newPaymentAmount, '-150');
await page.waitToClick(selectors.clientBalance.saveButton);
const message = await page.waitForSnackbar();
expect(message.type).toBe('success');
});
it('should check balance is now 50', async() => {
let result = await page
.waitToGetProperty(selectors.clientBalance.firstBalanceLine, 'innerText');
expect(result).toEqual('€50.00');
});
it('should now click on the Clients button of the top bar menu', async() => {
await page.login('employee');
await page.waitToClick(selectors.globalItems.applicationsMenuButton);
await page.wait(selectors.globalItems.applicationsMenuVisible);
await page.waitToClick(selectors.globalItems.clientsButton);
await page.wait(selectors.clientsIndex.createClientButton);
await page.waitForState('client.index');
});
it('should now search for the user Petter Parker', async() => {
await page.accessToSearchResult('Petter Parker');
await page.accessToSection('client.card.balance.index');
});
it('should not be able to click the new payment button as it isnt present', async() => {
await page.waitFor(selectors.clientBalance.newPaymentButton, {hidden: true});
});
});