From 6f2ab4f6885b0762101fee33649996945320559a Mon Sep 17 00:00:00 2001 From: Cahir O'Doherty <41006337+cahirodoherty-learningpool@users.noreply.github.com> Date: Fri, 2 Feb 2024 16:38:47 +0000 Subject: [PATCH] Chore: Using testContainsOrNotExists helper function and tidy up of getData call (#177) --- test/e2e/adapt-contrib-boxMenu.cy.js | 29 ++++++---------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/test/e2e/adapt-contrib-boxMenu.cy.js b/test/e2e/adapt-contrib-boxMenu.cy.js index 4bb9a70..05a5e7d 100644 --- a/test/e2e/adapt-contrib-boxMenu.cy.js +++ b/test/e2e/adapt-contrib-boxMenu.cy.js @@ -1,9 +1,7 @@ describe('Menu Page', function () { beforeEach(function () { - cy.getData().then(function (data) { - this.data = data; - cy.visit('/'); - }); + cy.getData(); + cy.visit('/'); }); it(`should have the correct title and description`, function () { @@ -22,32 +20,17 @@ describe('Menu Page', function () { cy.get($item).within(function () { const { _graphic, body, displayTitle, duration, linkText } = this.data.contentObjects[index]; + cy.testContainsOrNotExists('.menu-item__title', displayTitle); + cy.testContainsOrNotExists('.menu-item__body', body); + cy.testContainsOrNotExists('.menu-item__duration', duration); + if (_graphic?.src) { cy.get('img.menu-item__image').should('exist').should('have.attr', 'src', _graphic.src); } else { cy.get('img.menu-item__image').should('not.exist'); } - if (displayTitle) { - cy.get('.menu-item__title').should('contain', displayTitle); - } else { - cy.get('.menu-item__title').should('not.exist'); - } - cy.get('.menu-item__details-inner').should('contain', _graphic.alt); - - if (body) { - cy.get('.menu-item__body').should('contain', body); - } else { - cy.get('.menu-item__body').should('not.exist'); - } - - if (duration) { - cy.get('.menu-item__duration').should('contain', duration); - } else { - cy.get('.menu-item__duration').should('not.exist'); - } - cy.get('button.boxmenu-item__button').should('contain', linkText); }); });