refactor: refs #8422 add testDmsAction command for streamlined DMS operations in Cypress tests
gitea/salix-front/pipeline/pr-dev This commit is unstable Details

This commit is contained in:
Jose Antonio Tubau 2025-04-14 12:07:58 +02:00
parent b45c97e3c1
commit be877fa2b8
3 changed files with 58 additions and 25 deletions

View File

@ -306,6 +306,7 @@ defineExpose({
:data-key="$props.model" :data-key="$props.model"
:url="$props.model" :url="$props.model"
:user-filter="dmsFilter" :user-filter="dmsFilter"
search-url="dmsFilter"
:order="['dmsFk DESC']" :order="['dmsFk DESC']"
:filter="{ where: { [$props.filter]: route.params.id } }" :filter="{ where: { [$props.filter]: route.params.id } }"
auto-load auto-load

View File

@ -21,8 +21,8 @@ describe('Vehicle DMS', () => {
warehouseSelect: 'Warehouse_select', warehouseSelect: 'Warehouse_select',
typeSelect: 'Type_select', typeSelect: 'Type_select',
fileInput: 'VnDms_inputFile', fileInput: 'VnDms_inputFile',
importBtn: 'importBtn', importBtn: '[data-cy="importBtn"]',
addBtn: 'addButton', addBtn: '[data-cy="addButton"]',
saveFormBtn: 'FormModelPopup_save', saveFormBtn: 'FormModelPopup_save',
}; };
@ -61,46 +61,65 @@ describe('Vehicle DMS', () => {
cy.get(selectors.lastRowDownloadBtn).click(); cy.get(selectors.lastRowDownloadBtn).click();
cy.wait('@download').then((interception) => { cy.wait('@download').then((interception) => {
cy.log('RESPUESTA: ', JSON.stringify(interception.response));
expect(interception.response.statusCode).to.equal(200); expect(interception.response.statusCode).to.equal(200);
expect(interception.response.headers['content-disposition']).to.contain(fileName); expect(interception.response.headers['content-disposition']).to.contain(
fileName,
);
}); });
}); });
it('Should create new DMS', () => { it('Should create new DMS', () => {
cy.dataCy(selectors.addBtn).click(); const formSelectors = {
cy.fillInForm(data); actionBtn: selectors.addBtn,
cy.dataCy(selectors.fileInput).selectFile('test/cypress/fixtures/image.jpg', { fileInput: selectors.fileInput,
force: true, saveFormBtn: selectors.saveFormBtn,
}); };
cy.dataCy(selectors.saveFormBtn).click();
cy.checkNotification('Data saved'); cy.testDmsAction('create', formSelectors, data, 'Data saved');
}); });
it('Should import DMS', () => { it('Should import DMS', () => {
const data = { const data = {
Document: { val: '10', type: 'select' }, Document: { val: '10', type: 'select' },
}; };
cy.dataCy(selectors.importBtn).click(); const formSelectors = {
cy.fillInForm(data); actionBtn: selectors.importBtn,
cy.dataCy(selectors.saveFormBtn).click(); selectorContentToCheck: selectors.lastRowReference,
cy.checkNotification('Data saved'); saveFormBtn: selectors.saveFormBtn,
cy.validateContent(selectors.lastRowReference, '1'); };
cy.testDmsAction('import', formSelectors, data, 'Data saved', '1');
}); });
it('Should edit DMS', () => { it('Should edit DMS', () => {
cy.get(selectors.lastRowEditBtn).click(); const formSelectors = {
cy.fillInForm(updateData); actionBtn: selectors.lastRowEditBtn,
cy.dataCy(selectors.saveFormBtn).click(); selectorContentToCheck: selectors.lastRowReference,
cy.checkNotification('Data saved'); saveFormBtn: selectors.saveFormBtn,
cy.validateContent(selectors.lastRowReference, updateData.Reference.val); };
cy.testDmsAction(
'edit',
formSelectors,
updateData,
'Data saved',
updateData.Reference.val,
);
}); });
it('Should delete DMS', () => { it('Should delete DMS', () => {
cy.get(selectors.lastRowDeleteBtn).click(); const formSelectors = {
cy.clickConfirm(); actionBtn: selectors.lastRowDeleteBtn,
cy.checkNotification('Data deleted'); selectorContentToCheck: selectors.lastRowReference,
cy.containContent(selectors.lastRowReference, 'Vehicle:3333-BAT'); };
cy.testDmsAction(
'delete',
formSelectors,
null,
'Data deleted',
'Vehicle:3333-BAT',
);
}); });
describe('Worker pop-ups', () => { describe('Worker pop-ups', () => {

View File

@ -638,3 +638,16 @@ Cypress.Commands.add(
}); });
}, },
); );
Cypress.Commands.add('testDmsAction', (action, selectors, data, message, content) => {
cy.get(selectors.actionBtn).click();
if (action !== 'delete') cy.fillInForm(data);
if (action === 'create')
cy.dataCy(selectors.fileInput).selectFile('test/cypress/fixtures/image.jpg', {
force: true,
});
if (action === 'delete') cy.clickConfirm();
if (action !== 'delete') cy.dataCy(selectors.saveFormBtn).click();
cy.checkNotification(message);
if (action !== 'create') cy.containContent(selectors.selectorContentToCheck, content);
});