diff --git a/cypress.config.js b/cypress.config.js index d9cdbe7284e..7458c0b05b6 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -44,6 +44,7 @@ export default defineConfig({ supportFile: 'test/cypress/support/index.js', videosFolder: 'test/cypress/videos', downloadsFolder: 'test/cypress/downloads', + tmpUploadFolder: 'test/cypress/storage/tmp/dms', video: false, specPattern: 'test/cypress/integration/**/*.spec.js', experimentalRunAllSpecs: true, diff --git a/src/components/common/VnDms.vue b/src/components/common/VnDms.vue index 028bb9a9d97..128cee069b0 100644 --- a/src/components/common/VnDms.vue +++ b/src/components/common/VnDms.vue @@ -4,6 +4,7 @@ import { useRoute } from 'vue-router'; import { useI18n } from 'vue-i18n'; import axios from 'axios'; +import useNotify from 'src/composables/useNotify.js'; import FetchData from 'components/FetchData.vue'; import VnRow from 'components/ui/VnRow.vue'; import VnSelect from 'src/components/common/VnSelect.vue'; @@ -12,6 +13,7 @@ import FormModelPopup from 'components/FormModelPopup.vue'; const route = useRoute(); const { t } = useI18n(); +const { notify } = useNotify(); const emit = defineEmits(['onDataSaved']); const $props = defineProps({ @@ -86,11 +88,16 @@ function getUrl() { } async function save() { - const body = mapperDms(dms.value); - const response = await axios.post(getUrl(), body[0], body[1]); - emit('onDataSaved', body[1].params, response); - delete dms.value.files; - return response; + try { + const body = mapperDms(dms.value); + const response = await axios.post(getUrl(), body[0], body[1]); + emit('onDataSaved', body[1].params, response); + notify(t('globals.dataSaved'), 'positive'); + delete dms.value.files; + return response; + } catch (e) { + throw e; + } } function defaultData() { @@ -211,7 +218,7 @@ function addDefaultData(data) { } -en: +en: contentTypesInfo: Allowed file types {allowedContentTypes} EntryDmsDescription: Reference {reference} WorkersDescription: Working of employee id {reference} diff --git a/src/components/common/VnDmsList.vue b/src/components/common/VnDmsList.vue index aafa9f4babc..345870aa465 100644 --- a/src/components/common/VnDmsList.vue +++ b/src/components/common/VnDmsList.vue @@ -13,10 +13,12 @@ import VnDms from 'src/components/common/VnDms.vue'; import VnConfirm from 'components/ui/VnConfirm.vue'; import VnInputDate from 'components/common/VnInputDate.vue'; import { useSession } from 'src/composables/useSession'; +import useNotify from 'src/composables/useNotify.js'; const route = useRoute(); const quasar = useQuasar(); const { t } = useI18n(); +const { notify } = useNotify(); const rows = ref([]); const dmsRef = ref(); const formDialog = ref({}); @@ -88,7 +90,6 @@ const dmsFilter = { ], }, }, - where: { [$props.filter]: route.params.id }, }; const columns = computed(() => [ @@ -258,9 +259,16 @@ function deleteDms(dmsFk) { }, }) .onOk(async () => { - await axios.post(`${$props.deleteModel ?? $props.model}/${dmsFk}/removeFile`); - const index = rows.value.findIndex((row) => row.id == dmsFk); - rows.value.splice(index, 1); + try { + await axios.post( + `${$props.deleteModel ?? $props.model}/${dmsFk}/removeFile`, + ); + const index = rows.value.findIndex((row) => row.id == dmsFk); + rows.value.splice(index, 1); + notify(t('globals.dataDeleted'), 'positive'); + } catch (e) { + throw e; + } }); } @@ -298,7 +306,9 @@ defineExpose({ :data-key="$props.model" :url="$props.model" :user-filter="dmsFilter" + search-url="dmsFilter" :order="['dmsFk DESC']" + :filter="{ where: { [$props.filter]: route.params.id } }" auto-load @on-fetch="setData" > diff --git a/src/i18n/locale/en.yml b/src/i18n/locale/en.yml index de5a27ff26d..5f21ea15edc 100644 --- a/src/i18n/locale/en.yml +++ b/src/i18n/locale/en.yml @@ -162,6 +162,9 @@ globals: department: Department noData: No data available vehicle: Vehicle + selectDocumentId: Select document id + document: Document + import: Import from existing pageTitles: logIn: Login addressEdit: Update address diff --git a/src/i18n/locale/es.yml b/src/i18n/locale/es.yml index 84ba150c4b4..fcaac9790ab 100644 --- a/src/i18n/locale/es.yml +++ b/src/i18n/locale/es.yml @@ -166,6 +166,9 @@ globals: noData: Datos no disponibles department: Departamento vehicle: Vehículo + selectDocumentId: Seleccione el id de gestión documental + document: Documento + import: Importar desde existente pageTitles: logIn: Inicio de sesión addressEdit: Modificar consignatario diff --git a/src/pages/Route/Vehicle/Card/VehicleDmsImportForm.vue b/src/pages/Route/Vehicle/Card/VehicleDmsImportForm.vue new file mode 100644 index 00000000000..ade3e6dc5b8 --- /dev/null +++ b/src/pages/Route/Vehicle/Card/VehicleDmsImportForm.vue @@ -0,0 +1,65 @@ + + + diff --git a/src/pages/Route/Vehicle/VehicleDms.vue b/src/pages/Route/Vehicle/VehicleDms.vue new file mode 100644 index 00000000000..61f608d6c12 --- /dev/null +++ b/src/pages/Route/Vehicle/VehicleDms.vue @@ -0,0 +1,42 @@ + + diff --git a/src/pages/Route/Vehicle/locale/en.yml b/src/pages/Route/Vehicle/locale/en.yml index c92022f9d29..af6f78fd16a 100644 --- a/src/pages/Route/Vehicle/locale/en.yml +++ b/src/pages/Route/Vehicle/locale/en.yml @@ -18,3 +18,5 @@ vehicle: params: vehicleTypeFk: Type vehicleStateFk: State + errors: + documentIdEmpty: The document identifier can't be empty diff --git a/src/pages/Route/Vehicle/locale/es.yml b/src/pages/Route/Vehicle/locale/es.yml index c878f97ac56..9fd0d3e9148 100644 --- a/src/pages/Route/Vehicle/locale/es.yml +++ b/src/pages/Route/Vehicle/locale/es.yml @@ -18,3 +18,5 @@ vehicle: params: vehicleTypeFk: Tipo vehicleStateFk: Estado + errors: + documentIdEmpty: El número de documento no puede estar vacío diff --git a/src/pages/Ticket/Card/TicketDmsImportForm.vue b/src/pages/Ticket/Card/TicketDmsImportForm.vue index 4b6b9c6cd7b..04cb3d75ec2 100644 --- a/src/pages/Ticket/Card/TicketDmsImportForm.vue +++ b/src/pages/Ticket/Card/TicketDmsImportForm.vue @@ -34,7 +34,7 @@ const importDms = async () => { dmsId.value = null; emit('onDataSaved'); } catch (e) { - throw new Error(e.message); + throw e; } }; @@ -49,7 +49,7 @@ const importDms = async () => { @@ -70,7 +70,6 @@ const importDms = async () => { es: - Select document id: Introduzca id de gestion documental Document: Documento The document indentifier can't be empty: El número de documento no puede estar vacío diff --git a/src/router/modules/route.js b/src/router/modules/route.js index 0dd41c86eeb..2b7cfc5be30 100644 --- a/src/router/modules/route.js +++ b/src/router/modules/route.js @@ -166,7 +166,11 @@ const vehicleCard = { component: () => import('src/pages/Route/Vehicle/Card/VehicleCard.vue'), redirect: { name: 'VehicleSummary' }, meta: { - menu: ['VehicleBasicData', 'VehicleNotes'], + menu: [ + 'VehicleBasicData', + 'VehicleNotes', + 'VehicleDms', + ], }, children: [ { @@ -195,7 +199,16 @@ const vehicleCard = { icon: 'vn:notes', }, component: () => import('src/pages/Route/Vehicle/Card/VehicleNotes.vue'), - } + }, + { + name: 'VehicleDms', + path: 'dms', + meta: { + title: 'dms', + icon: 'cloud_upload', + }, + component: () => import('src/pages/Route/Vehicle/VehicleDms.vue'), + }, ], }; diff --git a/test/cypress/integration/route/routeAutonomous.spec.js b/test/cypress/integration/route/routeAutonomous.spec.js index 0e25be7a458..b61431bfb3d 100644 --- a/test/cypress/integration/route/routeAutonomous.spec.js +++ b/test/cypress/integration/route/routeAutonomous.spec.js @@ -1,11 +1,12 @@ describe('RouteAutonomous', () => { - const getLinkSelector = (colField) => - `tr:first-child > [data-col-field="${colField}"] > .no-padding > .link`; + const getLinkSelector = (colField, link = true) => + `tr:first-child > [data-col-field="${colField}"] > .no-padding${link ? ' > .link' : ''}`; const selectors = { - reference: 'Reference_input', - date: 'tr:first-child > [data-col-field="dated"]', total: '.value > .text-h6', + routeId: getLinkSelector('routeFk', false), + agencyRoute: getLinkSelector('agencyModeName'), + agencyAgreement: getLinkSelector('agencyAgreement'), received: getLinkSelector('invoiceInFk'), autonomous: getLinkSelector('supplierName'), firstRowCheckbox: '.q-virtual-scroll__content tr:first-child .q-checkbox__bg', @@ -13,22 +14,30 @@ describe('RouteAutonomous', () => { createInvoiceBtn: '.q-card > .q-btn', saveFormBtn: 'FormModelPopup_save', summaryIcon: 'tableAction-0', - summaryPopupBtn: '.header > :nth-child(2) > .q-btn__content > .q-icon', - summaryHeader: '.summaryHeader > :nth-child(2)', - descriptorHeader: '.summaryHeader > div', - descriptorTitle: '.q-item__label--header > .title > span', - summaryGoToSummaryBtn: '.header > .q-icon', - descriptorGoToSummaryBtn: '.descriptor > .header > a[href] > .q-btn', + descriptorRouteSubtitle: '[data-cy="vnDescriptor_subtitle"]', + descriptorAgencyAndSupplierTitle: '[data-cy="vnDescriptor_description"]', + descriptorInvoiceInTitle: '[data-cy="vnDescriptor_title"]', + descriptorOpenSummaryBtn: '.q-menu > .descriptor [data-cy="openSummaryBtn"]', + descriptorGoToSummaryBtn: '.q-menu > .descriptor [data-cy="goToSummaryBtn"]', + summaryGoToSummaryBtn: '.summaryHeader [data-cy="goToSummaryBtn"]', }; - const data = { - reference: 'Test invoice', - total: '€206.40', - supplier: 'PLANTS SL', - route: 'first route', + const newInvoice = { + Reference: { val: 'Test invoice' }, + Company: { val: 'VNL', type: 'select' }, + Warehouse: { val: 'Warehouse One', type: 'select' }, + Type: { val: 'Vehiculos', type: 'select' }, + Description: { val: 'Test description' }, }; - const summaryUrl = '/summary'; + const total = '€206.40'; + + const urls = { + summaryAgencyUrlRegex: /agency\/\d+\/summary/, + summaryInvoiceInUrlRegex: /invoice-in\/\d+\/summary/, + summarySupplierUrlRegex: /supplier\/\d+\/summary/, + summaryRouteUrlRegex: /route\/\d+\/summary/, + }; const dataSaved = 'Data saved'; beforeEach(() => { @@ -47,7 +56,7 @@ describe('RouteAutonomous', () => { it.skip('Should create invoice in to selected route', () => { cy.get(selectors.firstRowCheckbox).click(); cy.get(selectors.createInvoiceBtn).click(); - cy.dataCy(selectors.reference).type(data.reference); + cy.fillInForm(newInvoice); cy.dataCy('attachFile').click(); cy.get('.q-file').selectFile('test/cypress/fixtures/image.jpg', { force: true, @@ -59,62 +68,120 @@ describe('RouteAutonomous', () => { it('Should display the total price of the selected rows', () => { cy.get(selectors.firstRowCheckbox).click(); cy.get(selectors.secondRowCheckbox).click(); - cy.validateContent(selectors.total, data.total); + cy.validateContent(selectors.total, total); }); it('Should redirect to the summary when clicking a route', () => { - cy.get(selectors.date).click(); - cy.get(selectors.summaryHeader).should('contain', data.route); - cy.url().should('include', summaryUrl); + cy.checkRedirectionFromPopUp({ + selectorToClick: selectors.routeId, + expectedUrlRegex: urls.summaryRouteUrlRegex, + expectedTextSelector: selectors.descriptorRouteSubtitle, + }); }); - describe.skip('Received pop-ups', () => { - it('Should redirect to invoice in summary from the received descriptor pop-up', () => { - cy.get(selectors.received).click(); - cy.validateContent(selectors.descriptorTitle, data.reference); - cy.get(selectors.descriptorGoToSummaryBtn).click(); - cy.get(selectors.descriptorHeader).should('contain', data.supplier); - cy.url().should('include', summaryUrl); + describe('Agency route pop-ups', () => { + it('Should redirect to the agency route summary from the agency route descriptor pop-up', () => { + cy.checkRedirectionFromPopUp({ + selectorToClick: selectors.agencyRoute, + steps: [selectors.descriptorGoToSummaryBtn], + expectedUrlRegex: urls.summaryAgencyUrlRegex, + expectedTextSelector: selectors.descriptorAgencyAndSupplierTitle, + }); + }); + + it('Should redirect to the agency route summary from summary pop-up from the agency route descriptor pop-up', () => { + cy.checkRedirectionFromPopUp({ + selectorToClick: selectors.agencyRoute, + steps: [ + selectors.descriptorOpenSummaryBtn, + selectors.summaryGoToSummaryBtn, + ], + expectedUrlRegex: urls.summaryAgencyUrlRegex, + expectedTextSelector: selectors.descriptorAgencyAndSupplierTitle, + }); + }); + }); + + describe('Agency route pop-ups', () => { + it('Should redirect to the agency agreement summary from the agency agreement descriptor pop-up', () => { + cy.checkRedirectionFromPopUp({ + selectorToClick: selectors.agencyAgreement, + steps: [selectors.descriptorGoToSummaryBtn], + expectedUrlRegex: urls.summaryAgencyUrlRegex, + expectedTextSelector: selectors.descriptorAgencyAndSupplierTitle, + }); + }); + + it('Should redirect to the agency agreement summary from summary pop-up from the agency agreement descriptor pop-up', () => { + cy.checkRedirectionFromPopUp({ + selectorToClick: selectors.agencyAgreement, + steps: [ + selectors.descriptorOpenSummaryBtn, + selectors.summaryGoToSummaryBtn, + ], + expectedUrlRegex: urls.summaryAgencyUrlRegex, + expectedTextSelector: selectors.descriptorAgencyAndSupplierTitle, + }); + }); + }); + + describe('Received pop-ups', () => { + it('Should redirect to the invoice in summary from the received descriptor pop-up', () => { + cy.checkRedirectionFromPopUp({ + selectorToClick: selectors.received, + steps: [selectors.descriptorGoToSummaryBtn], + expectedUrlRegex: urls.summaryInvoiceInUrlRegex, + expectedTextSelector: selectors.descriptorInvoiceInTitle, + }); }); it('Should redirect to the invoiceIn summary from summary pop-up from the received descriptor pop-up', () => { - cy.get(selectors.received).click(); - cy.validateContent(selectors.descriptorTitle, data.reference); - cy.get(selectors.summaryPopupBtn).click(); - cy.get(selectors.descriptorHeader).should('contain', data.supplier); - cy.get(selectors.summaryGoToSummaryBtn).click(); - cy.get(selectors.descriptorHeader).should('contain', data.supplier); - cy.url().should('include', summaryUrl); + cy.checkRedirectionFromPopUp({ + selectorToClick: selectors.received, + steps: [ + selectors.descriptorOpenSummaryBtn, + selectors.summaryGoToSummaryBtn, + ], + expectedUrlRegex: urls.summaryInvoiceInUrlRegex, + expectedTextSelector: selectors.descriptorInvoiceInTitle, + }); }); }); describe('Autonomous pop-ups', () => { it('Should redirect to the supplier summary from the received descriptor pop-up', () => { - cy.get(selectors.autonomous).click(); - cy.validateContent(selectors.descriptorTitle, data.supplier); - cy.get(selectors.descriptorGoToSummaryBtn).click(); - cy.get(selectors.summaryHeader).should('contain', data.supplier); - cy.url().should('include', summaryUrl); + cy.checkRedirectionFromPopUp({ + selectorToClick: selectors.autonomous, + steps: [selectors.descriptorGoToSummaryBtn], + expectedUrlRegex: urls.summarySupplierUrlRegex, + expectedTextSelector: selectors.descriptorAgencyAndSupplierTitle, + }); }); it('Should redirect to the supplier summary from summary pop-up from the autonomous descriptor pop-up', () => { - cy.get(selectors.autonomous).click(); - cy.get(selectors.descriptorTitle).should('contain', data.supplier); - cy.get(selectors.summaryPopupBtn).click(); - cy.get(selectors.summaryHeader).should('contain', data.supplier); - cy.get(selectors.summaryGoToSummaryBtn).click(); - cy.get(selectors.summaryHeader).should('contain', data.supplier); - cy.url().should('include', summaryUrl); + cy.checkRedirectionFromPopUp({ + selectorToClick: selectors.autonomous, + steps: [ + selectors.descriptorOpenSummaryBtn, + selectors.summaryGoToSummaryBtn, + ], + expectedUrlRegex: urls.summarySupplierUrlRegex, + expectedTextSelector: selectors.descriptorAgencyAndSupplierTitle, + }); }); }); describe('Route pop-ups', () => { it('Should redirect to the summary from the route summary pop-up', () => { - cy.dataCy(selectors.summaryIcon).first().click(); - cy.get(selectors.summaryHeader).should('contain', data.route); - cy.get(selectors.summaryGoToSummaryBtn).click(); - cy.get(selectors.summaryHeader).should('contain', data.route); - cy.url().should('include', summaryUrl); + cy.get(selectors.routeId) + .invoke('text') + .then((routeId) => { + routeId = routeId.trim(); + cy.dataCy(selectors.summaryIcon).first().click(); + cy.get(selectors.summaryGoToSummaryBtn).click(); + cy.url().should('match', urls.summaryRouteUrlRegex); + cy.containContent(selectors.descriptorRouteSubtitle, routeId); + }); }); }); }); diff --git a/test/cypress/integration/route/routeExtendedList.spec.js b/test/cypress/integration/route/routeExtendedList.spec.js index 83ecac122b6..d2b4e210856 100644 --- a/test/cypress/integration/route/routeExtendedList.spec.js +++ b/test/cypress/integration/route/routeExtendedList.spec.js @@ -69,7 +69,8 @@ describe.skip('Route extended list', () => { .type(`{selectall}{backspace}${value}`); break; case 'checkbox': - cy.get(selector).should('be.visible').click().click(); + cy.get(selector).should('be.visible').click() + cy.get(selector).click(); break; } } diff --git a/test/cypress/integration/route/vehicle/vehicleDms.spec.js b/test/cypress/integration/route/vehicle/vehicleDms.spec.js new file mode 100644 index 00000000000..4d9250e0f7b --- /dev/null +++ b/test/cypress/integration/route/vehicle/vehicleDms.spec.js @@ -0,0 +1,147 @@ +describe('Vehicle DMS', () => { + const getSelector = (btnPosition) => + `tr:last-child > .text-right > .no-wrap > :nth-child(${btnPosition}) > .q-btn > .q-btn__content > .q-icon`; + + const selectors = { + lastRowDownloadBtn: getSelector(1), + lastRowEditBtn: getSelector(2), + lastRowDeleteBtn: getSelector(3), + lastRowReference: 'tr:last-child > :nth-child(5) > .q-tr > :nth-child(1) > span', + firstRowReference: + 'tr:first-child > :nth-child(5) > .q-tr > :nth-child(1) > span', + firstRowId: 'tr:first-child > :nth-child(2) > .q-tr > :nth-child(1) > span', + lastRowWorkerLink: 'tr:last-child > :nth-child(8) > .q-tr > .link', + descriptorTitle: '.descriptor .title', + descriptorOpenSummaryBtn: '.q-menu .descriptor [data-cy="openSummaryBtn"]', + descriptorGoToSummaryBtn: '.q-menu .descriptor [data-cy="goToSummaryBtn"]', + summaryGoToSummaryBtn: '.summaryHeader [data-cy="goToSummaryBtn"]', + summaryTitle: '.summaryHeader', + referenceInput: 'Reference_input', + companySelect: 'Company_select', + warehouseSelect: 'Warehouse_select', + typeSelect: 'Type_select', + fileInput: 'VnDms_inputFile', + importBtn: '[data-cy="importBtn"]', + addBtn: '[data-cy="addButton"]', + saveFormBtn: 'FormModelPopup_save', + }; + + const data = { + Reference: { val: 'Vehicle:1234-ABC' }, + Company: { val: 'VNL', type: 'select' }, + Warehouse: { val: 'Warehouse One', type: 'select' }, + Type: { val: 'Vehiculos', type: 'select' }, + }; + + const updateData = { + Reference: { val: 'Vehicle:4598-FGH' }, + Company: { val: 'CCs', type: 'select' }, + Warehouse: { val: 'Warehouse Two', type: 'select' }, + Type: { val: 'Facturas Recibidas', type: 'select' }, + }; + + const workerSummaryUrlRegex = /worker\/\d+\/summary/; + + beforeEach(() => { + cy.viewport(1920, 1080); + cy.login('developer'); + cy.visit(`/#/route/vehicle/1/dms`); + }); + + it('should display vehicle DMS', () => { + cy.get('.q-table') + .children() + .should('be.visible') + .should('have.length.greaterThan', 0); + }); + + it.skip('Should download DMS', () => { + const fileName = '11.jpg'; + cy.intercept('GET', /\/api\/dms\/11\/downloadFile/).as('download'); + cy.get(selectors.lastRowDownloadBtn).click(); + + cy.wait('@download').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + expect(interception.response.headers['content-disposition']).to.contain( + fileName, + ); + }); + }); + + it('Should create new DMS', () => { + const formSelectors = { + actionBtn: selectors.addBtn, + fileInput: selectors.fileInput, + saveFormBtn: selectors.saveFormBtn, + }; + + cy.testDmsAction('create', formSelectors, data, 'Data saved'); + }); + + it('Should import DMS', () => { + const data = { + Document: { val: '10', type: 'select' }, + }; + const formSelectors = { + actionBtn: selectors.importBtn, + selectorContentToCheck: selectors.lastRowReference, + saveFormBtn: selectors.saveFormBtn, + }; + + cy.testDmsAction('import', formSelectors, data, 'Data saved', '1'); + }); + + it('Should edit DMS', () => { + const formSelectors = { + actionBtn: selectors.lastRowEditBtn, + selectorContentToCheck: selectors.lastRowReference, + saveFormBtn: selectors.saveFormBtn, + }; + + cy.testDmsAction( + 'edit', + formSelectors, + updateData, + 'Data saved', + updateData.Reference.val, + ); + }); + + it('Should delete DMS', () => { + const formSelectors = { + actionBtn: selectors.lastRowDeleteBtn, + selectorContentToCheck: selectors.lastRowReference, + }; + + cy.testDmsAction( + 'delete', + formSelectors, + null, + 'Data deleted', + 'Vehicle:3333-BAT', + ); + }); + + describe('Worker pop-ups', () => { + it('Should redirect to worker summary from worker descriptor pop-up', () => { + cy.checkRedirectionFromPopUp({ + selectorToClick: selectors.lastRowWorkerLink, + steps: [selectors.descriptorGoToSummaryBtn], + expectedUrlRegex: workerSummaryUrlRegex, + expectedTextSelector: selectors.descriptorTitle, + }); + }); + + it('Should redirect to worker summary from summary pop-up from worker descriptor pop-up', () => { + cy.checkRedirectionFromPopUp({ + selectorToClick: selectors.lastRowWorkerLink, + steps: [ + selectors.descriptorOpenSummaryBtn, + selectors.summaryGoToSummaryBtn, + ], + expectedUrlRegex: workerSummaryUrlRegex, + expectedTextSelector: selectors.descriptorTitle, + }); + }); + }); +}); diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index ac84a5e60ae..c83674e3c5b 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -635,3 +635,41 @@ Cypress.Commands.add('validateScrollContent', (validations) => { ); }); }); + +Cypress.Commands.add( + 'checkRedirectionFromPopUp', + ({ selectorToClick, steps = [], expectedUrlRegex, expectedTextSelector }) => { + cy.get(selectorToClick) + .click() + .invoke('text') + .then((label) => { + label = label.trim(); + + steps.forEach((stepSelector) => { + cy.get(stepSelector).should('be.visible').click(); + }); + + cy.location().should('match', expectedUrlRegex); + cy.containContent(expectedTextSelector, label); + }); + }, +); + +Cypress.Commands.add('testDmsAction', (action, selectors, data, message, content) => { + cy.get(selectors.actionBtn).click(); + + if (action === 'create') { + cy.dataCy(selectors.fileInput).selectFile('test/cypress/fixtures/image.jpg', { + force: true, + }); + } + + if (action !== 'delete') { + cy.fillInForm(data); + cy.dataCy(selectors.saveFormBtn).click(); + } else cy.clickConfirm(); + + cy.checkNotification(message); + + if (action !== 'create') cy.containContent(selectors.selectorContentToCheck, content); +});