From 6b993ea93a5df72faf41185655417dc15b65f34e Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Tue, 15 Mar 2022 10:45:15 +0100 Subject: [PATCH] Use file upload instead of typing large text (#2228) --- .../integration/partial_import_test.spec.ts | 4 ++-- cypress/support/commands.ts | 1 + .../realm_settings/PartialImportModal.ts | 15 +++----------- cypress/tsconfig.json | 2 +- package-lock.json | 20 +++++++++++++++++++ package.json | 1 + 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/cypress/integration/partial_import_test.spec.ts b/cypress/integration/partial_import_test.spec.ts index 27efd8d70e..723e73bee9 100644 --- a/cypress/integration/partial_import_test.spec.ts +++ b/cypress/integration/partial_import_test.spec.ts @@ -39,7 +39,7 @@ describe("Partial import test", () => { modal.importButton().should("not.exist"); }); - it.skip("Import button only enabled if JSON has something to import", () => { + it("Import button only enabled if JSON has something to import", () => { modal.open(); cy.get(".pf-c-code-editor__code textarea").type("{}"); modal.importButton().should("be.disabled"); @@ -85,7 +85,7 @@ describe("Partial import test", () => { modal.closeButton().click(); }); - it.skip("Displays user options after realmless import and does the import", () => { + it("Displays user options after realmless import and does the import", () => { modal.open(); modal.typeResourceFile("client-only.json"); diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 3816c58aa2..366116474e 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -25,3 +25,4 @@ // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) import "@testing-library/cypress/add-commands"; +import "cypress-file-upload"; diff --git a/cypress/support/pages/admin_console/configure/realm_settings/PartialImportModal.ts b/cypress/support/pages/admin_console/configure/realm_settings/PartialImportModal.ts index 6e75c35062..8e859bd9a8 100644 --- a/cypress/support/pages/admin_console/configure/realm_settings/PartialImportModal.ts +++ b/cypress/support/pages/admin_console/configure/realm_settings/PartialImportModal.ts @@ -7,18 +7,9 @@ export default class GroupModal { } typeResourceFile = (filename: string) => { - cy.readFile("cypress/fixtures/partial-import-test-data/" + filename).then( - (myJSON) => { - const text = JSON.stringify(myJSON); - - cy.get(".pf-c-code-editor__code textarea") - .type(text, { - delay: 0, - parseSpecialCharSequences: false, - }) - .type("{shift}{end}") - .type("{del}"); - } + cy.get("#partial-import-file-filename").attachFile( + "./partial-import-test-data/" + filename, + { subjectType: "drag-n-drop" } ); }; diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json index e0f13d47da..9a3c5c8e3f 100644 --- a/cypress/tsconfig.json +++ b/cypress/tsconfig.json @@ -2,7 +2,7 @@ "extends": "../tsconfig.json", "include": ["**/*"], "compilerOptions": { - "types": ["node", "cypress", "@testing-library/cypress"], + "types": ["node", "cypress", "@testing-library/cypress", "cypress-file-upload"], "module": "ES2015", "target": "ES2015", } diff --git a/package-lock.json b/package-lock.json index e7bee28d6d..c36ee2da10 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,6 +53,7 @@ "@typescript-eslint/parser": "^5.14.0", "cli-progress": "^3.10.0", "cypress": "^9.5.1", + "cypress-file-upload": "^5.0.8", "decompress": "^4.2.1", "eslint": "^8.11.0", "eslint-config-prettier": "^8.5.0", @@ -8145,6 +8146,18 @@ "node": ">=12.0.0" } }, + "node_modules/cypress-file-upload": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/cypress-file-upload/-/cypress-file-upload-5.0.8.tgz", + "integrity": "sha512-+8VzNabRk3zG6x8f8BWArF/xA/W0VK4IZNx3MV0jFWrJS/qKn8eHfa5nU73P9fOQAgwHFJx7zjg4lwOnljMO8g==", + "dev": true, + "engines": { + "node": ">=8.2.1" + }, + "peerDependencies": { + "cypress": ">3.0.0" + } + }, "node_modules/cypress/node_modules/@types/node": { "version": "14.17.21", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.21.tgz", @@ -28328,6 +28341,13 @@ } } }, + "cypress-file-upload": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/cypress-file-upload/-/cypress-file-upload-5.0.8.tgz", + "integrity": "sha512-+8VzNabRk3zG6x8f8BWArF/xA/W0VK4IZNx3MV0jFWrJS/qKn8eHfa5nU73P9fOQAgwHFJx7zjg4lwOnljMO8g==", + "dev": true, + "requires": {} + }, "d3-color": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/d3-color/-/d3-color-3.0.1.tgz", diff --git a/package.json b/package.json index 4f700570ea..e1b51c9e0d 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "@typescript-eslint/parser": "^5.14.0", "cli-progress": "^3.10.0", "cypress": "^9.5.1", + "cypress-file-upload": "^5.0.8", "decompress": "^4.2.1", "eslint": "^8.11.0", "eslint-config-prettier": "^8.5.0",