salix/e2e/paths/08-route/03_create_and_clone.spec.js

92 lines
3.7 KiB
JavaScript

import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer';
describe('Route create path', () => {
let browser;
let page;
beforeAll(async() => {
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('employee', 'route');
});
afterAll(async() => {
await browser.close();
});
describe('as employee', () => {
it('should click on the add new route button and open the creation form', async() => {
await page.waitToClick(selectors.routeIndex.addNewRouteButton);
await page.waitForState('route.create');
});
it(`should attempt to create a new route but fail since employee has no access rights`, async() => {
await page.write(selectors.createRouteView.description, 'faster faster!!');
await page.waitToClick(selectors.createRouteView.submitButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain('Access denied');
});
});
describe('as delivery', () => {
beforeAll(async() => {
await page.login('delivery');
await page.selectModule('route');
});
it('should again click on the add new route button and open the creation form', async() => {
await page.waitToClick(selectors.routeIndex.addNewRouteButton);
await page.waitForState('route.create');
});
it(`should create a new route`, async() => {
await page.autocompleteSearch(selectors.createRouteView.worker, 'teamManagerNick');
await page.pickDate(selectors.createRouteView.createdDatePicker);
await page.autocompleteSearch(selectors.createRouteView.vehicleAuto, '4444-IMK');
await page.autocompleteSearch(selectors.createRouteView.agency, 'Teleportation device');
await page.write(selectors.createRouteView.description, 'faster faster!!');
await page.waitToClick(selectors.createRouteView.submitButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain('Data saved!');
});
it(`should confirm the redirection to the created route summary`, async() => {
await page.waitForState('route.card.summary');
});
it(`should navigate back to the route index`, async() => {
await page.waitToClick(selectors.globalItems.returnToModuleIndexButton);
await page.waitForState('route.index');
});
let count;
it(`should count the amount of routes before clonation`, async() => {
await page.waitForFunction(selector => {
return document.querySelectorAll(selector).length > 6;
}, {}, selectors.routeIndex.anyResult);
count = await page.countElement(selectors.routeIndex.anyResult);
expect(count).toBeGreaterThanOrEqual(7);
});
it(`should clone the first route`, async() => {
await page.waitToClick(selectors.routeIndex.firstRouteCheckbox);
await page.waitToClick(selectors.routeIndex.cloneButton);
await page.waitToClick(selectors.routeIndex.submitClonationButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain('Data saved!');
});
it(`should reload the section and count the amount of routes after clonation`, async() => {
await page.waitForNumberOfElements(selectors.routeIndex.anyResult, count + 1);
const result = await page.countElement(selectors.routeIndex.anyResult);
expect(result).toEqual(count + 1);
});
});
});