Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Added menu page e2e tests (Issue/167) #168

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Comment on lines +21 to +49
Copy link

@eleanor-heath eleanor-heath Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, rather than putting if else conditions to test for different scenarios we should do some negative and positive testing and each scenario should go into its own test definition. For example you might have a test for it('should display information in each tile when all details exist', () => { as the positive test and another test for it('should not display information in each tile when menu item details do not exist', () => { as the negative test. You could also provide some invalid data as a negative test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also provide some invalid data as a negative test.

If I've understood this correctly - we'd need to provide some invalid data to the course to rerender, which we currently can't do.

There is as yet no way of providing the rendered course with alternative test data. The tests are performed against the provided course data only. The results of this test will consequently vary depending on the course data provided. A single run of this test does not explicitly test all potential scenarios, as would normally be expected from test cases.

The reason for this is that providing a test course for all possible scenarios for each plugin could get quite unmanageable. At the moment this is a halfway house, we have meaningful tests that are course agnostic, at a later date we can run them with various course configurations when we have a need / a strategy for doing so. We will need to work out how to provide alternative JSON and how to rerender the course in that eventuality.


I think the title as it is: should display the correct information in each tile is reasonably self descriptive - where correct information is the six properties as configured.

});
});
});
});