Skip to content

Chore: e2e tests on page level progress extension (Issue/207) #214

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

Merged
merged 9 commits into from
Apr 22, 2024
41 changes: 41 additions & 0 deletions test/e2e/pageLevelProgress.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
describe('Page Level Progress', function () {
beforeEach(function () {
cy.getData()
cy.visit('/')
});

it('should display the page level progress bars correctly on the menu items', function () {
const isPageLevelProgressEnabled = this.data.course._pageLevelProgress._isEnabled
// Check if PLP is enabled. Check it's visible on menu tiles
if (isPageLevelProgressEnabled) {
const pagesCount = this.data.contentObjects.filter((page) => page._pageLevelProgress._isEnabled === true).length
cy.get('.pagelevelprogress__indicator').should('have.length', pagesCount)
} else {
cy.get('.pagelevelprogress__indicator').should('not.exist')
}
});

it('should display the page level progress bars correctly on the pages', function () {
const pageLevelProgress = this.data.course._pageLevelProgress
if (!pageLevelProgress._isEnabled) return
const pages = this.data.contentObjects
pages.forEach((page) => {
cy.visit(`/#/${page._id}`);
// Only check it appears correctly if it shows in the nav bar and its enabled on the page
if (page._pageLevelProgress._isEnabled === true && pageLevelProgress._isShownInNavigationBar) {
const articlesOnPage = this.data.articles.filter((article) => article._parentId === page._id).map(article => article._id)
const blocksOnPage = this.data.blocks.filter((block) => articlesOnPage.includes(block._parentId)).map(blocks => blocks._id)
const componentsOnPage = this.data.components.filter((component) => blocksOnPage.includes(component._parentId))
const plpComponents = componentsOnPage.filter((component) => component._pageLevelProgress?._isEnabled === true)
cy.get('.pagelevelprogress__indicator').should('exist')
cy.get('button.nav__pagelevelprogress-btn').click()
// TODO: If its a random assessment more checks are necessary
if (page._classes !== 'assessment') {
cy.get('.pagelevelprogress__item').should('have.length', plpComponents.length)
}
} else {
cy.get('.pagelevelprogress__indicator').should('not.exist')
}
})
});
});