From 277b07e576dcbcb9d7b7c7ed116fec61b3f792b7 Mon Sep 17 00:00:00 2001 From: murage Date: Mon, 18 Oct 2021 00:19:04 +0300 Subject: [PATCH 1/7] fix: async task should return a promise that resolves to a val --- cypress/plugins/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js index bf9caece..efc87574 100644 --- a/cypress/plugins/index.js +++ b/cypress/plugins/index.js @@ -26,10 +26,10 @@ module.exports = (on, config) => { on('task', { 'unzip:h5p': async () => { - await fs.createReadStream(`${workspace}${h5pFile}`) + return await fs.createReadStream(`${workspace}${h5pFile}`) .pipe(unzipper.Extract({path: `${workspace}${extractFolder}`})) - .promise(); - return true; + .promise() + .then(() => true); }, 'copy:libraries': () => { const H5PLibraries = ['Drop-1.0', 'FontAwesome-4.5', 'H5P.FontIcons-1.0', 'H5P.JoubelUI-1.3', From 893ba087d5884d382de30aa375027fb5c7c69100 Mon Sep 17 00:00:00 2001 From: murage Date: Mon, 1 Nov 2021 18:02:19 +0300 Subject: [PATCH 2/7] test(e2e): add cypress command to select iframe DOM elements --- .gitignore | 20 +++++++++++++++++++- cypress/support/commands.js | 4 ++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4d09ff3d..86dc7995 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,22 @@ node_modules .DS_Store cypress/videos -dist \ No newline at end of file +dist +.idea + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history/* \ No newline at end of file diff --git a/cypress/support/commands.js b/cypress/support/commands.js index ca4d256f..c229218d 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -23,3 +23,7 @@ // // -- This will overwrite an existing command -- // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) + +Cypress.Commands.add("iframe", (selector) => { + return cy.get(selector).its("0.contentDocument.body").then(cy.wrap); +}); From dd847f010d23ec8056fa835d2c7d637cfd90184c Mon Sep 17 00:00:00 2001 From: murage Date: Mon, 1 Nov 2021 18:07:48 +0300 Subject: [PATCH 3/7] test(e2e): refactor basic single player h5p tests --- cypress/integration/single.spec.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/cypress/integration/single.spec.js b/cypress/integration/single.spec.js index 86a58b98..6c494c7f 100644 --- a/cypress/integration/single.spec.js +++ b/cypress/integration/single.spec.js @@ -1,16 +1,19 @@ -describe('single', () => { - it('should display h5p', () => { - - cy.visit('test/single.html'); - - cy.get('.h5p-iframe').should(iframe => { - expect(iframe.contents().find('.h5p-content')).to.exist; +describe("Single H5P player", () => { + beforeEach(() => { + cy.visit("test/single.html"); + }); - iframe.contents().find('.h5p-true-false-answer').click(); + it("should display h5p", () => { + cy.iframe("iframe.h5p-iframe.h5p-iframe.h5p-initialized") + .should("be.visible") + .within(() => { + cy.get(".h5p-true-false-answers .h5p-true-false-answer") + .contains("False") + .click(); - iframe.contents().find('.h5p-question-check-answer').click(); + cy.get(".h5p-question-check-answer").click(); - expect(iframe.contents().find('.h5p-joubelui-score-bar-star')).to.exist; - }); + cy.get(".h5p-joubelui-score-bar-star").should("be.visible"); + }); }); -}); \ No newline at end of file +}); From d1dbdb154f0f76df78d739ff2ff03ce51033e8df Mon Sep 17 00:00:00 2001 From: murage Date: Mon, 1 Nov 2021 18:08:10 +0300 Subject: [PATCH 4/7] test(e2e): refactor basic multiple player h5p tests --- cypress/integration/multiple.spec.js | 36 ++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/cypress/integration/multiple.spec.js b/cypress/integration/multiple.spec.js index d29f93dd..690f2ef2 100644 --- a/cypress/integration/multiple.spec.js +++ b/cypress/integration/multiple.spec.js @@ -1,14 +1,30 @@ -describe('multiple', () => { - it('should display 2 h5ps', () => { +describe("Multiple H5P players", () => { + beforeEach(() => { + cy.visit("test/multiple.html"); + }); + + it("should display & load multiple h5p players", () => { + cy.iframe("#h5p-container-1 iframe.h5p-iframe.h5p-iframe.h5p-initialized") + .should("be.visible") + .within(() => { + cy.get(".h5p-true-false-answers .h5p-true-false-answer") + .contains("False") + .click(); + + cy.get(".h5p-question-check-answer").click(); - cy.visit('test/multiple.html'); + cy.get(".h5p-joubelui-score-bar-star").should("be.visible"); + }); + cy.iframe("#h5p-container-2 iframe.h5p-iframe.h5p-iframe.h5p-initialized") + .should("be.visible") + .within(() => { + cy.get(".h5p-true-false-answers .h5p-true-false-answer") + .contains("False") + .click(); - cy.get('#h5p-container-1 .h5p-iframe').should(iframe => { - expect(iframe.contents().find('.h5p-content')).to.exist; - }); + cy.get(".h5p-question-check-answer").click(); - cy.get('#h5p-container-2 .h5p-iframe').should(iframe => { - expect(iframe.contents().find('.h5p-content')).to.exist; - }); + cy.get(".h5p-joubelui-score-bar-star").should("be.visible"); + }); }); -}); \ No newline at end of file +}); From b45d3dbbaa371dc38d53081625abc67b7c2acb9d Mon Sep 17 00:00:00 2001 From: murage Date: Mon, 1 Nov 2021 18:08:49 +0300 Subject: [PATCH 5/7] test(e2e): refactor h5p player w/ external libraries tests --- .../integration/external_libraries.spec.js | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/cypress/integration/external_libraries.spec.js b/cypress/integration/external_libraries.spec.js index 5c67e7dc..be75953b 100644 --- a/cypress/integration/external_libraries.spec.js +++ b/cypress/integration/external_libraries.spec.js @@ -1,16 +1,19 @@ -describe('external libraries', () => { - it('should display h5p', () => { - - cy.visit('test/external_libraries.html'); - - cy.get('.h5p-iframe').should(iframe => { - expect(iframe.contents().find('.h5p-content')).to.exist; +describe("H5P player loading external libraries", () => { + beforeEach(() => { + cy.visit("test/external_libraries.html"); + }); - iframe.contents().find('.h5p-true-false-answer').click(); + it("should display h5p", () => { + cy.iframe("iframe.h5p-iframe.h5p-iframe.h5p-initialized") + .should("be.visible") + .within(() => { + cy.get(".h5p-true-false-answers .h5p-true-false-answer") + .contains("False") + .click(); - iframe.contents().find('.h5p-question-check-answer').click(); + cy.get(".h5p-question-check-answer").click(); - expect(iframe.contents().find('.h5p-joubelui-score-bar-star')).to.exist; - }); + cy.get(".h5p-joubelui-score-bar-star").should("be.visible"); + }); }); -}); \ No newline at end of file +}); From fa70bc39afecb189802025dd0f115e7a839c0f44 Mon Sep 17 00:00:00 2001 From: murage Date: Mon, 1 Nov 2021 18:09:22 +0300 Subject: [PATCH 6/7] test(e2e): refactor h5p player with advance options tests --- cypress/integration/advance-options.spec.js | 70 +++++++++------------ 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/cypress/integration/advance-options.spec.js b/cypress/integration/advance-options.spec.js index 2bea0636..57df0330 100644 --- a/cypress/integration/advance-options.spec.js +++ b/cypress/integration/advance-options.spec.js @@ -1,43 +1,35 @@ -describe('single', () => { - it('should display h5p', () => { - - cy.visit('test/advance-options.html'); - - cy.get('.h5p-iframe').should(iframe => { - expect(iframe.contents().find('.h5p-content')).to.exist; - - iframe.contents().find('.h5p-true-false-answer').click(); - - iframe.contents().find('.h5p-question-check-answer').click(); - - expect(iframe.contents().find('.h5p-joubelui-score-bar-star')).to.exist; - - expect(iframe.contents().find('.h5p-actions').find('.h5p-export')).to.exist; - - iframe.contents() - .find('.h5p-actions') - .find('.h5p-export') - .click(); - - expect(iframe.contents().find('.h5p-download-button')).to.exist; - }); +describe("H5P player with advance options", () => { + beforeEach(() => { + cy.visit("test/advance-options.html"); + }); + + it("should display h5p", () => { + cy.iframe("iframe.h5p-iframe.h5p-iframe.h5p-initialized") + .should("be.visible") + .within(() => { + cy.get(".h5p-true-false-answers .h5p-true-false-answer") + .contains("False") + .click(); + + cy.get(".h5p-question-check-answer").click(); + cy.get(".h5p-joubelui-score-bar-star").should("be.visible"); + }); + }); + + it("should display export dialog", () => { + cy.iframe("iframe.h5p-iframe.h5p-iframe.h5p-initialized").within(() => { + cy.get(".h5p-actions").find(".h5p-export").should("be.visible").click(); + + cy.get(".h5p-download-button").should("be.visible"); }); + }); - it('should display embed code dialog', () => { - - cy.visit('test/advance-options.html'); - cy.get('.h5p-iframe').should((iframe) => { - - expect(iframe.contents().find('.h5p-actions').find('.h5p-embed')).to.exist; - - iframe.contents() - .find('.h5p-actions') - .find('.h5p-embed') - .click(); - - expect(iframe.contents().find('.h5p-embed-code-container')).to.exist; - expect(iframe.contents().find('.h5p-embed-size')).to.exist; - }) + it("should display embed code dialog", () => { + cy.iframe("iframe.h5p-iframe.h5p-iframe.h5p-initialized").within(() => { + cy.get(".h5p-actions").find(".h5p-embed").should("be.visible").click(); + cy.get(".h5p-embed-code-container").should("be.visible"); + cy.get(".h5p-embed-size").should("be.visible"); }); -}); \ No newline at end of file + }); +}); From bdbcb3fd378a72f3af0af832d1a1b9d94f100908 Mon Sep 17 00:00:00 2001 From: murage Date: Mon, 1 Nov 2021 18:17:52 +0300 Subject: [PATCH 7/7] test(e2e): remove redundant duplicate iframe class --- cypress/integration/advance-options.spec.js | 6 +++--- cypress/integration/external_libraries.spec.js | 2 +- cypress/integration/multiple.spec.js | 4 ++-- cypress/integration/single.spec.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cypress/integration/advance-options.spec.js b/cypress/integration/advance-options.spec.js index 57df0330..a37176ce 100644 --- a/cypress/integration/advance-options.spec.js +++ b/cypress/integration/advance-options.spec.js @@ -4,7 +4,7 @@ describe("H5P player with advance options", () => { }); it("should display h5p", () => { - cy.iframe("iframe.h5p-iframe.h5p-iframe.h5p-initialized") + cy.iframe("iframe.h5p-iframe.h5p-initialized") .should("be.visible") .within(() => { cy.get(".h5p-true-false-answers .h5p-true-false-answer") @@ -17,7 +17,7 @@ describe("H5P player with advance options", () => { }); it("should display export dialog", () => { - cy.iframe("iframe.h5p-iframe.h5p-iframe.h5p-initialized").within(() => { + cy.iframe("iframe.h5p-iframe.h5p-initialized").within(() => { cy.get(".h5p-actions").find(".h5p-export").should("be.visible").click(); cy.get(".h5p-download-button").should("be.visible"); @@ -25,7 +25,7 @@ describe("H5P player with advance options", () => { }); it("should display embed code dialog", () => { - cy.iframe("iframe.h5p-iframe.h5p-iframe.h5p-initialized").within(() => { + cy.iframe("iframe.h5p-iframe.h5p-initialized").within(() => { cy.get(".h5p-actions").find(".h5p-embed").should("be.visible").click(); cy.get(".h5p-embed-code-container").should("be.visible"); diff --git a/cypress/integration/external_libraries.spec.js b/cypress/integration/external_libraries.spec.js index be75953b..aab504aa 100644 --- a/cypress/integration/external_libraries.spec.js +++ b/cypress/integration/external_libraries.spec.js @@ -4,7 +4,7 @@ describe("H5P player loading external libraries", () => { }); it("should display h5p", () => { - cy.iframe("iframe.h5p-iframe.h5p-iframe.h5p-initialized") + cy.iframe("iframe.h5p-iframe.h5p-initialized") .should("be.visible") .within(() => { cy.get(".h5p-true-false-answers .h5p-true-false-answer") diff --git a/cypress/integration/multiple.spec.js b/cypress/integration/multiple.spec.js index 690f2ef2..31ca6d96 100644 --- a/cypress/integration/multiple.spec.js +++ b/cypress/integration/multiple.spec.js @@ -4,7 +4,7 @@ describe("Multiple H5P players", () => { }); it("should display & load multiple h5p players", () => { - cy.iframe("#h5p-container-1 iframe.h5p-iframe.h5p-iframe.h5p-initialized") + cy.iframe("#h5p-container-1 iframe.h5p-iframe.h5p-initialized") .should("be.visible") .within(() => { cy.get(".h5p-true-false-answers .h5p-true-false-answer") @@ -15,7 +15,7 @@ describe("Multiple H5P players", () => { cy.get(".h5p-joubelui-score-bar-star").should("be.visible"); }); - cy.iframe("#h5p-container-2 iframe.h5p-iframe.h5p-iframe.h5p-initialized") + cy.iframe("#h5p-container-2 iframe.h5p-iframe.h5p-initialized") .should("be.visible") .within(() => { cy.get(".h5p-true-false-answers .h5p-true-false-answer") diff --git a/cypress/integration/single.spec.js b/cypress/integration/single.spec.js index 6c494c7f..4066cf1b 100644 --- a/cypress/integration/single.spec.js +++ b/cypress/integration/single.spec.js @@ -4,7 +4,7 @@ describe("Single H5P player", () => { }); it("should display h5p", () => { - cy.iframe("iframe.h5p-iframe.h5p-iframe.h5p-initialized") + cy.iframe("iframe.h5p-iframe.h5p-initialized") .should("be.visible") .within(() => { cy.get(".h5p-true-false-answers .h5p-true-false-answer")