From 1e950a0500761f9b7d1840767e2bf1d0f2f7fbd9 Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Fri, 2 Feb 2024 09:50:15 +0000 Subject: [PATCH] Improved graphic tests for new system [wip] --- tests/e2e/graphic.cy.js | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/tests/e2e/graphic.cy.js b/tests/e2e/graphic.cy.js index 256cc1b..7ff87cb 100644 --- a/tests/e2e/graphic.cy.js +++ b/tests/e2e/graphic.cy.js @@ -1,20 +1,31 @@ -import Components from '../../src/course/en/components.json' -const graphicComponent = Components[4] - -describe('Graphic', () => { - beforeEach(() => { +describe('Graphic', function () { + beforeEach(function () { + cy.getData() cy.visit('/'); - }) + }); - it('should display the graphic component', () => { - cy.get('.menu-item').first().should('contain', 'Presentation Components').within(() => { - cy.get('button').contains('View').click() - }); + it('should display the graphic component', function () { + const graphicComponents = this.data.components.filter((component) => component._component === 'graphic') + + this.data.contentObjects.filter((page) => page._classes !== 'assessment').forEach((page) => { + cy.visit(`/#/id/${page._id}`); + 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 = graphicComponents.filter((component) => blocksOnPage.includes(component._parentId)) - cy.get('.graphic').eq(1).within(() => { - cy.get('.graphic__title').should('contain', graphicComponent.displayTitle) - cy.get('.graphic__body').should('contain', 'Graphic') - cy.get('.graphic__image').should('have.attr', 'src', graphicComponent._graphic.src) - }) + componentsOnPage.forEach(({ body, displayTitle, _graphic }) => { + const bodyWithoutHtml = body.replace(/<[^>]*>/g, ''); + + cy.testContainsOrNotExists('.graphic__title', displayTitle) + cy.testContainsOrNotExists('.graphic__body', bodyWithoutHtml) + if(_graphic.src) { + cy.get('.graphic__image').should('have.attr', 'src', _graphic.src) + } else if(_graphic.large) { + cy.get('.graphic__image').should('have.attr', 'src', _graphic.large) + } + }) + + cy.visit('/'); + }); }); });