describe('FixedAssetDms', () => { const getBtnSelector = (trPosition, btnPosition) => `tr:${trPosition}-child > .text-right > .no-wrap > :nth-child(${btnPosition}) > .q-btn > .q-btn__content > .q-icon`; const selectors = { firstRowDownloadBtn: getBtnSelector('first', 1), firstRowEditBtn: getBtnSelector('first', 2), firstRowDeleteBtn: getBtnSelector('first', 3), 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', descriptorTitle: '.descriptor .title', lastRowWorkerLink: 'tr:last-child > :nth-child(8) > .q-tr > .link', summaryGoToSummaryBtn: '.summaryHeader [data-cy="goToSummaryBtn"]', descriptorOpenSummaryBtn: '.q-menu > .descriptor [data-cy="openSummaryBtn"]', descriptorGoToSummaryBtn: '.q-menu .descriptor [data-cy="goToSummaryBtn"]', summaryTitle: '.summaryHeader', referenceInput: 'Reference_input', companySelect: 'Company_select', warehouseSelect: 'Warehouse_select', fileInput: 'VnDms_inputFile', importBtn: 'importBtn', addBtn: 'addButton', saveFormBtn: 'FormModelPopup_save', }; const data = { Reference: { val: 'FixedAsset:Peter Parker' }, Company: { val: 'VNL', type: 'select' }, Warehouse: { val: 'Warehouse One', type: 'select' }, }; const updateData = { Reference: { val: 'FixedAsset:Peter Parker House' }, Company: { val: 'CCs', type: 'select' }, Warehouse: { val: 'Warehouse Two', type: 'select' }, }; const workerSummaryUrlRegex = /worker\/\d+\/summary/; beforeEach(() => { cy.viewport(1920, 1080); cy.login('developer'); cy.visit(`/#/fixed-asset/1/dms`); }); it('Should create new DMS', () => { cy.dataCy(selectors.addBtn).click(); cy.fillInForm(data); cy.dataCy(selectors.fileInput).selectFile('test/cypress/fixtures/image.jpg', { force: true, }); cy.dataCy(selectors.saveFormBtn).click(); cy.checkNotification('Data saved'); }); /* TODO: #8946 REDMINE */ it.skip('Should download DMS', () => { let fileName; cy.get(selectors.firstRowId) .invoke('text') .then((label) => { label = label.trim(); fileName = `${label}.jpg`; }); cy.intercept('GET', /\/api\/dms\/\d+\/downloadFile/).as('download'); cy.get(selectors.firstRowDownloadBtn).click(); cy.wait('@download').then((interception) => { expect(interception.response.statusCode).to.equal(200); expect(interception.response.headers['content-disposition']).to.contain( fileName, ); }); }); it('Should edit DMS', () => { cy.get(selectors.firstRowEditBtn).click(); cy.fillInForm(updateData); cy.dataCy(selectors.saveFormBtn).click(); cy.checkNotification('Data saved'); cy.validateContent(selectors.firstRowReference, updateData.Reference.val); }); it('Should delete DMS', () => { cy.get(selectors.firstRowDeleteBtn).click(); cy.clickConfirm(); cy.checkNotification('Data deleted'); cy.validateContent(selectors.firstRowReference, 'FixedAsset: Laser'); }); describe('Worker pop-ups', () => { it('Should redirect to the worker summary from worker descriptor pop-up', () => { cy.get(selectors.lastRowWorkerLink) .should('be.visible') .click() .invoke('text') .then((workerName) => { workerName = workerName.trim(); cy.get(selectors.descriptorGoToSummaryBtn).click(); cy.location().should('match', workerSummaryUrlRegex); cy.containContent(selectors.descriptorTitle, workerName); }); }); it('Should redirect to the worker summary from summary pop-up from the worker descriptor pop-up', () => { cy.get(selectors.lastRowWorkerLink) .should('be.visible') .click() .invoke('text') .then((workerName) => { workerName = workerName.trim(); cy.get(selectors.descriptorOpenSummaryBtn).click(); cy.get(selectors.summaryGoToSummaryBtn).click(); cy.location().should('match', workerSummaryUrlRegex); cy.containContent(selectors.descriptorTitle, workerName); }); }); }); });