From 3d7c2d093badf94ef50761e0d9fdf01f42329a8c Mon Sep 17 00:00:00 2001 From: Lemmy Adams <103187526+lemmyadams@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:13:24 +0100 Subject: [PATCH] Chore: e2e tests on page level progress extension (Issue/207) (#214) * Added basic e2e test * Cleanup * Update test/e2e/pageLevelProgress.cy.js Co-authored-by: Cahir O'Doherty <41006337+cahirodoherty-learningpool@users.noreply.github.com> * Update test/e2e/pageLevelProgress.cy.js Co-authored-by: Cahir O'Doherty <41006337+cahirodoherty-learningpool@users.noreply.github.com> * Update test/e2e/pageLevelProgress.cy.js Co-authored-by: Cahir O'Doherty <41006337+cahirodoherty-learningpool@users.noreply.github.com> * Update test/e2e/pageLevelProgress.cy.js Co-authored-by: Cahir O'Doherty <41006337+cahirodoherty-learningpool@users.noreply.github.com> * Update test/e2e/pageLevelProgress.cy.js Co-authored-by: Cahir O'Doherty <41006337+cahirodoherty-learningpool@users.noreply.github.com> * Update test/e2e/pageLevelProgress.cy.js Co-authored-by: Cahir O'Doherty <41006337+cahirodoherty-learningpool@users.noreply.github.com> * Lint fixes --------- Co-authored-by: Cahir O'Doherty <41006337+cahirodoherty-learningpool@users.noreply.github.com> --- test/e2e/pageLevelProgress.cy.js | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/e2e/pageLevelProgress.cy.js diff --git a/test/e2e/pageLevelProgress.cy.js b/test/e2e/pageLevelProgress.cy.js new file mode 100644 index 0000000..9f8daa7 --- /dev/null +++ b/test/e2e/pageLevelProgress.cy.js @@ -0,0 +1,42 @@ +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).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 || pageLevelProgress._isShownInNavigationBar) { + cy.get('.pagelevelprogress__indicator').should('not.exist'); + return; + }; + + 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); + 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); + }; + }); + }); +});