Skip to content

Commit

Permalink
Improved graphic tests for new system [wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
lemmyadams committed Feb 2, 2024
1 parent cb987f4 commit 1e950a0
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions tests/e2e/graphic.cy.js
Original file line number Diff line number Diff line change
@@ -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('/');
});
});
});

0 comments on commit 1e950a0

Please sign in to comment.