Skip to content

Commit

Permalink
Chore: Added menu page e2e tests (Issue/167) (#168)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
lemmyadams and cahirodoherty-learningpool authored Jan 24, 2024
1 parent ec6709c commit dc44460
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/e2e/adapt-contrib-boxMenu.cy.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});

0 comments on commit dc44460

Please sign in to comment.