diff --git a/cypress/E2E_TESTING_GUIDE.md b/cypress/E2E_TESTING_GUIDE.md index 37f655e99..a024bba11 100644 --- a/cypress/E2E_TESTING_GUIDE.md +++ b/cypress/E2E_TESTING_GUIDE.md @@ -33,6 +33,8 @@ cy.get('[data-testid="activity"]') Takes the HTML of the visible activity and matches it against the old version. If you need to update the snapshots, remove the outdated one and rerun the tests. +You can also run `npm run cy:record`, and then check the appropriate `git diff`. + ## Should I write an e2e test? E2e tests are very expensive compared to other ones. If you are writing tests for a minor bug, try to write a unit test first. You should write e2e tests for: diff --git a/cypress/e2e/wallet_balance.cy.js b/cypress/e2e/wallet_balance.cy.js index dee9764b3..32813e976 100644 --- a/cypress/e2e/wallet_balance.cy.js +++ b/cypress/e2e/wallet_balance.cy.js @@ -3,7 +3,10 @@ describe('Wallet balance tests', () => { cy.clearDb(); const now = new Date(2024, 11, 5); cy.clock(now); - cy.playback('GET', /explorer/, { toBeCalledAtLeast: 4 }).as('sync'); + cy.playback('GET', /address/, { + toBeCalledAtLeast: 4, + matching: { ignores: ['hostname', 'port'] }, + }).as('sync'); cy.visit('/'); cy.importWallet('DLabsktzGMnsK5K9uRTMCF6NoYNY6ET4Bb'); }); @@ -11,7 +14,7 @@ describe('Wallet balance tests', () => { for (let i = 0; i < 5; i++) { cy.wait('@sync'); } - cy.get('[data-testid="primaryBalance"]').contains('1,297'); + cy.get('[data-testid="primaryBalance"]').contains('0'); for (let i = 0; i < 10; i++) { cy.get('[data-testid="activity"]') diff --git a/cypress/fixtures/e2e/wallet-balance-cy/wallet-balance-tests-calculates-balance-correctly.cy-playback b/cypress/fixtures/e2e/wallet-balance-cy/wallet-balance-tests-calculates-balance-correctly.cy-playback index fc91f00c1..86165a84f 100644 Binary files a/cypress/fixtures/e2e/wallet-balance-cy/wallet-balance-tests-calculates-balance-correctly.cy-playback and b/cypress/fixtures/e2e/wallet-balance-cy/wallet-balance-tests-calculates-balance-correctly.cy-playback differ diff --git a/cypress/snapshots/html/snapshot.html b/cypress/snapshots/html/snapshot.html index c529356ae..66567e073 100644 --- a/cypress/snapshots/html/snapshot.html +++ b/cypress/snapshots/html/snapshot.html @@ -1,4 +1,28 @@ -
TimeDescriptionAmount
11/02/24Block Reward4.00 PIV +
TimeDescriptionAmount
11/07/24Block Reward4.00 PIV + + +
11/07/24Sent to DJYKS3...780 PIV + + +
11/06/24Delegated to SdgQDp...500 PIV + + +
11/04/24Sent to D9m8Q9...10.00 PIV + + +
11/04/24Sent to D9m8Q9...5.00 PIV + + +
11/04/24Sent to D9m8Q9...2.00 PIV + + +
11/02/24Block Reward4.00 PIV @@ -414,28 +438,4 @@ -
06/22/24Received with DLabsk...5.10 PIV - - -
06/22/24Received with DLabsk...0.63 PIV - - -
06/22/24Received with DLabsk...0.50 PIV - - -
06/22/24Received with DLabsk...0.50 PIV - - -
06/22/24Received with DLabsk...1.26 PIV - - -
06/22/24Received with DLabsk...0.31 PIV - -
\ No newline at end of file diff --git a/cypress/support/snapshot.js b/cypress/support/snapshot.js index 73d228c1e..ab391d454 100644 --- a/cypress/support/snapshot.js +++ b/cypress/support/snapshot.js @@ -11,7 +11,7 @@ Cypress.Commands.add( const snapshotPath = `cypress/snapshots/html/${snapshotName}.html`; cy.task('fileExists', snapshotPath).then((exists) => { - if (exists) { + if (exists && !process.env.CYPRESS_PLAYBACK_MODE === 'record') { cy.readFile(snapshotPath).then((expectedHtml) => { expect(htmlContent === expectedHtml).to.equal(true); }); diff --git a/package.json b/package.json index 3fa0e5797..5275045dc 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "coverage": "vitest --coverage", "cy:open": "TZ=Europe/London npx cypress open", "cy:run": "TZ=Europe/London npx cypress run --browser chromium", - "cy:ci": "TZ=Europe/London start-server-and-test dev http://localhost:5500 cy:run" + "cy:ci": "TZ=Europe/London start-server-and-test dev http://localhost:5500 cy:run", + "cy:record": "CYPRESS_PLAYBACK_MODE=record start-server-and-test dev http://localhost:5500 cy:run" }, "repository": { "type": "git",