From feb745353b611a62965e0e3ad514bb89f5d63c31 Mon Sep 17 00:00:00 2001 From: Lemmy Adams <103187526+lemmyadams@users.noreply.github.com> Date: Thu, 11 Apr 2024 15:27:25 +0100 Subject: [PATCH] Chore: e2e tests on mcq component (Issue/218) (#219) --- test/e2e/mcq.cy.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/e2e/mcq.cy.js diff --git a/test/e2e/mcq.cy.js b/test/e2e/mcq.cy.js new file mode 100644 index 0000000..8102602 --- /dev/null +++ b/test/e2e/mcq.cy.js @@ -0,0 +1,26 @@ +describe('Multiple Choice Question', function () { + beforeEach(function () { + cy.getData(); + cy.visit('/'); + }); + + it('should display the mcq component', function () { + const mcqComponents = this.data.components.filter(component => component._component === 'mcq'); + mcqComponents.forEach(mcqComponent => { + cy.visit(`/#/preview/${mcqComponent._id}`); + const stripHtml = cy.helpers.stripHtml; + cy.testContainsOrNotExists('.mcq__body', stripHtml(mcqComponent.body)); + cy.testContainsOrNotExists('.mcq__title', stripHtml(mcqComponent.displayTitle)); + cy.testContainsOrNotExists('.mcq__instruction', stripHtml(mcqComponent.instruction)); + + cy.get('.mcq-item').should('have.length', mcqComponent._items.length); + mcqComponent._items.forEach(item => { + cy.testContainsOrNotExists('.mcq-item__text', stripHtml(item.text)); + }); + + // Make sure the current component is tested before moving to the next one + // Custom cypress tests are async so we need to wait for them to pass first + cy.wait(1000); + }); + }); +}); \ No newline at end of file