From 9907fdf2fe6d3a7a7fdd997e712e9b33de761425 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Sat, 1 Mar 2025 02:09:09 +0100 Subject: [PATCH] test: clean test --- .../ticket/negative/TicketLackDetail.spec.js | 182 ++++++++---------- test/cypress/support/commands.js | 8 + 2 files changed, 91 insertions(+), 99 deletions(-) diff --git a/test/cypress/integration/ticket/negative/TicketLackDetail.spec.js b/test/cypress/integration/ticket/negative/TicketLackDetail.spec.js index 71cee0d68..bbbe80c56 100644 --- a/test/cypress/integration/ticket/negative/TicketLackDetail.spec.js +++ b/test/cypress/integration/ticket/negative/TicketLackDetail.spec.js @@ -1,5 +1,15 @@ /// + const firstRow = 'tr.cursor-pointer > :nth-child(1)'; +const ticketId = 1000000; +const findTr = (index) => `tbody > tr > :nth-child(${index}) > div`; +const clickNotificationAction = () => { + const notification = '.q-notification'; + cy.waitForElement(notification); + cy.get(notification).should('be.visible'); + cy.get(notification).find('.q-btn').click(); + cy.get(notification).should('not.be.visible'); +}; describe('Ticket Lack detail', () => { beforeEach(() => { cy.viewport(1280, 720); @@ -19,153 +29,126 @@ describe('Ticket Lack detail', () => { describe('Table detail', () => { it('should open descriptors', () => { cy.get('.q-table').should('be.visible'); - - cy.get('[data-col-field="zoneName"]').click(); + cy.colField('zoneName').click(); cy.dataCy('zoneDescriptorProxy').should('be.visible'); cy.get('.q-item > .q-item__label').should('have.text', ' #1'); - cy.get('[data-col-field="ticketFk"]').click(); + cy.colField('ticketFk').click(); cy.dataCy('ticketDescriptorProxy').should('be.visible'); - cy.get('.q-item > .q-item__label').should('have.text', ' #1000000'); - cy.get('[data-col-field="nickname"] > .no-padding > .link').click(); + cy.get('.q-item > .q-item__label').should('have.text', ` #${ticketId}`); + cy.colField('nickname').find('.link').click(); cy.waitForElement('[data-cy="customerDescriptorProxy"]'); cy.dataCy('customerDescriptorProxy').should('be.visible'); cy.get('.q-item > .q-item__label').should('have.text', ' #1'); }); it('should display only one row in the lack list', () => { - cy.get('[data-cy="changeItem"]').should('be.disabled'); - cy.get('[data-cy="changeState"]').should('be.disabled'); - cy.get('[data-cy="changeQuantity"]').should('be.disabled'); - cy.get('[data-cy="itemProposal"]').should('be.disabled'); - cy.get('[data-cy="transferLines"]').should('be.disabled'); + cy.dataCy('changeItem').should('be.disabled'); + cy.dataCy('changeState').should('be.disabled'); + cy.dataCy('changeQuantity').should('be.disabled'); + cy.dataCy('itemProposal').should('be.disabled'); + cy.dataCy('transferLines').should('be.disabled'); cy.get('tr.cursor-pointer > :nth-child(1)').click(); - cy.get('[data-cy="changeItem"]').should('be.enabled'); - cy.get('[data-cy="changeState"]').should('be.enabled'); - cy.get('[data-cy="changeQuantity"]').should('be.enabled'); - cy.get('[data-cy="itemProposal"]').should('be.enabled'); - cy.get('[data-cy="transferLines"]').should('be.enabled'); + cy.dataCy('changeItem').should('be.enabled'); + cy.dataCy('changeState').should('be.enabled'); + cy.dataCy('changeQuantity').should('be.enabled'); + cy.dataCy('itemProposal').should('be.enabled'); + cy.dataCy('transferLines').should('be.enabled'); }); }); describe('Split', () => { beforeEach(() => { cy.get(firstRow).click(); - cy.get('[data-cy="transferLines"]').click(); + cy.dataCy('transferLines').click(); }); it('Split', () => { - cy.get('[data-cy="ticketTransferPopup"] > .flex > .q-btn').click(); - cy.get('.q-notification').should('be.visible'); - cy.get('.q-notification').find('.q-btn').click(); - cy.get('.q-notification').should('not.be.visible'); + cy.dataCy('ticketTransferPopup').find('.flex > .q-btn').click(); - cy.get('[data-cy="handleSplitDialog"]').should('be.visible'); - cy.get('[data-cy="handleSplitDialog"]').find( - 'tbody > tr > :nth-child(1) > .q-icon', - ); - cy.get('[data-cy="handleSplitDialog"]') - .find('tbody > tr > :nth-child(2) > div') - .should('have.class', 'link'); - cy.get('[data-cy="handleSplitDialog"]') - .find('tbody > tr > :nth-child(2) > div.link > div > span') - .should('have.text', '1000000 '); - cy.get('[data-cy="handleSplitDialog"]') - .find('tbody > tr > :nth-child(3) > div') - .should('have.text', 'noSplit'); + clickNotificationAction(); + + cy.dataCy('handleSplitDialog').should('be.visible'); + cy.dataCy('handleSplitDialog').find('tbody > tr > :nth-child(1) > .q-icon'); + cy.dataCy('handleSplitDialog').find(findTr(2)).should('have.class', 'link'); + cy.dataCy('handleSplitDialog') + .find(`${findTr(2)}.link > div > span`) + .should('have.text', `${ticketId} `); + cy.dataCy('handleSplitDialog').find(findTr(3)).should('have.text', 'noSplit'); }); }); describe('Change Item', () => { beforeEach(() => { cy.get(firstRow).click(); - cy.get('[data-cy="changeItem"]').click(); + cy.dataCy('changeItem').click(); }); it('Change failed', () => { - cy.get('[data-cy="New item_select"]').click(); + cy.dataCy('New item_select').should('be.visible').click(); cy.get('.q-item').contains('Palito rojo').click(); cy.get('.q-btn--unelevated > .q-btn__content > .block').click(); - cy.waitForElement('.q-notification'); - cy.get('.q-notification').should('be.visible'); - cy.get('.q-notification').find('.q-btn').click(); - cy.get('[data-cy="handleSplitDialog"]').should('be.visible'); - cy.get('[data-cy="handleSplitDialog"]').find( - 'tbody > tr > :nth-child(1) > .q-icon', - ); - cy.get('[data-cy="handleSplitDialog"]') - .find('tbody > tr > :nth-child(2) > div') - .should('have.class', 'link'); - cy.get('[data-cy="handleSplitDialog"]') - .find('tbody > tr > :nth-child(2) > div.link > span') - .should('have.text', '1000000'); - cy.get('[data-cy="handleSplitDialog"]') - .find('tbody > tr > :nth-child(3) > div') + clickNotificationAction(); + + cy.dataCy('handleSplitDialog').should('be.visible'); + cy.dataCy('handleSplitDialog').find('tbody > tr > :nth-child(1) > .q-icon'); + cy.dataCy('handleSplitDialog').find(findTr(2)).should('have.class', 'link'); + cy.dataCy('handleSplitDialog') + .find(`${findTr(2)}.link > span`) + .should('have.text', `${ticketId}`); + cy.dataCy('handleSplitDialog') + .find(findTr(3)) .should('have.text', 'price retrieval failed'); }); }); describe('Change state', () => { beforeEach(() => { cy.get(firstRow).click(); - cy.get('[data-cy="changeState"]').click(); + cy.dataCy('changeState').click(); }); it('Change success', () => { - cy.get('[data-cy="New state_select"]').click(); + cy.dataCy('New state_select').should('be.visible').click(); cy.get('.q-item').contains('OK').click(); cy.get('.q-btn--unelevated > .q-btn__content > .block').click(); - cy.waitForElement('.q-notification'); - cy.get('.q-notification').should('be.visible'); - cy.get('.q-notification').find('.q-btn').click(); + clickNotificationAction(); - cy.get('[data-cy="handleSplitDialog"]').should('be.visible'); - cy.get('[data-cy="handleSplitDialog"]').find( - 'tbody > tr > :nth-child(1) > .q-icon', - ); - cy.get('[data-cy="handleSplitDialog"]') - .find('tbody > tr > :nth-child(2) > div') - .should('have.class', 'link'); - cy.get('[data-cy="handleSplitDialog"]') - .find('tbody > tr > :nth-child(2) > div.link > div > span') - .should('have.text', '1000000 '); - cy.get('[data-cy="handleSplitDialog"]') - .find('tbody > tr > :nth-child(3) > div') - .should('have.text', 'OK'); + cy.dataCy('handleSplitDialog') + .should('be.visible') + .find('tbody > tr > :nth-child(1) > .q-icon'); + cy.dataCy('handleSplitDialog').find(findTr(2)).should('have.class', 'link'); + cy.dataCy('handleSplitDialog') + .find(`${findTr(2)}.link > div > span`) + .should('have.text', `${ticketId} `); + cy.dataCy('handleSplitDialog').find(findTr(3)).should('have.text', 'OK'); }); }); describe('change quantity', () => { beforeEach(() => { cy.get(firstRow).click(); - cy.get('[data-cy="changeQuantity"]').click(); + cy.dataCy('changeQuantity').click(); }); it('Change success', () => { - cy.get('[data-cy="New quantity_input"]').type(10); + cy.dataCy('New quantity_input').type(10); cy.get('.q-btn--unelevated > .q-btn__content > .block').click(); - cy.waitForElement('.q-notification'); - cy.get('.q-notification').should('be.visible'); - cy.get('.q-notification').find('.q-btn').click(); - cy.get('[data-cy="handleSplitDialog"]').should('be.visible'); - cy.get('[data-cy="handleSplitDialog"]').find( - 'tbody > tr > :nth-child(1) > .q-icon', - ); - cy.get('[data-cy="handleSplitDialog"]') - .find('tbody > tr > :nth-child(2) > div') - .should('have.class', 'link'); - cy.get('[data-cy="handleSplitDialog"]') - .find('tbody > tr > :nth-child(2) > div.link > div > span') - .should('have.text', '1000000 '); - cy.get('[data-cy="handleSplitDialog"]') - .find('tbody > tr > :nth-child(3) > div') - .should('have.text', '10'); + clickNotificationAction(); + + cy.dataCy('handleSplitDialog') + .should('be.visible') + .find('tbody > tr > :nth-child(1) > .q-icon'); + cy.dataCy('handleSplitDialog').find(findTr(2)).should('have.class', 'link'); + cy.dataCy('handleSplitDialog') + .find(`${findTr(2)}.link > div > span`) + .should('have.text', `${ticketId} `); + cy.dataCy('handleSplitDialog').find(findTr(3)).should('have.text', '10'); }); }); describe('Item proposal', () => { beforeEach(() => { cy.get(firstRow).click(); - - cy.get('[data-cy="itemProposal"]').click(); + cy.dataCy('itemProposal').click(); }); describe('Replace item if', () => { - it('Quantity is less than available', () => { + it.skip('Quantity is less than available', () => { cy.get(':nth-child(1) > .text-right > .q-btn').click(); }); @@ -175,18 +158,19 @@ describe('Ticket Lack detail', () => { ).should('not.be.visible'); cy.get('[data-col-field="longName"] .link').first().click(); + cy.dataCy('itemDescriptorProxy').should('be.visible'); - cy.get( - ':nth-child(2) > [data-col-field="longName"] > .no-padding > .q-td > .middle', - ).should('have.class', 'proposal-primary'); - cy.get( - ':nth-child(2) > [data-col-field="tag5"] > .no-padding > .match', - ).should('have.class', 'match'); - cy.get( - ':nth-child(2) > [data-col-field="tag6"] > .no-padding > .match', - ).should('have.class', 'match'); - cy.get(':nth-child(2) > [data-col-field="tag7"]').click(); + cy.colField('longName', 2) + .find('.no-padding > .q-td > .middle') + .should('have.class', 'proposal-primary'); + cy.colField('tag5', 2) + .find('.no-padding > .match') + .should('have.class', 'match'); + cy.colField('tag6', 2) + .find('.no-padding > .match') + .should('have.class', 'match'); + cy.colField('tag7', 2).click(); }); }); }); diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index aa4a1219e..a860dbf00 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -384,3 +384,11 @@ Cypress.Commands.add('clickButtonWithIcon', (iconClass) => { Cypress.Commands.add('clickButtonWithText', (buttonText) => { cy.get('.q-btn').contains(buttonText).click(); }); + +Cypress.Commands.add('colField', (name, index = null) => { + if (index) { + cy.get(`:nth-child(${index}) > [data-col-field="${name}"]`); + } else { + cy.get(`[data-col-field="${name}"]`); + } +});