Skip to content

Commit

Permalink
Fix: Check landing page is a boxmenu type menu (#179)
Browse files Browse the repository at this point in the history
Lovely
  • Loading branch information
cahirodoherty-learningpool authored Feb 12, 2024
1 parent 6f2ab4f commit b8ba030
Showing 1 changed file with 48 additions and 21 deletions.
69 changes: 48 additions & 21 deletions test/e2e/adapt-contrib-boxMenu.cy.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,64 @@
describe('Menu Page', function () {
beforeEach(function () {
cy.getData();
cy.getData().then((data) => {
this.boxMenus = this.data.filter(item => item._component === 'boxMenu' || item._view === 'boxMenu');
if (this.boxMenus.length) return;
this.boxMenus = this.data.filter(item => ['course', 'menu'].includes(item._type));
});

cy.visit('/');
});

it(`should have the correct title and description`, function () {
const { body, displayTitle } = this.data.course;
it(`should be an instance of a box menu content object on each menu page`, function () {
this.boxMenus.forEach((menu, index) => {
cy.visit(`#/id/${menu._id}`);
cy.get('.boxmenu').should('exist');
});
});

it(`should have the correct title and description for each menu page`, function () {
this.boxMenus.forEach((menu, index) => {
cy.visit(`#/id/${menu._id}`);

const { body, displayTitle } = menu;

cy.get('.menu__title-inner').should('contain', displayTitle);
cy.get('.menu__body-inner').should('contain', body);
cy.get('.menu__title-inner').should('contain', displayTitle);
cy.get('.menu__body-inner').should('contain', body);
});
});

it(`should display the correct number of menu tiles`, function () {
cy.get('.menu-item').should('have.length', this.data.contentObjects.length);
it(`should display the correct number of menu tiles for each menu page`, function () {
this.boxMenus.forEach((menu, index) => {
cy.visit(`#/id/${menu._id}`);

const subPages = this.data.contentObjects.filter((page) => page._parentId === menu._id);
cy.get('.menu-item').should('have.length', subPages.length);
});
});

it('should display the correct information in each tile', function () {
cy.get('.menu-item').each(($item, index) => {
cy.get($item).within(function () {
const { _graphic, body, displayTitle, duration, linkText } = this.data.contentObjects[index];
it('should display the correct information in each tile for each menu page', function () {
this.boxMenus.forEach((menu, index) => {
cy.visit(`#/id/${menu._id}`);

const subPages = this.data.contentObjects.filter((page) => page._parentId === menu._id);

cy.get('.menu-item').each(($item, index) => {
cy.get($item).within(function () {
const { _graphic, body, displayTitle, duration, linkText } = subPages[index];

cy.testContainsOrNotExists('.menu-item__title', displayTitle);
cy.testContainsOrNotExists('.menu-item__body', body);
cy.testContainsOrNotExists('.menu-item__duration', duration);
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 (_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');
}

cy.get('.menu-item__details-inner').should('contain', _graphic.alt);
cy.get('button.boxmenu-item__button').should('contain', linkText);
cy.get('.menu-item__details-inner').should('contain', _graphic.alt);
cy.get('button.boxmenu-item__button').should('contain', linkText);
});
});
});
});
Expand Down

0 comments on commit b8ba030

Please sign in to comment.