From 87a584eafed5696821d55e964b50674b18639791 Mon Sep 17 00:00:00 2001 From: moneymanolis Date: Fri, 20 Jan 2023 21:00:49 +0100 Subject: [PATCH] cypress tests: until amounts and balances --- .../spec_elm_multi_segwit_wallet.js | 0 .../spec_elm_single_segwit_wallet.js | 0 .../spec_multiuser_sessions.js | 0 .../spec_setup_tor.js | 0 .../spec_setup_wizard.js | 0 cypress/integration/spec_balances_amounts.js | 94 +++++-------------- .../integration/spec_empty_specter_home.js | 2 +- cypress/integration/spec_labeling.js | 2 +- cypress/integration/spec_plugins.js | 2 +- cypress/integration/spec_qr_signing.js | 58 +++++++----- cypress/support/commands.js | 49 +++++----- .../templates/includes/address-data.html | 2 +- .../components/sidebar_device_list_item.jinja | 2 +- .../components/sidebar_wallet_list_item.jinja | 2 +- .../templates/includes/sidebar/sidebar.jinja | 2 +- .../wallet/new_wallet/new_wallet_type.jinja | 4 +- 16 files changed, 92 insertions(+), 127 deletions(-) rename cypress/{integration => archive}/spec_elm_multi_segwit_wallet.js (100%) rename cypress/{integration => archive}/spec_elm_single_segwit_wallet.js (100%) rename cypress/{integration => archive}/spec_multiuser_sessions.js (100%) rename cypress/{integration => archive}/spec_setup_tor.js (100%) rename cypress/{integration => archive}/spec_setup_wizard.js (100%) diff --git a/cypress/integration/spec_elm_multi_segwit_wallet.js b/cypress/archive/spec_elm_multi_segwit_wallet.js similarity index 100% rename from cypress/integration/spec_elm_multi_segwit_wallet.js rename to cypress/archive/spec_elm_multi_segwit_wallet.js diff --git a/cypress/integration/spec_elm_single_segwit_wallet.js b/cypress/archive/spec_elm_single_segwit_wallet.js similarity index 100% rename from cypress/integration/spec_elm_single_segwit_wallet.js rename to cypress/archive/spec_elm_single_segwit_wallet.js diff --git a/cypress/integration/spec_multiuser_sessions.js b/cypress/archive/spec_multiuser_sessions.js similarity index 100% rename from cypress/integration/spec_multiuser_sessions.js rename to cypress/archive/spec_multiuser_sessions.js diff --git a/cypress/integration/spec_setup_tor.js b/cypress/archive/spec_setup_tor.js similarity index 100% rename from cypress/integration/spec_setup_tor.js rename to cypress/archive/spec_setup_tor.js diff --git a/cypress/integration/spec_setup_wizard.js b/cypress/archive/spec_setup_wizard.js similarity index 100% rename from cypress/integration/spec_setup_wizard.js rename to cypress/archive/spec_setup_wizard.js diff --git a/cypress/integration/spec_balances_amounts.js b/cypress/integration/spec_balances_amounts.js index 098001b52..3f62bd4eb 100644 --- a/cypress/integration/spec_balances_amounts.js +++ b/cypress/integration/spec_balances_amounts.js @@ -11,54 +11,14 @@ describe('Test the rendering of balances and amounts', () => { Cypress.Cookies.preserveOnce('session') }) - it('Total balance of 20 BTC', () => { - /* This is how the DOM looks like - - 20.0 - 0 - - 0 - 0 - 0 - - - 0 - 0 - 0 - - - */ + it('Total balance', () => { cy.selectWallet('Ghost wallet') - cy.get('#fullbalance_amount').should('have.text', '20.00000000') // should('have.text') returns ALL textContents (descendants and unvisible text) - cy.get('#fullbalance_amount').find('span').first().should('have.text', '0').and('not.be.visible') - cy.get('#fullbalance_amount').find('.thousand-digits-in-btc-amount').children().each((element) => { - cy.wrap(element).should('have.text', '0') - cy.wrap(element).should('not.be.visible') - }); - cy.get('#fullbalance_amount').find('.last-digits-in-btc-amount').children().each((element) => { - cy.wrap(element).should('have.text', '0') - cy.wrap(element).should('not.be.visible') - }); + cy.get('#fullbalance_amount').then(($amount) => { + expect(parseFloat($amount.text())).to.be.gt(20) + }) }) - it('Unconfirmed balance of 0.05 BTC', () => { - /* This is how the DOM looks like - - 0.05 - - 0 - 0 - 0 - - - 0 - 0 - 0 - - - */ - // We get 5 mio. sats from a funding wallet - // TODO: If this funding wallet is used more, move it to a seperate spec file + it('Unconfirmed balance', () => { cy.addHotDevice('Satoshis hot keys','bitcoin') cy.addWallet('Funding wallet', 'segwit', 'funded', 'btc', 'singlesig', 'Satoshis hot keys') cy.selectWallet('Funding wallet') @@ -75,42 +35,38 @@ describe('Test the rendering of balances and amounts', () => { cy.get('#satoshis_hot_keys_hot_sign_btn').click() cy.get('#hot_enter_passphrase__submit').click() cy.get('#broadcast_local_btn').click() + // To close the overlay (no cancel button here) + cy.get('#page_overlay_popup').click() + cy.reload() cy.selectWallet('Ghost wallet') - // Once again because only once doesn't work for some stupid unknown reason - cy.selectWallet('Ghost wallet') - cy.get('#unconfirmed_amount').should('have.text', '0.05000000') + cy.get('#unconfirmed_amount').then(($amount) => { + expect(parseFloat($amount.text())).to.be.gt(0).and.to.be.lt(1); + }) cy.get('#unconfirmed_amount').find('.thousand-digits-in-btc-amount').children().each((element) => { cy.wrap(element).should('have.text', '0') - cy.wrap(element).should('not.be.visible') }); cy.get('#unconfirmed_amount').find('.last-digits-in-btc-amount').children().each((element) => { cy.wrap(element).should('have.text', '0') - cy.wrap(element).should('not.be.visible') }); }) it('Total balance with all digits', () => { - /* This is how the DOM looks like - - 19.94 - 999 - 291 - - */ - // Let's use the funding wallet - // Works as long as the fee was 709 and the original balance of the funding wallet was 20 BTC cy.selectWallet('Funding wallet') - cy.get('#fullbalance_amount').should('have.text', '19.94999291') - cy.get('#fullbalance_amount').find('.thousand-digits-in-btc-amount').should('have.text', '999') - cy.get('#fullbalance_amount').find('.thousand-digits-in-btc-amount').should('have.css', 'color','rgb(145, 145, 145)') - cy.get('#fullbalance_amount').find('.last-digits-in-btc-amount').should('have.text', '291') - cy.get('#fullbalance_amount').find('.last-digits-in-btc-amount').should('have.css', 'color','rgb(121, 121, 121)') + cy.get('#fullbalance_amount').then(($amount) => { + expect(parseFloat($amount.text())).to.be.gt(19).and.to.be.lt(20); + }) + cy.get('#fullbalance_amount').find('.thousand-digits-in-btc-amount').should(($amount) => { + expect($amount.text()).to.match(/^\d{3}$/) + }).and(($amount) => { + expect(parseFloat($amount.text())).to.be.gt(0); + }); + cy.get('#fullbalance_amount').find('.last-digits-in-btc-amount').should(($amount) => { + expect($amount.text()).to.match(/^\d{3}$/) + }).and(($amount) => { + expect(parseFloat($amount.text())).to.be.gt(0); + }); cy.get('#fullbalance_amount').children().each((element) => { cy.wrap(element).should('be.visible') - cy.log(element) - }); + }) }) - - // TODO: Test (new) amount display once implemented, e.g. in sending dialogue, could probably be done in one of the tests above. - }) diff --git a/cypress/integration/spec_empty_specter_home.js b/cypress/integration/spec_empty_specter_home.js index 25dfe399e..f85dcd542 100644 --- a/cypress/integration/spec_empty_specter_home.js +++ b/cypress/integration/spec_empty_specter_home.js @@ -8,7 +8,7 @@ describe('Completely empty specter-home', () => { it('Click around on the welcome page', () => { cy.contains('Welcome to Specter') - cy.contains('Settings').click() + cy.get('[data-cy="settings-btn"]').click() cy.contains('Backup and Restore') cy.contains('Authentication').click() cy.contains('USB Devices').click() diff --git a/cypress/integration/spec_labeling.js b/cypress/integration/spec_labeling.js index 4f99859ce..250d7dca0 100644 --- a/cypress/integration/spec_labeling.js +++ b/cypress/integration/spec_labeling.js @@ -13,7 +13,7 @@ describe('Test the labeling of addresses and transactions', () => { it('Labeling an address on the address overview', () => { // Using the ghost wallet - cy.get('.side').contains('Ghost wallet').click() + cy.selectWallet('Ghost wallet') cy.get('main').contains('Addresses').click() // Checking the correct titles since those are the only orientation for the user right now cy.get('[data-cy="edit-label-btn"]').last().should('have.attr', 'title', 'Edit label') // The last element in the array is the first one on the screen ... diff --git a/cypress/integration/spec_plugins.js b/cypress/integration/spec_plugins.js index ef0dd4eb3..c13a700ec 100644 --- a/cypress/integration/spec_plugins.js +++ b/cypress/integration/spec_plugins.js @@ -35,7 +35,7 @@ describe('Test plugins', () => { // This flow only works if we don't keep the session alive! So, no Cypress.Cookies.preserveOnce('session') in beforeEach(). cy.get('#password').type("mySecretPassword") cy.get('#login-btn').click() - cy.get('[href="/settings/"] > .svg-white').click() + cy.get('[data-cy="settings-btn"]').click() cy.get('[href="/settings/auth"]').click() cy.get('select').select("none") cy.get('#submit-btn').click() diff --git a/cypress/integration/spec_qr_signing.js b/cypress/integration/spec_qr_signing.js index ebb126c08..f0e145282 100644 --- a/cypress/integration/spec_qr_signing.js +++ b/cypress/integration/spec_qr_signing.js @@ -2,17 +2,17 @@ describe('Test QR code signing flow', () => { before(() => { Cypress.config('includeShadowDom', true) - cy.visit('/') }) // Keeps the session cookie alive, Cypress by default clears all cookies before each test beforeEach(() => { + cy.visit('/') cy.viewport(1200,660) Cypress.Cookies.preserveOnce('session') }) it('Message signing with Specter DIY', () => { - cy.get('.side').contains('Ghost wallet').click() + cy.selectWallet('Ghost wallet') cy.get('main').contains('Addresses').click() // Click on the first address cy.contains('td', '#0').siblings().contains('bcrt').click() @@ -22,7 +22,8 @@ describe('Test QR code signing flow', () => { cy.get('#message').type('The DIY is the best signing device.') cy.get('#diy_ghost_qr_sign_msg_btn').click() cy.get('#diy_ghost_sign_msg_qr > h2').contains('Scan this QR code') - cy.get('#page_overlay_popup_cancel_button').click() + // To close the overlay (no cancel button here) + cy.get('#page_overlay_popup').click() }) it('No QR message signing button for a Trezor', () => { @@ -33,36 +34,41 @@ describe('Test QR code signing flow', () => { // Only USB signing available for a Trezor device cy.contains('Sign message via USB').should('be.visible') cy.contains('Sign message via QR code').should('not.exist') - // Change device type back to DIY + cy.get('#page_overlay_popup').click() cy.changeDeviceType("DIY ghost", "specter") }) - + it('No message signing with Electrum', () => { - Cypress.on('uncaught:exception', (err, runnable) => { - return false + cy.get('body').then(($body) => { + if (!$body.text().includes("Electrum Device")) { + cy.get('#toggle_devices_list').click() + cy.get('#btn_new_device').click() + cy.get('#electrum_device_card').click() + cy.get('#device_name').type("Electrum Device") + cy.get('#master_pub_key').type("vpub5VGXXixD2pHLFtcKtCF57e8mx2JW6fie8VydXijC8sRKAL4RshgjEmzbmV915NeVB9pd23DVYem6zWM7HXFLNwaffNVHowdD9SJWwESyQhp") + cy.get('.small-card > .btn').click() + cy.contains('Close').click() + } }) - // returning false here prevents Cypress from - // failing the test due to this thus far unidentified error: - // "The following error originated from your application code, not from Cypress. - // > missing ) after argument list" - - cy.deleteWallet("Wallet that can't sign messages") - cy.deleteDevice("Electron's Electrum Device") - cy.get('#toggle_devices_list').click() - cy.get('#btn_new_device').click() - cy.get('#electrum_device_card').click() - cy.get('#device_name').type("Electron's Electrum Device") - cy.get('#master_pub_key').type("vpub5VGXXixD2pHLFtcKtCF57e8mx2JW6fie8VydXijC8sRKAL4RshgjEmzbmV915NeVB9pd23DVYem6zWM7HXFLNwaffNVHowdD9SJWwESyQhp") - cy.get('.small-card > .btn').click() - cy.get('button').contains("Create single key wallet").click() - cy.get('#wallet_name').type("Wallet that can't sign messages") - cy.get('#keysform').contains("Create wallet").click() - cy.get('#btn_continue').click() + cy.get('body').then(($body) => { + if (!$body.text().includes("Wallet that cannot sign messages")) { + cy.get('#btn_new_wallet').click() + cy.get('[data-cy="singlesig-wallet-btn"]').click() + cy.get('#electrum_device').click() + cy.get('#wallet_name').type("Wallet that cannot sign messages") + cy.get('#keysform').contains("Create wallet").click() + cy.get('#btn_continue').click() + } + }) + cy.selectWallet("Wallet that cannot sign messages") cy.get('main').contains('Addresses').click() cy.contains('td', '#0').siblings().contains('bcrt').click() cy.get('#msg-signing-btn').should('not.exist') + // Close the address data screen + cy.get('[data-cy="address-data-screen-close-btn"]').click() + // Clean up - cy.deleteWallet("Wallet that can't sign messages") - cy.deleteDevice("Electron's Electrum Device") + cy.deleteWallet("Wallet that cannot sign messages") + cy.deleteDevice("Electrum Device") }) }) \ No newline at end of file diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 122366ceb..964dc59cb 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -62,24 +62,18 @@ Cypress.Commands.add("addHotDevice", (name, node_type) => { // node_type is either elements or bitcoin cy.get('body').then(($body) => { if ($body.text().includes(name)) { - cy.deleteDevice(name) - // We might get an error here, if the device is used in a wallet - // We assume therefore that this is ok (see below) + return } cy.get('#side-content').click() if (!cy.get('#btn_new_device').isVisible) { cy.get('#toggle_devices_list').click() } cy.get('#btn_new_device').click( {force: true} ) - cy.contains('Select Your Device Type') cy.get(`#${node_type}core_device_card`).click() cy.get('#submit-mnemonic').click() cy.get('#device_name').type(name) cy.get('#submit-keys').click() - cy.get('#toggle_devices_list').click() - // It's a bit hackish as if the device already exists, we'll get an error - // but continue flaslessly nevertheless - cy.get('#devices_list > .item > div', { timeout: 8000 }).contains(name) + cy.get('[data-cy="new-device-added-screen-close-btn"]').click() }) }) @@ -97,11 +91,16 @@ Cypress.Commands.add("deleteDevice", (name) => { }) }) -Cypress.Commands.add("changeDeviceType", (nameDevice, newType) => { +Cypress.Commands.add("changeDeviceType", (deviceName, newType) => { cy.get('body').then(($body) => { - if ($body.text().includes(nameDevice)) { - cy.get('#toggle_devices_list').click() - cy.contains(nameDevice).click() + if ($body.text().includes(deviceName)) { + cy.get('#toggle_devices_list').then(($devicesList) => { + if ($devicesList.text() == 'Devices ▸') { + cy.get('#toggle_devices_list').click() + } + }) + let refDeviceName = deviceName.toLowerCase().replace(/ /g,"_"); + cy.get(`[data-cy='device-sidebar-btn-${refDeviceName}']`).click() cy.get('#device_type').select(newType) cy.get('#settype').click() } @@ -154,8 +153,6 @@ Cypress.Commands.add("addWallet", (walletName, walletType, funded, nodeType, key } cy.get('body').then(($body) => { if ($body.text().includes(walletName)) { - cy.get('#toggle_wallets_list').click() - cy.contains(walletName).click() return } cy.get('#side-content').click() @@ -198,23 +195,29 @@ Cypress.Commands.add("addWallet", (walletName, walletType, funded, nodeType, key }) }) -Cypress.Commands.add("deleteWallet", (name) => { +Cypress.Commands.add("deleteWallet", (walletName) => { cy.get('body').then(($body) => { - if ($body.text().includes(name)) { - cy.contains(name).click() + if ($body.text().includes(walletName)) { + cy.get(`[data-cy='wallet-sidebar-btn-${walletName}']`).click() cy.get('#btn_settings').click( {force: true} ) cy.get('#advanced_settings_tab_btn').click() cy.get('#delete_wallet').click() - // That does not seem to delete the wallet-file in elements, though - // So let's do that as well - cy.task("delete:elements-hotwallet") } }) }) -Cypress.Commands.add("selectWallet", (name) => { - cy.get('body').then(() => { - cy.contains(name).click( {force: true} ) +Cypress.Commands.add("selectWallet", (walletName) => { + cy.get('body').then(($body) => { + if ($body.text().includes(walletName)) { + cy.get('#toggle_wallets_list').then(($walletsList) => { + // Only toggle the wallets list if it is not already toggled + if ($walletsList.text() == 'Wallets ▸') { + cy.get('#toggle_wallets_list').click() + } + cy.get(`[data-cy='wallet-sidebar-btn-${walletName}']`).click() + }) + + } }) }) diff --git a/src/cryptoadvance/specter/templates/includes/address-data.html b/src/cryptoadvance/specter/templates/includes/address-data.html index 7a2da291b..3819d05e3 100644 --- a/src/cryptoadvance/specter/templates/includes/address-data.html +++ b/src/cryptoadvance/specter/templates/includes/address-data.html @@ -44,7 +44,7 @@

{{ _("Address Data") }}

-

Close

+

Close

diff --git a/src/cryptoadvance/specter/templates/includes/sidebar/components/sidebar_device_list_item.jinja b/src/cryptoadvance/specter/templates/includes/sidebar/components/sidebar_device_list_item.jinja index 90410c58d..968378b76 100644 --- a/src/cryptoadvance/specter/templates/includes/sidebar/components/sidebar_device_list_item.jinja +++ b/src/cryptoadvance/specter/templates/includes/sidebar/components/sidebar_device_list_item.jinja @@ -5,7 +5,7 @@ - device_alias: Active device alias. #} {% macro sidebar_device_list_item(device, device_alias) -%} - +
diff --git a/src/cryptoadvance/specter/templates/includes/sidebar/components/sidebar_wallet_list_item.jinja b/src/cryptoadvance/specter/templates/includes/sidebar/components/sidebar_wallet_list_item.jinja index 5c3b9bd7a..a0ebe8f1c 100644 --- a/src/cryptoadvance/specter/templates/includes/sidebar/components/sidebar_wallet_list_item.jinja +++ b/src/cryptoadvance/specter/templates/includes/sidebar/components/sidebar_wallet_list_item.jinja @@ -7,7 +7,7 @@ - loading: Boolean indicating if the wallet is loaded in Specter already or not. #} {% macro sidebar_wallet_list_item(wallet, wallet_alias, chain, loading=false) -%} -
+