diff --git a/cypress.json b/cypress.json index 0f0f794..5ded01a 100644 --- a/cypress.json +++ b/cypress.json @@ -1,3 +1,3 @@ { - "video": false + "video": true } diff --git a/cypress/integration/import-passphrase-page.ts b/cypress/integration/import-passphrase-page.ts new file mode 100644 index 0000000..5cc8248 --- /dev/null +++ b/cypress/integration/import-passphrase-page.ts @@ -0,0 +1,78 @@ +import { cleanIndexedDB } from "../plugins/helpers/clean-indexed-db"; +import { elementNotExists } from "../plugins/helpers/element-not-exists"; + +describe("ImportPassphrasePage", () => { + beforeEach(() => { + cleanIndexedDB(); + + cy.visit("http://localhost:8100"); + + goToPage(); + }); + + it("should not show the import button initially", () => { + elementNotExists("page-wallet-import-passphrase", "[data-cy=import-button]"); + }); + + it("should show a warning if the passwords do not match", () => { + cy.get("[data-cy=password-input] input").type("pass123"); + cy.get("[data-cy=password-confirm-input] input").type("321ssap"); + + cy.get("[data-cy=password-error-box]"); + }); + + it("should show a warning if the passphrase is invalid", () => { + cy.get("[data-cy=passphrase-input] textarea").type("bla bla bla"); + + cy.get("[data-cy=passphrase-error-box]"); + }); + + it("should show the import button once all fields have been filled correctly", () => { + cy.get("[data-cy=passphrase-input] textarea").type("one two three"); + + cy.get("[data-cy=password-input] input").type("pass123"); + cy.get("[data-cy=password-confirm-input] input").type("pass123"); + + cy.get("[data-cy=wallet-name-input] input").type("Wallet Name"); + + cy.get("[data-cy=import-button]").click(); + + cy.get("page-prepare-wallet"); + }); + + it("should toggle the advanced options correctly", () => { + elementNotExists("page-wallet-import-passphrase", "[data-cy=wallet-index-input] input").then( + () => { + cy.get("[data-cy=toggle-advanced-button").click(); + + cy.get("[data-cy=wallet-index-input] input"); + + cy.get("[data-cy=toggle-advanced-button").click(); + + elementNotExists("page-wallet-import-passphrase", "[data-cy=wallet-index-input] input"); + } + ); + }); + + it("should show a warning when entering incorrect address index input", () => { + cy.get("[data-cy=toggle-advanced-button").click(); + + cy.get("[data-cy=wallet-index-input] input").clear(); + + cy.get("[data-cy=wallet-index-input] input").type("wrong input"); + + cy.get("[data-cy=wallet-index-error-box]"); + + cy.get("[data-cy=wallet-index-input] input").clear(); + + cy.get("[data-cy=wallet-index-input] input").type("100"); + + elementNotExists("page-wallet-import-passphrase", "[data-cy=wallet-index-error-box]"); + }); + + function goToPage() { + cy.get("[data-cy=restore-backup-button]").click(); + + cy.get("[data-cy=import-passphrase-button]").click(); + } +}); \ No newline at end of file diff --git a/cypress/integration/import-private-key-page.ts b/cypress/integration/import-private-key-page.ts index 0f3816a..9742940 100644 --- a/cypress/integration/import-private-key-page.ts +++ b/cypress/integration/import-private-key-page.ts @@ -5,11 +5,11 @@ describe("ImportPrivateKeyPage", () => { cleanIndexedDB(); cy.visit("http://localhost:8100"); - }); - it("should not show the import button initially", () => { goToPage(); + }); + it("should not show the import button initially", () => { cy.get("page-wallet-import-privatekey").then( (page) => { expect(page.find("[data-cy=import-privatekey-button]")).to.have.length(0); @@ -18,8 +18,6 @@ describe("ImportPrivateKeyPage", () => { }); it("should show a password warning if the passwords do not match", () => { - goToPage(); - cy.get("[data-cy=password-input] input").type("pass123"); cy.get("[data-cy=password-confirm-input] input").type("321ssap"); @@ -27,8 +25,6 @@ describe("ImportPrivateKeyPage", () => { }); it("should show the import button once all fields have been filled correctly", () => { - goToPage(); - cy.get("[data-cy=private-key-input] textarea").type("PrivateKey"); cy.get("[data-cy=wallet-name-input] input").type("Wallet Name"); cy.get("[data-cy=password-input] input").type("pass123"); @@ -41,8 +37,6 @@ describe("ImportPrivateKeyPage", () => { }); it("should show a password explanation dialog", () => { - goToPage(); - // Open modal cy.get("[data-cy=password-explanation]").click(); @@ -53,7 +47,7 @@ describe("ImportPrivateKeyPage", () => { cy.get("[data-cy=password-explain-ok-button]").click(); // Wait to allow the modal animation to end - cy.wait(2000); + cy.wait(10000); cy.get("body").then( (body) => { diff --git a/cypress/plugins/helpers/clean-indexed-db.ts b/cypress/plugins/helpers/clean-indexed-db.ts index 4e7ced2..069f966 100644 --- a/cypress/plugins/helpers/clean-indexed-db.ts +++ b/cypress/plugins/helpers/clean-indexed-db.ts @@ -1,3 +1,5 @@ +/// + export function cleanIndexedDB() { - indexedDB.deleteDatabase("_ionicstorage"); + indexedDB.deleteDatabase("smilo-wallet"); } \ No newline at end of file diff --git a/cypress/plugins/helpers/element-not-exists.ts b/cypress/plugins/helpers/element-not-exists.ts new file mode 100644 index 0000000..254feaa --- /dev/null +++ b/cypress/plugins/helpers/element-not-exists.ts @@ -0,0 +1,9 @@ +/// + +export function elementNotExists(baseSelector: string, selector: string): Cypress.Chainable { + return cy.get(baseSelector).then( + (baseElement) => { + expect(baseElement.find(selector)).to.have.length(0); + } + ) +} \ No newline at end of file diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json index c36bdf8..06e5c75 100644 --- a/cypress/tsconfig.json +++ b/cypress/tsconfig.json @@ -4,6 +4,10 @@ "module": "commonjs", "skipLibCheck": true, "strict": true, + "lib": [ + "es2015", + "dom" + ], "types": [ "node", "cypress" diff --git a/package.json b/package.json index d7ea497..79774f7 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "test-ci": "karma start ./test-config/karma.conf.js --coverage --single-run", "e2e": "cypress open", "e2e-ci": "nohup ionic serve --no-open --no-livereload --no-interactive &> /dev/null & (wait-on http://localhost:8100 && cypress run && pkill -f ionic)", + "e2e-electron-headed": "cypress run --headed", "ionic:build": "ionic-app-scripts build", "ionic:serve": "ionic-app-scripts serve", "release:android": "./scripts/release-android.sh", diff --git a/src/pages/wallet-import-passphrase/wallet-import-passphrase.html b/src/pages/wallet-import-passphrase/wallet-import-passphrase.html index a8400a3..d5294ea 100644 --- a/src/pages/wallet-import-passphrase/wallet-import-passphrase.html +++ b/src/pages/wallet-import-passphrase/wallet-import-passphrase.html @@ -15,8 +15,8 @@ formControlName="passphrase" [(ngModel)]="passphrase" (ionChange)="onPassphraseChanged()" - class="passphrase-input" - [placeholder]="'import_passphrase.passphrase_hint' | translate"> + [placeholder]="'import_passphrase.passphrase_hint' | translate" + [attr.data-cy]="'passphrase-input'"> @@ -25,9 +25,9 @@ + (ionChange)="onPasswordChanged()" + [attr.data-cy]="'password-input'"> @@ -36,18 +36,18 @@ + (ionChange)="onPasswordChanged()" + [attr.data-cy]="'password-confirm-input'"> {{ 'import_passphrase.wallet_name' | translate }} - +
@@ -55,36 +55,38 @@ {{ 'import_passphrase.wallet_index' | translate }} - + [(ngModel)]="walletIndex" + [attr.data-cy]="'wallet-index-input'">
-
+
{{ passwordStatus.message }}
-
+
+ class="error-box"> {{ passphraseStatus.errorMessage }}
-
- +
+ {{ 'import_passphrase.errors.wallet_index' | translate }}
- +
-
@@ -92,7 +94,7 @@
-