From dc444606135732cbe5dd53a5649e546cc019d584 Mon Sep 17 00:00:00 2001 From: Lemmy Adams <103187526+lemmyadams@users.noreply.github.com> Date: Wed, 24 Jan 2024 11:41:39 +0000 Subject: [PATCH] Chore: Added menu page e2e tests (Issue/167) (#168) * Added e2e test * Wrap menu item tests in a per-language loop and reference the course build (#173) * Wrap menu item tests in a per-language loop and reference the course build * Removing language looping from tests * Destructuring some variables * Making use of 'data' attribute that is already wrapped * Fixing paste fail * Removing duplication * Performing empty value check and testing for non-writing of element in such cases --------- Co-authored-by: Cahir O'Doherty <41006337+cahirodoherty-learningpool@users.noreply.github.com> --- test/e2e/adapt-contrib-boxMenu.cy.js | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 test/e2e/adapt-contrib-boxMenu.cy.js diff --git a/test/e2e/adapt-contrib-boxMenu.cy.js b/test/e2e/adapt-contrib-boxMenu.cy.js new file mode 100644 index 0000000..96536d4 --- /dev/null +++ b/test/e2e/adapt-contrib-boxMenu.cy.js @@ -0,0 +1,53 @@ +describe('Menu Page', () => { + beforeEach(() => { + cy.getData(); + cy.visit('/'); + }); + + it(`should have the title '${this.data.course.displayTitle}' and correct description`, () => { + const { body, displayTitle } = this.data.course; + + cy.get('.menu__title-inner').should('contain', displayTitle); + cy.get('.menu__body-inner').should('contain', body); + }); + + it(`should display the correct number (${this.data.contentObjects.length}) of menu tiles`, () => { + cy.get('.menu-item').should('have.length', this.data.contentObjects.length); + }); + + it('should display the correct information in each tile', () => { + cy.get('.menu-item').each(($item, index) => { + cy.get($item).within(() => { + const { _graphic, body, displayTitle, duration, linkText } = this.data.contentObjects[index]; + + 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); + }); + }); + }); +});