refactor: refs #8618 simplify selectors and improve test readability in routeExtendedList.spec.js

This commit is contained in:
Jose Antonio Tubau 2025-02-19 14:38:13 +01:00
parent 35253c8127
commit 6a3d13144c
1 changed files with 102 additions and 95 deletions

View File

@ -1,27 +1,86 @@
describe('Route extended list', () => {
const worker = 'tr:last-child > [data-col-field="workerFk"]';
const agency = 'tr:last-child > [data-col-field="agencyModeFk"]';
const vehicle = 'tr:last-child > [data-col-field="vehicleFk"]';
const date = 'tr:last-child > [data-col-field="dated"]';
const description = 'tr:last-child > [data-col-field="description"]';
const served = 'tr:last-child > [data-col-field="isOk"]';
const getSelector = (colField) => `tr:last-child > [data-col-field="${colField}"]`;
const selectors = {
worker: getSelector('workerFk'),
agency: getSelector('agencyModeFk'),
vehicle: getSelector('vehicleFk'),
date: getSelector('dated'),
description: getSelector('description'),
served: getSelector('isOk'),
lastRowSelectCheckBox: 'tbody > tr:last-child > :nth-child(1) .q-checkbox__inner',
removeBtn: '[title="Remove"]',
resetBtn: '[title="Reset"]',
confirmBtn: 'VnConfirm_confirm',
saveBtn: 'crudModelDefaultSaveBtn',
saveFormBtn: 'FormModelPopup_save',
cloneBtn: '#st-actions > .q-btn-group > :nth-child(1)',
downloadBtn: '#st-actions > .q-btn-group > :nth-child(2)',
markServedBtn: '#st-actions > .q-btn-group > :nth-child(3)',
searchbar: 'searchbar',
};
const checkboxState = {
check: 'check',
uncheck: 'close',
};
const url = '/#/route/extended-list';
const dataCreated = 'Data created';
const dataSaved = 'Data saved';
const originalFields = [
{ selector: selectors.worker, type: 'select', value: 'logistic' },
{ selector: selectors.agency, type: 'select', value: 'Super-Man delivery' },
{ selector: selectors.vehicle, type: 'select', value: '3333-IMK' },
{ selector: selectors.date, type: 'date', value: '01/02/2024' },
{ selector: selectors.description, type: 'input', value: 'Test route' },
{ selector: selectors.served, type: 'checkbox', value: checkboxState.uncheck },
];
const updateFields = [
{ selector: selectors.worker, type: 'select', value: 'salesperson' },
{ selector: selectors.agency, type: 'select', value: 'inhouse pickup' },
{ selector: selectors.vehicle, type: 'select', value: '1111-IMK' },
{ selector: selectors.date, type: 'date', value: '01/01/2001' },
{ selector: selectors.description, type: 'input', value: 'Description updated' },
{ selector: selectors.served, type: 'checkbox', value: checkboxState.check },
];
function fillField(selector, type, value) {
switch (type) {
case 'select':
cy.get(selector).should('be.visible').click();
cy.dataCy('null_select').clear().type(value);
cy.get('.q-item').contains(value).click();
break;
case 'input':
cy.get(selector).should('be.visible').click();
cy.dataCy('null_input').clear().type(`${value}{enter}`);
break;
case 'date':
cy.get(selector).should('be.visible').click();
cy.dataCy('null_inputDate').clear().type(`${value}{enter}`);
break;
case 'checkbox':
cy.get(selector).should('be.visible').click().click();
break;
}
}
beforeEach(() => {
cy.viewport(1920, 1080);
cy.login('developer');
cy.visit('/#/route/extended-list');
cy.visit(url);
cy.typeSearchbar('{enter}');
});
after(() => {
cy.visit('/#/route/extended-list');
cy.visit(url);
cy.typeSearchbar('{enter}');
cy.get(
'tbody > tr:last-child > :nth-child(1) > .q-checkbox > .q-checkbox__inner',
).click();
cy.get(selectors.lastRowSelectCheckBox).click();
cy.get('[title="Remove"]').click();
cy.dataCy('VnConfirm_confirm').click();
cy.get(selectors.removeBtn).click();
cy.dataCy(selectors.confirmBtn).click();
});
it('Should list routes', () => {
@ -48,62 +107,35 @@ describe('Route extended list', () => {
cy.fillInForm(data);
cy.dataCy('FormModelPopup_save').click();
cy.checkNotification('Data created');
cy.dataCy(selectors.saveFormBtn).click();
cy.checkNotification(dataCreated);
cy.url().should('include', '/summary');
});
it('Should reset changed values when click reset button', () => {
cy.get(worker).should('be.visible').click();
cy.dataCy('null_select').clear().type('salesperson');
cy.get('.q-item').contains('salesperson').click();
cy.get(agency).should('be.visible').click();
cy.dataCy('null_select').clear().type('inhouse pickup');
cy.get('.q-item').contains('inhouse pickup').click();
cy.get(vehicle).should('be.visible').click();
cy.dataCy('null_select').clear().type('1111-IMK');
cy.get('.q-item').contains('1111-IMK').click();
cy.get(date).should('be.visible').click();
cy.dataCy('null_inputDate').clear().type('01-01-2001{enter}');
cy.get(description).should('be.visible').click();
cy.dataCy('null_input').clear().type('DescriptionUpdated{enter}');
cy.get(served).should('be.visible').click().click();
updateFields.forEach(({ selector, type, value }) => {
fillField(selector, type, value);
});
cy.get('[title="Reset"]').click();
cy.validateContent(worker, 'logistic');
cy.validateContent(agency, 'Super-Man delivery');
cy.validateContent(vehicle, '3333-IMK');
cy.validateContent(date, '01/02/2024');
cy.validateContent(description, 'Test route');
cy.validateContent(served, 'close');
originalFields.forEach(({ selector, value }) => {
cy.validateContent(selector, value);
});
});
it('Should clone selected route', () => {
cy.get(
'tbody > tr:last-child > :nth-child(1) > .q-checkbox > .q-checkbox__inner',
).click();
cy.get(
'#st-actions > .q-btn-group > :nth-child(1) > .q-btn__content > .q-icon',
).click();
cy.get(selectors.lastRowSelectCheckBox).click();
cy.get(selectors.cloneBtn).click();
cy.dataCy('route.Starting date_inputDate').type('10-05-2001{enter}');
cy.get('.q-card__actions > .q-btn--standard > .q-btn__content').click();
cy.validateContent('tr:last-child > [data-col-field="dated"]', '05/10/2001');
cy.validateContent(selectors.date, '05/10/2001');
});
it('Should download selected route', () => {
const downloadsFolder = Cypress.config('downloadsFolder');
cy.get(
'tbody > tr:last-child > :nth-child(1) > .q-checkbox > .q-checkbox__inner',
).click();
cy.get(
'#st-actions > .q-btn-group > :nth-child(2) > .q-btn__content > .q-icon',
).click();
cy.get(selectors.lastRowSelectCheckBox).click();
cy.get(selectors.downloadBtn).click();
cy.wait(5000); //necesario para dar tiempo a que descargue el documento
const fileName = 'download.zip';
@ -115,60 +147,35 @@ describe('Route extended list', () => {
});
it('Should mark as served the selected route', () => {
cy.get(
'tbody > tr:last-child > :nth-child(1) > .q-checkbox > .q-checkbox__inner',
).click();
cy.get(
'#st-actions > .q-btn-group > :nth-child(3) > .q-btn__content > .q-icon',
).click();
cy.get(selectors.lastRowSelectCheckBox).click();
cy.get(selectors.markServedBtn).click();
cy.typeSearchbar('{enter}');
cy.validateContent('tr:last-child > [data-col-field="isOk"]', 'check');
cy.validateContent(selectors.served, checkboxState.check);
});
it('Should delete the selected route', () => {
cy.get(
'tbody > tr:last-child > :nth-child(1) > .q-checkbox > .q-checkbox__inner',
).click();
cy.get(selectors.lastRowSelectCheckBox).click();
cy.get('[title="Remove"]').click();
cy.dataCy('VnConfirm_confirm').click();
cy.get(selectors.removeBtn).click();
cy.dataCy(selectors.confirmBtn).click();
cy.checkNotification('Data saved');
cy.checkNotification(dataSaved);
});
it('Should save changes in route', () => {
cy.get(worker).should('be.visible').click();
cy.dataCy('null_select').clear().type('salesperson');
cy.get('.q-item').contains('salesperson').click();
updateFields.forEach(({ selector, type, value }) => {
fillField(selector, type, value);
});
cy.get(agency).should('be.visible').click();
cy.dataCy('null_select').clear().type('inhouse pickup');
cy.get('.q-item').contains('inhouse pickup').click();
cy.get(vehicle).should('be.visible').click();
cy.dataCy('null_select').clear().type('1111-IMK');
cy.get('.q-item').contains('1111-IMK').click();
cy.get(date).should('be.visible').click();
cy.dataCy('null_inputDate').clear().type('01-01-2001{enter}');
cy.get(description).should('be.visible').click();
cy.dataCy('null_input').clear().type('DescriptionUpdated{enter}');
cy.get(served).should('be.visible').click().click();
cy.dataCy('crudModelDefaultSaveBtn').should('not.be.disabled').click();
cy.checkNotification('Data saved');
cy.dataCy(selectors.saveBtn).should('not.be.disabled').click();
cy.checkNotification(dataSaved);
cy.typeSearchbar('{enter}');
cy.validateContent(worker, 'salesperson');
cy.validateContent(agency, 'inhouse pickup');
cy.validateContent(vehicle, '1111-IMK');
cy.validateContent(date, '01/01/2001');
cy.validateContent(description, 'DescriptionUpdated');
cy.validateContent(served, 'check');
updateFields.forEach(({ selector, value }) => {
cy.validateContent(selector, value);
});
});
it('Should add ticket to route', () => {
@ -177,12 +184,12 @@ describe('Route extended list', () => {
'.q-card > :nth-child(2) > .q-table__container > .q-table__middle > .q-table > tbody > :nth-child(1) > .q-table--col-auto-width > .q-checkbox > .q-checkbox__inner > .q-checkbox__bg > .q-checkbox__svg',
).click();
cy.get('.q-card__actions > .q-btn--standard > .q-btn__content').click();
cy.get('.q-notification__message').should('have.text', 'Data saved');
cy.checkNotification(dataSaved);
});
it('Should open summary pop-up when click summuary icon', () => {
cy.dataCy('tableAction-1').last().click();
cy.get('.summaryHeader > :nth-child(2').should('contain', '- DescriptionUpdated');
cy.get('.summaryHeader > :nth-child(2').should('contain', updateFields[4].value);
});
it('Should redirect to the summary from the route summary pop-up', () => {