diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index 008de0760..24329e8c7 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -455,36 +455,40 @@ Cypress.Commands.add('validateVnTableRows', (opts = {}) => { .invoke('text') .then((text) => { if (type === 'string') expect(text.trim()).to.equal(val); - if (type === 'number') { - const num = parseFloat(text.trim().replace(/[^\d.-]/g, '')); - switch (operation) { - case 'equal': - expect(num).to.equal(val); - break; - case 'greater': - expect(num).to.be.greaterThan(val); - break; - case 'less': - expect(num).to.be.lessThan(val); - break; - } - } - if (type === 'date') { - const date = moment(text.trim(), 'DD/MM/YYYY'); - const compareDate = moment(val, 'DD/MM/YYYY'); - switch (operation) { - case 'equal': - expect(text.trim()).to.equal(val); - break; - case 'before': - expect(date.isBefore(compareDate)).to.be.true; - break; - case 'after': - expect(date.isAfter(compareDate)).to.be.true; - } - } + if (type === 'number') cy.checkNumber(text, val, operation); + if (type === 'date') cy.checkDate(text, val, operation); }); } }); }); }); + +Cypress.Commands.add('checkNumber', (text, expectedVal, operation) => { + const num = parseFloat(text.trim().replace(/[^\d.-]/g, '')); // Remove the currency symbol + switch (operation) { + case 'equal': + expect(num).to.equal(expectedVal); + break; + case 'greater': + expect(num).to.be.greaterThan(expectedVal); + break; + case 'less': + expect(num).to.be.lessThan(expectedVal); + break; + } +}); + +Cypress.Commands.add('checkDate', (rawDate, expectedVal, operation) => { + const date = moment(rawDate.trim(), 'DD/MM/YYYY'); + const compareDate = moment(expectedVal, 'DD/MM/YYYY'); + switch (operation) { + case 'equal': + expect(text.trim()).to.equal(compareDate); + break; + case 'before': + expect(date.isBefore(compareDate)).to.be.true; + break; + case 'after': + expect(date.isAfter(compareDate)).to.be.true; + } +});