-
Notifications
You must be signed in to change notification settings - Fork 29
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 forit('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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 - wherecorrect information
is the six properties as configured.