From b9c9df1362bfc644321981cf50fd2108b8ae8ed7 Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Wed, 28 Feb 2024 12:26:11 +0000 Subject: [PATCH 1/4] Added media e2e test --- test/e2e/media.cy.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/e2e/media.cy.js diff --git a/test/e2e/media.cy.js b/test/e2e/media.cy.js new file mode 100644 index 0000000..fce3308 --- /dev/null +++ b/test/e2e/media.cy.js @@ -0,0 +1,34 @@ +describe('Media', function () { + beforeEach(function () { + cy.getData() + }); + + it('should display the media component', function () { + const mediaComponents = this.data.components.filter((component) => component._component === 'media') + mediaComponents.forEach((mediaComponent) => { + cy.visit(`/#/preview/${mediaComponent._id}`); + const bodyWithoutHtml = mediaComponent.body.replace(/<[^>]*>/g, ''); + + cy.testContainsOrNotExists('.media__title', mediaComponent.displayTitle) + cy.testContainsOrNotExists('.media__body', bodyWithoutHtml) + cy.testContainsOrNotExists('.media__instruction', mediaComponent.instruction) + + if(mediaComponent._media.mp4) { + cy.get('.mejs-mediaelement video').should('have.attr', 'src', mediaComponent._media.mp4) + } + if(mediaComponent._media.poster) { + cy.get('.mejs-poster img').should('have.attr', 'src', mediaComponent._media.poster) + } + + if(mediaComponent._transcript) { + cy.get('.media__transcript-body-inline').should('not.be.visible') + cy.get('button.media__transcript-btn').should('contain', mediaComponent._transcript.inlineTranscriptButton).click() + cy.get('.media__transcript-body-inline-inner').should('be.visible').should('contain', mediaComponent._transcript.inlineTranscriptBody) + cy.get('button.media__transcript-btn').should('contain', mediaComponent._transcript.inlineTranscriptCloseButton).click() + cy.get('.media__transcript-body-inline').should('not.be.visible') + } + + cy.wait(1000) + }); + }); +}); \ No newline at end of file From ae4af0c5300194c733c51a08c702c7e3f570cce5 Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Fri, 1 Mar 2024 10:04:11 +0000 Subject: [PATCH 2/4] Added comments --- test/e2e/media.cy.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/e2e/media.cy.js b/test/e2e/media.cy.js index fce3308..ce9bfe4 100644 --- a/test/e2e/media.cy.js +++ b/test/e2e/media.cy.js @@ -9,18 +9,19 @@ describe('Media', function () { cy.visit(`/#/preview/${mediaComponent._id}`); const bodyWithoutHtml = mediaComponent.body.replace(/<[^>]*>/g, ''); + // Test basic media component cy.testContainsOrNotExists('.media__title', mediaComponent.displayTitle) cy.testContainsOrNotExists('.media__body', bodyWithoutHtml) cy.testContainsOrNotExists('.media__instruction', mediaComponent.instruction) - if(mediaComponent._media.mp4) { + if (mediaComponent._media.mp4) { cy.get('.mejs-mediaelement video').should('have.attr', 'src', mediaComponent._media.mp4) } - if(mediaComponent._media.poster) { + if (mediaComponent._media.poster) { cy.get('.mejs-poster img').should('have.attr', 'src', mediaComponent._media.poster) } - if(mediaComponent._transcript) { + if (mediaComponent._transcript) { cy.get('.media__transcript-body-inline').should('not.be.visible') cy.get('button.media__transcript-btn').should('contain', mediaComponent._transcript.inlineTranscriptButton).click() cy.get('.media__transcript-body-inline-inner').should('be.visible').should('contain', mediaComponent._transcript.inlineTranscriptBody) @@ -28,6 +29,7 @@ describe('Media', function () { cy.get('.media__transcript-body-inline').should('not.be.visible') } + // Allow the component to load and run external custom tests cy.wait(1000) }); }); From 0a5ab6f734abfd411418179f5a6baafc9fd6d8df Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Mon, 17 Jun 2024 11:31:01 +0100 Subject: [PATCH 3/4] Updated test --- test/e2e/media.cy.js | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/test/e2e/media.cy.js b/test/e2e/media.cy.js index ce9bfe4..87bb4ab 100644 --- a/test/e2e/media.cy.js +++ b/test/e2e/media.cy.js @@ -1,36 +1,35 @@ describe('Media', function () { beforeEach(function () { - cy.getData() + cy.getData(); }); it('should display the media component', function () { - const mediaComponents = this.data.components.filter((component) => component._component === 'media') - mediaComponents.forEach((mediaComponent) => { + const mediaComponents = this.data.components.filter(component => component._component === 'media'); + mediaComponents.forEach(mediaComponent => { cy.visit(`/#/preview/${mediaComponent._id}`); - const bodyWithoutHtml = mediaComponent.body.replace(/<[^>]*>/g, ''); - - // Test basic media component - cy.testContainsOrNotExists('.media__title', mediaComponent.displayTitle) - cy.testContainsOrNotExists('.media__body', bodyWithoutHtml) - cy.testContainsOrNotExists('.media__instruction', mediaComponent.instruction) + const stripHtml = cy.helpers.stripHtml; + + cy.testContainsOrNotExists('.media__body', stripHtml(mediaComponent.body)); + cy.testContainsOrNotExists('.media__title', stripHtml(mediaComponent.displayTitle)); + cy.testContainsOrNotExists('.media__instruction', stripHtml(mediaComponent.instruction)); if (mediaComponent._media.mp4) { - cy.get('.mejs-mediaelement video').should('have.attr', 'src', mediaComponent._media.mp4) - } + cy.get('.mejs-mediaelement video').should('have.attr', 'src', mediaComponent._media.mp4); + }; if (mediaComponent._media.poster) { - cy.get('.mejs-poster img').should('have.attr', 'src', mediaComponent._media.poster) - } + cy.get('.mejs-poster img').should('have.attr', 'src', mediaComponent._media.poster); + }; if (mediaComponent._transcript) { - cy.get('.media__transcript-body-inline').should('not.be.visible') - cy.get('button.media__transcript-btn').should('contain', mediaComponent._transcript.inlineTranscriptButton).click() - cy.get('.media__transcript-body-inline-inner').should('be.visible').should('contain', mediaComponent._transcript.inlineTranscriptBody) - cy.get('button.media__transcript-btn').should('contain', mediaComponent._transcript.inlineTranscriptCloseButton).click() - cy.get('.media__transcript-body-inline').should('not.be.visible') - } + cy.get('.media__transcript-body-inline').should('not.be.visible'); + cy.get('button.media__transcript-btn').should('contain', mediaComponent._transcript.inlineTranscriptButton).click(); + cy.get('.media__transcript-body-inline-inner').should('be.visible').should('contain', mediaComponent._transcript.inlineTranscriptBody); + cy.get('button.media__transcript-btn').should('contain', mediaComponent._transcript.inlineTranscriptCloseButton).click(); + cy.get('.media__transcript-body-inline').should('not.be.visible'); + }; // Allow the component to load and run external custom tests - cy.wait(1000) + cy.wait(1000); }); }); }); \ No newline at end of file From 2d93a28c6a1956a350b3570ba8c122e18f3a7948 Mon Sep 17 00:00:00 2001 From: Lemmy Adams Date: Mon, 17 Jun 2024 12:37:46 +0100 Subject: [PATCH 4/4] moved out html --- test/e2e/media.cy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/media.cy.js b/test/e2e/media.cy.js index 87bb4ab..ad5f984 100644 --- a/test/e2e/media.cy.js +++ b/test/e2e/media.cy.js @@ -5,9 +5,9 @@ describe('Media', function () { it('should display the media component', function () { const mediaComponents = this.data.components.filter(component => component._component === 'media'); + const stripHtml = cy.helpers.stripHtml; mediaComponents.forEach(mediaComponent => { cy.visit(`/#/preview/${mediaComponent._id}`); - const stripHtml = cy.helpers.stripHtml; cy.testContainsOrNotExists('.media__body', stripHtml(mediaComponent.body)); cy.testContainsOrNotExists('.media__title', stripHtml(mediaComponent.displayTitle));