From 1e8f6894446baebd36987e8afcbc5d97d7ee811f Mon Sep 17 00:00:00 2001 From: robonetphy <1998patelumang@gmail.com> Date: Sun, 26 Mar 2023 22:02:52 +0530 Subject: [PATCH] test case for file drop added --- test/cypress/tests/dragnDrop.spec.ts | 63 ++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/test/cypress/tests/dragnDrop.spec.ts b/test/cypress/tests/dragnDrop.spec.ts index 08dde389..35db032d 100644 --- a/test/cypress/tests/dragnDrop.spec.ts +++ b/test/cypress/tests/dragnDrop.spec.ts @@ -11,6 +11,15 @@ describe("Drag and drop the block of Editor", function () { image: Image, }, }).as("editorInstance"); + + const numberOfBlocks = 5; + for (let i = 0; i < numberOfBlocks; i++) { + cy.get('[data-cy=editorjs]') + .get('div.ce-block') + .last() + .click() + .type(`Block ${i}{enter}`); + } }); afterEach(function () { @@ -18,4 +27,58 @@ describe("Drag and drop the block of Editor", function () { this.editorInstance.destroy(); } }); + + /** + * @todo check with dropping file other than the image. + */ + it("should drop file", function () { + // Read file locally + cy.readFile('example/assets/codex2x.png', 'base64').then((base64) => { + // Create URI + const uri = 'data:image/png;base64,' + base64; + // Test by dropping the image. + cy.get("[data-cy=editorjs]") + .get('div.ce-block') + .last() + .attachFile('../../../example/assets/codex2x.png', { subjectType: 'drag-n-drop' }) + .wait(10); + + cy.get('[data-cy=editorjs]') + // In Edge test are performed slower, so we need to + // increase timeout to wait until image is loaded on the page + .get('img', { timeout: 10000 }) + .should('have.attr', 'src', uri); + }) + }); + + // it("should drag the block", function () { + + // cy.get('[data-cy=editorjs]') + // .get('div.ce-block') + // .first() + // .click(); + + // const dataTransfer = new DataTransfer(); + // cy.get('.ce-toolbar__settings-btn') + // .trigger("dragstart", { dataTransfer }); + // cy.get('[data-cy=editorjs]') + // .get('div.ce-block') + // .eq(2) + // .trigger("dragenter").then((e) => { + // const bbox = e[0].getBoundingClientRect(); + // cy.get('[data-cy=editorjs]') + // .get('div.ce-block') + // .eq(2) + // .trigger("dragover", { clientX: bbox.x, clientY: (bbox.y + (bbox.width / 2 - 20)) }) + // .trigger("drop", { dataTransfer }); + // }) + // // .invoke('attr', 'class') // returns "class1 class2 class3" + // // .then(classList => { + // // console.log(classList); + // // }); + + + // // cy.get('.ce-toolbar__settings-btn') + // // .trigger("dragend", { dataTransfer }); + // }); });