From 84854587ad588b3ad1208a066eba89dd8c002dc9 Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Thu, 12 Oct 2023 13:18:40 +0100 Subject: [PATCH 1/9] Added text tests --- test/e2e/text.cy.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/e2e/text.cy.js diff --git a/test/e2e/text.cy.js b/test/e2e/text.cy.js new file mode 100644 index 0000000..32624be --- /dev/null +++ b/test/e2e/text.cy.js @@ -0,0 +1,19 @@ +import Components from '../../src/course/en/components.json' +const textComponent = Components[2] + +describe('Menu Page', () => { + beforeEach(() => { + cy.visit('/'); + }) + + it('should display the text component', () => { + cy.get('.menu-item').first().should('contain', 'Presentation Components').within(() => { + cy.get('button').contains('View').click() + }); + + cy.get('.text').eq(1).within(() => { + cy.get('.text__title').should('contain', textComponent.displayTitle) + cy.get('.text__body').should('contain', 'Text') + }) + }); +}); From 4a781929195d3852de989921e56ffbe998fe7786 Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Tue, 30 Jan 2024 11:01:08 +0000 Subject: [PATCH 2/9] Added text component test --- test/e2e/text.cy.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/test/e2e/text.cy.js b/test/e2e/text.cy.js index 32624be..d8a7639 100644 --- a/test/e2e/text.cy.js +++ b/test/e2e/text.cy.js @@ -1,19 +1,33 @@ -import Components from '../../src/course/en/components.json' -const textComponent = Components[2] +describe('Text', function () { + beforeEach(function () { + cy.getData().then(function (data) { + this.data = data; + cy.visit('/'); + }); + }); + + it('should display the text component', function () { + const textComponents = this.data.components.filter((component) => component._id = 'c-15') + const { body, displayTitle } = textComponents[2]; -describe('Menu Page', () => { - beforeEach(() => { - cy.visit('/'); - }) + const bodyWithoutHtml = body.replace(/<[^>]*>/g, ''); - it('should display the text component', () => { cy.get('.menu-item').first().should('contain', 'Presentation Components').within(() => { cy.get('button').contains('View').click() }); cy.get('.text').eq(1).within(() => { - cy.get('.text__title').should('contain', textComponent.displayTitle) - cy.get('.text__body').should('contain', 'Text') + if (displayTitle) { + cy.get('.text__title').should('contain', displayTitle); + } else { + cy.get('.text__title').should('not.exist'); + } + + if (bodyWithoutHtml) { + cy.get('.text__body').should('contain', bodyWithoutHtml); + } else { + cy.get('.text__body').should('not.exist'); + } }) }); }); From 2fe482ba16f3597813f9c3a7ecf6a4b55c2aa2d2 Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Tue, 30 Jan 2024 12:29:28 +0000 Subject: [PATCH 3/9] Using new function --- test/e2e/text.cy.js | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/test/e2e/text.cy.js b/test/e2e/text.cy.js index d8a7639..8826c70 100644 --- a/test/e2e/text.cy.js +++ b/test/e2e/text.cy.js @@ -16,18 +16,7 @@ describe('Text', function () { cy.get('button').contains('View').click() }); - cy.get('.text').eq(1).within(() => { - if (displayTitle) { - cy.get('.text__title').should('contain', displayTitle); - } else { - cy.get('.text__title').should('not.exist'); - } - - if (bodyWithoutHtml) { - cy.get('.text__body').should('contain', bodyWithoutHtml); - } else { - cy.get('.text__body').should('not.exist'); - } - }) + cy.testContainsOrNotExists('.text__title', displayTitle) + cy.testContainsOrNotExists('.text__body', bodyWithoutHtml) }); }); From 0ec131b52dc794d81f8a4d3178fecf557c8e7a56 Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Tue, 30 Jan 2024 13:03:43 +0000 Subject: [PATCH 4/9] Removed dumb mistake --- test/e2e/text.cy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/text.cy.js b/test/e2e/text.cy.js index 8826c70..73c1710 100644 --- a/test/e2e/text.cy.js +++ b/test/e2e/text.cy.js @@ -7,8 +7,8 @@ describe('Text', function () { }); it('should display the text component', function () { - const textComponents = this.data.components.filter((component) => component._id = 'c-15') - const { body, displayTitle } = textComponents[2]; + const textComponent = this.data.components.find((component) => component._id === 'c-15') + const { body, displayTitle } = textComponent; const bodyWithoutHtml = body.replace(/<[^>]*>/g, ''); From 6e516923b1554b6ec5ab08c7e641df4f2d7e0bd9 Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Tue, 30 Jan 2024 16:40:48 +0000 Subject: [PATCH 5/9] Testing every component --- test/e2e/text.cy.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/test/e2e/text.cy.js b/test/e2e/text.cy.js index 73c1710..d2437df 100644 --- a/test/e2e/text.cy.js +++ b/test/e2e/text.cy.js @@ -1,22 +1,31 @@ describe('Text', function () { beforeEach(function () { cy.getData().then(function (data) { - this.data = data; + this.pages = data.contentObjects.filter(item => item._type === 'page' && item._classes !== 'assessment'); + this.articles = data.filter(item => item._type === 'article'); + this.blocks = data.filter(item => item._type === 'block'); + this.components = data.filter(item => item._type === 'component'); cy.visit('/'); }); }); - it('should display the text component', function () { - const textComponent = this.data.components.find((component) => component._id === 'c-15') - const { body, displayTitle } = textComponent; + it('should display the text components', function () { + const textComponents = this.components.filter((component) => component._component === 'text') - const bodyWithoutHtml = body.replace(/<[^>]*>/g, ''); + this.pages.forEach((page, index) => { + cy.get('.menu-item__button').eq(index).click(); + const articlesOnPage = this.articles.filter((article) => article._parentId === page._id).map(article => article._id) + const blocksOnPage = this.blocks.filter((block) => articlesOnPage.includes(block._parentId)).map(blocks => blocks._id) + const componentsOnPage = textComponents.filter((component) => blocksOnPage.includes(component._parentId)) - cy.get('.menu-item').first().should('contain', 'Presentation Components').within(() => { - cy.get('button').contains('View').click() - }); + componentsOnPage.forEach(({ body, displayTitle }) => { + const bodyWithoutHtml = body.replace(/<[^>]*>/g, ''); + + cy.testContainsOrNotExists('.text__title', displayTitle) + cy.testContainsOrNotExists('.text__body', bodyWithoutHtml) + }) - cy.testContainsOrNotExists('.text__title', displayTitle) - cy.testContainsOrNotExists('.text__body', bodyWithoutHtml) + cy.visit('/'); + }); }); }); From beafd7a8931a55522d15731cfd8e48e123440d1d Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Wed, 31 Jan 2024 10:49:42 +0000 Subject: [PATCH 6/9] Visit page id --- test/e2e/text.cy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/text.cy.js b/test/e2e/text.cy.js index d2437df..229fe61 100644 --- a/test/e2e/text.cy.js +++ b/test/e2e/text.cy.js @@ -12,8 +12,8 @@ describe('Text', function () { it('should display the text components', function () { const textComponents = this.components.filter((component) => component._component === 'text') - this.pages.forEach((page, index) => { - cy.get('.menu-item__button').eq(index).click(); + this.pages.forEach((page) => { + cy.visit(`/#/id/${page._id}`); const articlesOnPage = this.articles.filter((article) => article._parentId === page._id).map(article => article._id) const blocksOnPage = this.blocks.filter((block) => articlesOnPage.includes(block._parentId)).map(blocks => blocks._id) const componentsOnPage = textComponents.filter((component) => blocksOnPage.includes(component._parentId)) From 8488e3922f7e764dc1bfba97add4a02d1ea441dd Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Wed, 31 Jan 2024 17:45:05 +0000 Subject: [PATCH 7/9] Updated data handle --- test/e2e/text.cy.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/test/e2e/text.cy.js b/test/e2e/text.cy.js index 229fe61..ab41ac8 100644 --- a/test/e2e/text.cy.js +++ b/test/e2e/text.cy.js @@ -1,21 +1,16 @@ describe('Text', function () { beforeEach(function () { - cy.getData().then(function (data) { - this.pages = data.contentObjects.filter(item => item._type === 'page' && item._classes !== 'assessment'); - this.articles = data.filter(item => item._type === 'article'); - this.blocks = data.filter(item => item._type === 'block'); - this.components = data.filter(item => item._type === 'component'); - cy.visit('/'); - }); + cy.getData() + cy.visit('/'); }); it('should display the text components', function () { - const textComponents = this.components.filter((component) => component._component === 'text') + const textComponents = this.data.components.filter((component) => component._component === 'text') - this.pages.forEach((page) => { + this.data.contentObjects.filter((page) => page._classes !== 'assessment').forEach((page) => { cy.visit(`/#/id/${page._id}`); - const articlesOnPage = this.articles.filter((article) => article._parentId === page._id).map(article => article._id) - const blocksOnPage = this.blocks.filter((block) => articlesOnPage.includes(block._parentId)).map(blocks => blocks._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 = textComponents.filter((component) => blocksOnPage.includes(component._parentId)) componentsOnPage.forEach(({ body, displayTitle }) => { From 2c87514a7b896cbb10af7de85dbb3faae6894621 Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Mon, 5 Feb 2024 16:38:57 +0000 Subject: [PATCH 8/9] Updated to use preview pages --- test/e2e/text.cy.js | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/test/e2e/text.cy.js b/test/e2e/text.cy.js index ab41ac8..c93095a 100644 --- a/test/e2e/text.cy.js +++ b/test/e2e/text.cy.js @@ -6,21 +6,30 @@ describe('Text', function () { it('should display the text components', function () { const textComponents = this.data.components.filter((component) => component._component === 'text') + textComponents.forEach((textComponent) => { + cy.visit(`/#/preview/${textComponent._id}`); + const bodyWithoutHtml = textComponent.body.replace(/<[^>]*>/g, ''); + + // 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 + let waited = false + function waitOneSecond() { + return new Cypress.Promise((resolve, reject) => { + setTimeout(() => { + waited = true + + resolve() + }, 1000) + }) + } - 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 = textComponents.filter((component) => blocksOnPage.includes(component._parentId)) - - componentsOnPage.forEach(({ body, displayTitle }) => { - const bodyWithoutHtml = body.replace(/<[^>]*>/g, ''); - - cy.testContainsOrNotExists('.text__title', displayTitle) - cy.testContainsOrNotExists('.text__body', bodyWithoutHtml) + cy.wrap(null).then(() => { + return waitOneSecond().then(() => { + cy.testContainsOrNotExists('.text__title', textComponent.displayTitle) + cy.testContainsOrNotExists('.text__body', bodyWithoutHtml) + expect(waited).to.be.true + }) }) - - cy.visit('/'); }); }); }); From 99f969190a78c29cd421942375eb77d67840215c Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Wed, 7 Feb 2024 11:02:58 +0000 Subject: [PATCH 9/9] Changed back to wait --- test/e2e/text.cy.js | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/test/e2e/text.cy.js b/test/e2e/text.cy.js index c93095a..32809bc 100644 --- a/test/e2e/text.cy.js +++ b/test/e2e/text.cy.js @@ -9,27 +9,12 @@ describe('Text', function () { textComponents.forEach((textComponent) => { cy.visit(`/#/preview/${textComponent._id}`); const bodyWithoutHtml = textComponent.body.replace(/<[^>]*>/g, ''); - + + cy.testContainsOrNotExists('.text__title', textComponent.displayTitle) + cy.testContainsOrNotExists('.text__body', bodyWithoutHtml) // 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 - let waited = false - function waitOneSecond() { - return new Cypress.Promise((resolve, reject) => { - setTimeout(() => { - waited = true - - resolve() - }, 1000) - }) - } - - cy.wrap(null).then(() => { - return waitOneSecond().then(() => { - cy.testContainsOrNotExists('.text__title', textComponent.displayTitle) - cy.testContainsOrNotExists('.text__body', bodyWithoutHtml) - expect(waited).to.be.true - }) - }) + cy.wait(1000) }); }); });