diff --git a/cypress.json b/cypress.json index e2c733cc9..31c0282a6 100644 --- a/cypress.json +++ b/cypress.json @@ -22,5 +22,6 @@ "reporterOptions": { "mochaFile": "cypresstest-output.xml", "toConsole": true - } + }, + "experimentalSessionAndOrigin": true } diff --git a/cypress/integration/spec_balances_amounts.js b/cypress/integration/spec_balances_amounts.js index 3f74e80cb..860571ed8 100644 --- a/cypress/integration/spec_balances_amounts.js +++ b/cypress/integration/spec_balances_amounts.js @@ -1,14 +1,6 @@ -// describe('Test the rendering of balances and amounts', () => { before(() => { Cypress.config('includeShadowDom', true) - cy.visit('/') - }) - - // Keeps the session cookie alive, Cypress by default clears all cookies before each test - beforeEach(() => { - cy.viewport(1200,660) - Cypress.Cookies.preserveOnce('session') }) it('Total balance', () => { diff --git a/cypress/integration/spec_connections.js b/cypress/integration/spec_connections.js index 173506758..531cc23e2 100644 --- a/cypress/integration/spec_connections.js +++ b/cypress/integration/spec_connections.js @@ -3,15 +3,6 @@ describe('Connecting nodes', () => { Cypress.config('includeShadowDom', true) }) - beforeEach(() => { - cy.visit('/') - cy.viewport(1200,660) - }) - - // Important! - // If you have a bitcoin.conf at the default data dir location this can create awkwardness. - // Either move your bitcoin.conf or use the exact RPC credentials that Cypress does - it('Connect with Bitcoin Core node', () => { // Starting from the welcome page cy.get('[data-cy="core-connection-btn"]').click() @@ -53,7 +44,6 @@ describe('Connecting nodes', () => { }) // TODO: For testing the deletion we could delete the Liquid connection here if we don't run the Liquid tests - it('Select Bitcoin Core connection', () => { cy.get('#node-switch-icon').click() cy.contains('Bitcoin Core').click() diff --git a/cypress/integration/spec_devices.js b/cypress/integration/spec_devices.js index 08eb62cff..5bc0430cf 100644 --- a/cypress/integration/spec_devices.js +++ b/cypress/integration/spec_devices.js @@ -3,13 +3,6 @@ describe('Test adding different devices', () => { Cypress.config('includeShadowDom', true) }) - // Keeps the session cookie alive, Cypress by default clears all cookies before each test - beforeEach(() => { - cy.viewport(1200,660) - cy.visit('/') - Cypress.Cookies.preserveOnce('session') - }) - it('Filter devices', () => { cy.get('#toggle_devices_list').click() cy.get('#btn_new_device').click() diff --git a/cypress/integration/spec_empty_specter_home.js b/cypress/integration/spec_empty_specter_home.js index f85dcd542..43c27ccdc 100644 --- a/cypress/integration/spec_empty_specter_home.js +++ b/cypress/integration/spec_empty_specter_home.js @@ -2,7 +2,6 @@ describe('Completely empty specter-home', () => { before(() => { cy.task("clear:specter-home") - cy.viewport(1200,660) cy.visit('/welcome/about') }) diff --git a/cypress/integration/spec_fees.js b/cypress/integration/spec_fees.js index d3eaa43b6..2a09baecd 100644 --- a/cypress/integration/spec_fees.js +++ b/cypress/integration/spec_fees.js @@ -4,14 +4,7 @@ describe('Test the fee UI', () => { before(() => { Cypress.config('includeShadowDom', true) - cy.visit('/') - }) - - // Keeps the session cookie alive, Cypress by default clears all cookies before each test - beforeEach(() => { - cy.viewport(1200,660) - Cypress.Cookies.preserveOnce('session') - }) + }) it('Using dynamic mode with normal fees', () => { // Fees: {"fastestFee": 9, "halfHourFee": 5, "hourFee": 3, "minimumFee": 1} @@ -151,7 +144,6 @@ describe('Test the fee UI', () => { cy.get('#fee_manual').find('#fee_rate').clear( { force: true }) cy.get('#fee_manual').find('#fee_rate').type(5, { force: true }) cy.get('#fee_manual').find('#fee_rate').should('have.value', '5') - cy.get('#fee_manual').find('.note').contains('1 sat/vbyte is the minimal fee rate.') }) }) \ No newline at end of file diff --git a/cypress/integration/spec_ghost_machine.js b/cypress/integration/spec_ghost_machine.js index 3aba89def..bcf00a071 100644 --- a/cypress/integration/spec_ghost_machine.js +++ b/cypress/integration/spec_ghost_machine.js @@ -1,7 +1,5 @@ describe('Ghost machine', () => { it('Create a DIY device with ghost machine keys and a wallet', () => { - cy.viewport(1200,660) - cy.visit('/') cy.addDevice('DIY ghost', 'Specter-DIY', 'ghost_machine') // addWallet assumes that we have a connection, so let's check for that and establish one if we don't have one cy.get('body') diff --git a/cypress/integration/spec_labeling.js b/cypress/integration/spec_labeling.js index 250d7dca0..083204601 100644 --- a/cypress/integration/spec_labeling.js +++ b/cypress/integration/spec_labeling.js @@ -7,7 +7,7 @@ describe('Test the labeling of addresses and transactions', () => { // Keeps the session cookie alive, Cypress by default clears all cookies before each test beforeEach(() => { - cy.viewport(1200,660) + cy.viewport('macbook-13') Cypress.Cookies.preserveOnce('session') }) diff --git a/cypress/integration/spec_plugins.js b/cypress/integration/spec_plugins.js index c13a700ec..95ce11ee1 100644 --- a/cypress/integration/spec_plugins.js +++ b/cypress/integration/spec_plugins.js @@ -3,12 +3,6 @@ describe('Test plugins', () => { Cypress.config('includeShadowDom', true) }) - // Keeps the session cookie alive, Cypress by default clears all cookies before each test - beforeEach(() => { - cy.viewport(1200,660) - cy.visit('/') - }) - it('Associate an address with a service', () => { // choose address cy.selectWallet("Ghost wallet") diff --git a/cypress/integration/spec_qr_signing.js b/cypress/integration/spec_qr_signing.js index f0e145282..d84d37b5b 100644 --- a/cypress/integration/spec_qr_signing.js +++ b/cypress/integration/spec_qr_signing.js @@ -4,13 +4,6 @@ describe('Test QR code signing flow', () => { Cypress.config('includeShadowDom', true) }) - // 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.selectWallet('Ghost wallet') cy.get('main').contains('Addresses').click() diff --git a/cypress/integration/spec_rescan.js b/cypress/integration/spec_rescan.js index 3d6e24522..af491b467 100644 --- a/cypress/integration/spec_rescan.js +++ b/cypress/integration/spec_rescan.js @@ -3,13 +3,6 @@ describe('Test the UI related to a blockchain rescan', () => { Cypress.config('includeShadowDom', true) }) - // 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('Go to the rescan section from a fresh wallet', () => { // Create a completely fresh wallet without any funds cy.addDevice('Trezor hold', 'Trezor', 'hold_accident') diff --git a/cypress/integration/spec_wallet_send.js b/cypress/integration/spec_wallet_send.js index 914a96c15..916cf94c3 100644 --- a/cypress/integration/spec_wallet_send.js +++ b/cypress/integration/spec_wallet_send.js @@ -4,13 +4,6 @@ describe('Test sending transactions', () => { Cypress.config('includeShadowDom', true) }) - // Keeps the session cookie alive, Cypress by default clears all cookies before each test - beforeEach(() => { - cy.viewport(1200,660) - cy.visit('/') - Cypress.Cookies.preserveOnce('session') - }) - it('Send a standard transaction', () => { cy.addHotDevice("Hot Device 1","bitcoin") cy.addWallet('Test Hot Wallet 1', 'segwit', 'funded', 'btc', 'singlesig', 'Hot Device 1') @@ -21,6 +14,7 @@ describe('Test sending transactions', () => { cy.get('#recipient_0').get('#send_max').click() cy.get('#create_psbt_btn').click() cy.get('body').contains("Paste signed transaction") + // TODO: Add check of transaction details here cy.get('#hot_device_1_tx_sign_btn').click() cy.get('#hot_device_1_hot_sign_btn').click() cy.get('#hot_enter_passphrase__submit').click() @@ -95,13 +89,15 @@ describe('Test sending transactions', () => { cy.get('#recipient_4').find('#amount').type(5, { force: true }) cy.get('main').scrollTo('bottom') - // Check the fee selection + // Check subtract fees from amount checkbox to subtract from a specific recipient cy.get('#toggle_advanced').click() - cy.get('#fee-selection-component').find('.fee_container').find('input#subtract').click() - cy.get('#fee-selection-component').find('.fee_container').find('input#subtract').invoke('prop', 'checked').should('eq', true) + cy.get('main').scrollTo('bottom') + cy.get('[data-cy="subtract-fees-checkbox"]').click() + cy.get('[data-cy="subtract-fees-checkbox"]').should('be.checked') - // Check whether the recipient number select field is visible - cy.get('#fee-selection-component').find('.fee_container').find('span#subtract_from').should('be.visible') + // Check whether the recipient number select field popped up + cy.get('[data-cy="subtract-from-recipient-selection"]').as('subtractFromRecipientSelection') + cy.get('@subtractFromRecipientSelection').should('be.visible') // Check the values of the hidden inputs in the light DOM which are used for the form // Note: Despite identical ids the hidden inputs seem to be fetched first since they are higher up in the DOM @@ -112,11 +108,12 @@ describe('Test sending transactions', () => { cy.get('#recipient_2').find('#remove').click({ force: true }) // Select different recipients to subtract the fees from - cy.get('#fee-selection-component').find('.fee_container').find('#subtract_from_recipient_id_select').select('Recipient 4') // html select with cypress: https://www.cypress.io/blog/2020/03/20/working-with-select-elements-and-select2-widgets-in-cypress/ - cy.get('#fee-selection-component').find('.fee_container').find('#subtract_from_recipient_id_select').select('Recipient 5') - cy.get('#fee-selection-component').find('.fee_container').find('#subtract_from_recipient_id_select').select('Recipient 2') - cy.get('#fee-selection-component').find('.fee_container').find('#subtract_from_recipient_id_select').should('have.value', '1'); - cy.get('#fee-selection-component').find('.fee_container').find('#subtract_from_recipient_id_select').find(':selected').should('have.text', 'Recipient 2'); + cy.get('[data-cy="subtract-from-recipient-selection"]').as('subtractFromRecipientSelection') + cy.get('@subtractFromRecipientSelection').select('Recipient 4') // html select with cypress: https://www.cypress.io/blog/2020/03/20/working-with-select-elements-and-select2-widgets-in-cypress/ + cy.get('@subtractFromRecipientSelection').select('Recipient 5') + cy.get('@subtractFromRecipientSelection').select('Recipient 2') + cy.get('@subtractFromRecipientSelection').should('have.value', '1'); + cy.get('@subtractFromRecipientSelection').find(':selected').should('have.text', 'Recipient 2'); cy.get('#create_psbt_btn').click() var amount = 0 @@ -162,32 +159,37 @@ describe('Test sending transactions', () => { // Check whether the subtract fees box is ticked (we used send max) cy.get('#toggle_advanced').click() - cy.get('#fee-selection-component').find('.fee_container').find('input#subtract').invoke('prop', 'checked').should('eq', true) - - // Check whether the recipient number input field is visible - cy.get('#fee-selection-component').find('.fee_container').find('span#subtract_from').should('be.visible') + cy.get('[data-cy="subtract-fees-checkbox"]').should('be.checked') + + // Check whether the selection of the recipient to subtract the fees from is visible + cy.get('main').scrollTo('bottom') + cy.get('[data-cy="subtract-from-recipient-selection"]').as('subtractFromRecipientSelection') + cy.get('@subtractFromRecipientSelection').should('be.visible') // Check the values of the hidden inputs in the light DOM which are used for the form // Note: Despite identical ids the hidden inputs seem to be fetched first since they are higher up in the DOM cy.get('#fee-selection-component').find('#subtract').invoke('attr', 'value').should('eq', 'true') // Check whether send max set subtract_from to Recipient 3 - cy.get('#fee-selection-component').find('.fee_container').find('#subtract_from_recipient_id_select').should('have.value', '2'); - cy.get('#fee-selection-component').find('.fee_container').find('#subtract_from_recipient_id_select').find(':selected').should('have.text', 'Recipient 3'); + cy.get('@subtractFromRecipientSelection').should('have.value', '2'); + cy.get('@subtractFromRecipientSelection').find(':selected').should('have.text', 'Recipient 3'); // Select Recipient 2 to subract the fee from - cy.get('#fee-selection-component').find('.fee_container').find('#subtract_from_recipient_id_select').select('Recipient 2') - cy.get('#fee-selection-component').find('.fee_container').find('#subtract_from_recipient_id_select').should('have.value', '1'); - cy.get('#fee-selection-component').find('.fee_container').find('#subtract_from_recipient_id_select').find(':selected').should('have.text', 'Recipient 2'); + cy.get('@subtractFromRecipientSelection').select('Recipient 2') + cy.get('@subtractFromRecipientSelection').should('have.value', '1'); + cy.get('@subtractFromRecipientSelection').find(':selected').should('have.text', 'Recipient 2'); // Change it back to Recipient 3 cy.get('#recipient_2').find('#send_max').click() // The fee should be subtracted from the third recipient cy.get('#create_psbt_btn').click() + // TODO: Avoid nth child cy.get('div.tx_info > :nth-child(3) > :nth-child(1)').then(($div) => { const amount = parseFloat($div.text()) - expect(amount).to.be.lte(5) + // Subtracting fees should give a number with decimals (amount above where whole numbers) + expect(amount % 1).not.to.equal(0); + }) cy.get('#deletepsbt_btn').click() // Clean up (Hot Device 1 is still needed below) diff --git a/cypress/integration/spec_wallet_utxo.js b/cypress/integration/spec_wallet_utxo.js index b550f64f9..4c8bf9154 100644 --- a/cypress/integration/spec_wallet_utxo.js +++ b/cypress/integration/spec_wallet_utxo.js @@ -3,7 +3,6 @@ describe('Test the actions in UTXO list', () => { before(() => { cy.visit('/') - cy.viewport(1200,660) Cypress.config('includeShadowDom', true) const device_name = "UTXO device" const wallet_name = "UTXO wallet" @@ -22,13 +21,6 @@ describe('Test the actions in UTXO list', () => { }) }) - // 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('Freezing', () => { cy.selectWallet('UTXO wallet') cy.get('[data-cy="utxo-list-btn"]').click() diff --git a/cypress/support/index.js b/cypress/support/index.js index d68db96df..b6b6a09e0 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -18,3 +18,11 @@ import './commands' // Alternatively you can use CommonJS syntax: // require('./commands') + +// Set the view port for each test +beforeEach(() => { + cy.viewport('macbook-13') + cy.session('preserveSession', () => {}) // Keeps the session cookie alive, Cypress by default clears all cookies before each test + cy.visit('/') + }) + \ No newline at end of file diff --git a/src/cryptoadvance/specter/static/output.css b/src/cryptoadvance/specter/static/output.css index 4decc42ee..146ad21e6 100644 --- a/src/cryptoadvance/specter/static/output.css +++ b/src/cryptoadvance/specter/static/output.css @@ -1389,16 +1389,12 @@ input[type="number"]::-webkit-outer-spin-button, height: 2.75rem; } -.h-64 { - height: 16rem; -} - .h-12 { height: 3rem; } -.h-20 { - height: 5rem; +.h-64 { + height: 16rem; } .max-h-\[40px\] { diff --git a/src/cryptoadvance/specter/templates/includes/fee-selection.html b/src/cryptoadvance/specter/templates/includes/fee-selection.html index c894b96d5..50b084e82 100644 --- a/src/cryptoadvance/specter/templates/includes/fee-selection.html +++ b/src/cryptoadvance/specter/templates/includes/fee-selection.html @@ -52,7 +52,7 @@
- +
@@ -198,6 +198,8 @@ * (can be called many times if an element is repeatedly added/removed) */ connectedCallback() { + // Adding the data-cy attribute here to avoid it be cloned when creating the light DOM elements + this.subtract.setAttribute('data-cy', 'subtract-fees-checkbox') // fetch the fees this.fetchFees() // Looks like this: {"result": {"fastestFee": 8, "halfHourFee": 8, "hourFee": 8, "minimumFee": 1}, "error_messages": []} diff --git a/src/cryptoadvance/specter/templates/includes/tx-table.html b/src/cryptoadvance/specter/templates/includes/tx-table.html index c6314303a..f8964c7ff 100644 --- a/src/cryptoadvance/specter/templates/includes/tx-table.html +++ b/src/cryptoadvance/specter/templates/includes/tx-table.html @@ -290,7 +290,7 @@ -