From 860860437e4bbd99dfb50fede7f4ecfd7065b2a4 Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Tue, 26 Mar 2024 11:16:42 +0000 Subject: [PATCH 1/4] Added slider test --- test/e2e/slider.cy.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/e2e/slider.cy.js diff --git a/test/e2e/slider.cy.js b/test/e2e/slider.cy.js new file mode 100644 index 0000000..aa7bcb2 --- /dev/null +++ b/test/e2e/slider.cy.js @@ -0,0 +1,25 @@ +describe('Slider', function () { + beforeEach(function () { + cy.getData() + cy.visit('/'); + }); + + it('should display the slider component', function () { + const sliderComponents = this.data.components.filter((component) => component._component === 'slider') + sliderComponents.forEach((sliderComponent) => { + cy.visit(`/#/preview/${sliderComponent._id}`); + const bodyWithoutHtml = sliderComponent.body.replace(/<[^>]*>/g, ''); + + cy.testQuestionButtons() + cy.testContainsOrNotExists('.slider__title', sliderComponent.displayTitle) + cy.testContainsOrNotExists('.slider__body', bodyWithoutHtml) + cy.testContainsOrNotExists('.slider__instruction', sliderComponent.instruction) + cy.get('.slider__number').should('contain', sliderComponent._scaleStart) + cy.get('.slider__number').should('contain', sliderComponent._scaleEnd) + + // 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 From cc716ee7c159dd3223eb2b38d887e4c71c4c0c05 Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Wed, 27 Mar 2024 10:53:07 +0000 Subject: [PATCH 2/4] Added stripHtml --- test/e2e/slider.cy.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/e2e/slider.cy.js b/test/e2e/slider.cy.js index aa7bcb2..cfb9ca4 100644 --- a/test/e2e/slider.cy.js +++ b/test/e2e/slider.cy.js @@ -8,11 +8,12 @@ describe('Slider', function () { const sliderComponents = this.data.components.filter((component) => component._component === 'slider') sliderComponents.forEach((sliderComponent) => { cy.visit(`/#/preview/${sliderComponent._id}`); - const bodyWithoutHtml = sliderComponent.body.replace(/<[^>]*>/g, ''); + cy.stripHtml(sliderComponent.body) + const bodyWithoutHtml = this.text; + cy.testContainsOrNotExists('.slider__body', bodyWithoutHtml) cy.testQuestionButtons() cy.testContainsOrNotExists('.slider__title', sliderComponent.displayTitle) - cy.testContainsOrNotExists('.slider__body', bodyWithoutHtml) cy.testContainsOrNotExists('.slider__instruction', sliderComponent.instruction) cy.get('.slider__number').should('contain', sliderComponent._scaleStart) cy.get('.slider__number').should('contain', sliderComponent._scaleEnd) From 716a5d37095f825f64edf01e6dc8c9f121535d09 Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Wed, 27 Mar 2024 17:55:37 +0000 Subject: [PATCH 3/4] Revised custom commands --- test/e2e/slider.cy.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/e2e/slider.cy.js b/test/e2e/slider.cy.js index cfb9ca4..e6150a2 100644 --- a/test/e2e/slider.cy.js +++ b/test/e2e/slider.cy.js @@ -8,11 +8,9 @@ describe('Slider', function () { const sliderComponents = this.data.components.filter((component) => component._component === 'slider') sliderComponents.forEach((sliderComponent) => { cy.visit(`/#/preview/${sliderComponent._id}`); - cy.stripHtml(sliderComponent.body) - const bodyWithoutHtml = this.text; + const bodyWithoutHtml = cy.helpers.stripHtml(sliderComponent.body) cy.testContainsOrNotExists('.slider__body', bodyWithoutHtml) - cy.testQuestionButtons() cy.testContainsOrNotExists('.slider__title', sliderComponent.displayTitle) cy.testContainsOrNotExists('.slider__instruction', sliderComponent.instruction) cy.get('.slider__number').should('contain', sliderComponent._scaleStart) From 7273f07446a5505abb1fc471d12984ca06ad5e82 Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Thu, 11 Apr 2024 14:32:11 +0100 Subject: [PATCH 4/4] PR feedback --- test/e2e/slider.cy.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/e2e/slider.cy.js b/test/e2e/slider.cy.js index e6150a2..c313756 100644 --- a/test/e2e/slider.cy.js +++ b/test/e2e/slider.cy.js @@ -1,24 +1,24 @@ describe('Slider', function () { beforeEach(function () { - cy.getData() + cy.getData(); cy.visit('/'); }); it('should display the slider component', function () { - const sliderComponents = this.data.components.filter((component) => component._component === 'slider') - sliderComponents.forEach((sliderComponent) => { + const sliderComponents = this.data.components.filter(component => component._component === 'slider'); + sliderComponents.forEach(sliderComponent => { cy.visit(`/#/preview/${sliderComponent._id}`); - const bodyWithoutHtml = cy.helpers.stripHtml(sliderComponent.body) - cy.testContainsOrNotExists('.slider__body', bodyWithoutHtml) - - cy.testContainsOrNotExists('.slider__title', sliderComponent.displayTitle) - cy.testContainsOrNotExists('.slider__instruction', sliderComponent.instruction) - cy.get('.slider__number').should('contain', sliderComponent._scaleStart) - cy.get('.slider__number').should('contain', sliderComponent._scaleEnd) - + const stripHtml = cy.helpers.stripHtml; + cy.testContainsOrNotExists('.slider__body', stripHtml(sliderComponent.body)); + cy.testContainsOrNotExists('.slider__title', stripHtml(sliderComponent.displayTitle)); + cy.testContainsOrNotExists('.slider__instruction', stripHtml(sliderComponent.instruction)); + + cy.get('.slider__number').should('contain', sliderComponent._scaleStart); + cy.get('.slider__number').should('contain', sliderComponent._scaleEnd); + // 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) + cy.wait(1000); }); }); }); \ No newline at end of file