salix/e2e/paths/05-ticket/13_services.spec.js

128 lines
5.4 KiB
JavaScript

import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer';
describe('Ticket services path', () => {
let browser;
let page;
const invoicedTicketId = '1';
afterAll(async() => {
await browser.close();
});
describe('as employee', () => {
it('should log in as employee, search for an invoice and get to services', async() => {
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('employee', 'ticket');
await page.accessToSearchResult(invoicedTicketId);
await page.accessToSection('ticket.card.service');
});
it('should find the add descripton button disabled for this user role', async() => {
await page.waitForClassPresent(selectors.ticketService.firstAddServiceTypeButton, 'disabled');
await page.waitToClick(selectors.ticketService.addServiceButton);
await page.waitForSelector(selectors.ticketService.firstAddServiceTypeButton);
const result = await page.isDisabled(selectors.ticketService.firstAddServiceTypeButton);
expect(result).toBe(true);
});
it('should receive an error if you attempt to save a service without access rights', async() => {
await page.clearInput(selectors.ticketService.firstPrice);
await page.write(selectors.ticketService.firstPrice, '999');
await page.waitToClick(selectors.ticketService.saveServiceButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain(`The current ticket can't be modified`);
});
});
describe('as administrative', () => {
let editableTicketId = '16';
it('should navigate to the services of a target ticket', async() => {
await page.loginAndModule('administrative', 'ticket');
await page.accessToSearchResult(editableTicketId);
await page.accessToSection('ticket.card.service');
});
it('should click on the add button to prepare the form to create a new service', async() => {
await page.waitToClick(selectors.ticketService.addServiceButton);
const result = await page
.isVisible(selectors.ticketService.firstServiceType);
expect(result).toBeTruthy();
});
it('should receive an error if you attempt to save it with empty fields', async() => {
await page.waitToClick(selectors.ticketService.saveServiceButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain(`can't be blank`);
});
it('should click on the add new service type to open the dialog', async() => {
await page.waitToClick(selectors.ticketService.firstAddServiceTypeButton);
await page.waitForSelector('.vn-dialog.shown');
const result = await page.isVisible(selectors.ticketService.newServiceTypeName);
expect(result).toBeTruthy();
});
it('should receive an error if service type is empty on submit', async() => {
await page.waitToClick(selectors.ticketService.saveServiceTypeButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain(`Name can't be empty`);
});
it('should create a new service type then add price then create the service', async() => {
await page.write(selectors.ticketService.newServiceTypeName, 'Documentos');
await page.waitToClick(selectors.ticketService.saveServiceTypeButton);
await page.write(selectors.ticketService.firstPrice, '999');
await page.waitToClick(selectors.ticketService.saveServiceButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain('Data saved!');
});
it('should confirm the service description was created correctly', async() => {
await page.reloadSection('ticket.card.service');
const result = await page
.waitToGetProperty(selectors.ticketService.firstServiceType, 'value');
expect(result).toEqual('Documentos');
});
it('should confirm the service quantity was created correctly', async() => {
const result = await page
.waitToGetProperty(selectors.ticketService.firstQuantity, 'value');
expect(result).toEqual('1');
});
it('should confirm the service price was created correctly', async() => {
const result = await page
.waitToGetProperty(selectors.ticketService.firstPrice, 'value');
expect(result).toEqual('999');
});
it('should delete the service', async() => {
await page.waitToClick(selectors.ticketService.fistDeleteServiceButton);
await page.waitForNumberOfElements(selectors.ticketService.serviceLine, 0);
await page.waitToClick(selectors.ticketService.saveServiceButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain('Data saved!');
});
it(`should confirm the service was removed`, async() => {
await page.reloadSection('ticket.card.service');
const nResults = await page.countElement(selectors.ticketService.serviceLine);
expect(nResults).toEqual(0);
});
});
});