From 4df18e21a8af757cd39e7a46d308d51af74ac411 Mon Sep 17 00:00:00 2001 From: Martin Vere Cihlar Date: Fri, 24 Jan 2025 21:14:08 +0100 Subject: [PATCH] feat(e2e): New test that actually works with a new tab --- .../support/pageActions/dashboardActions.ts | 4 ++-- .../e2e/tests/suite/multiple-sessions.test.ts | 21 +++++++++++++++++-- .../tests/suite/database-migration.test.ts | 4 ++-- .../tests/suite/passphrase-cardano.test.ts | 8 +++---- .../DeviceItem/DeviceStatusText.tsx | 6 ++++-- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/packages/suite-desktop-core/e2e/support/pageActions/dashboardActions.ts b/packages/suite-desktop-core/e2e/support/pageActions/dashboardActions.ts index 5ef6a35c50e..35a589983bd 100644 --- a/packages/suite-desktop-core/e2e/support/pageActions/dashboardActions.ts +++ b/packages/suite-desktop-core/e2e/support/pageActions/dashboardActions.ts @@ -41,10 +41,10 @@ export class DashboardActions { this.addStandardWalletButton = this.page.getByTestId('@switch-device/add-wallet-button'); this.hideBalanceButton = this.page.getByTestId('@quickActions/hideBalances'); this.portfolioFiatAmount = this.page.getByTestId('@dashboard/portfolio/fiat-amount'); - this.deviceStatus = this.page.getByTestId('@deviceStatus'); + this.deviceStatus = this.page.locator("[data-testid-alt='@deviceStatus']"); this.deviceStatusOnSwitchDevice = this.page .getByTestId('@menu/switch-device') - .getByTestId('@deviceStatus'); + .getByTestId("[data-testid-alt='@deviceStatus']"); this.solveIssuesButton = this.page.getByTestId('@switch-device/solve-issue-button'); } diff --git a/packages/suite-desktop-core/e2e/tests/suite/multiple-sessions.test.ts b/packages/suite-desktop-core/e2e/tests/suite/multiple-sessions.test.ts index aa11f3e1738..aba6250c965 100644 --- a/packages/suite-desktop-core/e2e/tests/suite/multiple-sessions.test.ts +++ b/packages/suite-desktop-core/e2e/tests/suite/multiple-sessions.test.ts @@ -2,6 +2,7 @@ import { BridgeTransport } from '@trezor/transport'; import * as messages from '@trezor/protobuf/src/messages'; import { test, expect } from '../../support/fixtures'; +import { DashboardActions } from '../../support/pageActions/dashboardActions'; const stealBridgeSession = async () => { const bridge = new BridgeTransport({ messages, id: 'foo-bar' }); @@ -15,11 +16,11 @@ const stealBridgeSession = async () => { const testCases = [ { - description: 'Multiple sessions for view-only disabled', + description: 'Session overtaken by another - View-Only Disabled', enableViewOnly: false, }, { - description: 'Multiple sessions for view-only enabled', + description: 'Session overtaken by another - View-Only Enabled', enableViewOnly: true, }, ]; @@ -68,4 +69,20 @@ test.describe('Multiple sessions', { tag: ['@group=suite'] }, () => { }); }); } + + test( + 'Overtake session by opening suite new tab', + { tag: ['@webOnly'] }, + async ({ context, onboardingPage, dashboardPage }) => { + await onboardingPage.completeOnboarding(); + await dashboardPage.discoveryShouldFinish(); + + const pageTwo = await context.newPage(); + await pageTwo.goto(''); + const dashboardPageTwo = new DashboardActions(pageTwo); + await dashboardPageTwo.discoveryShouldFinish(); + await expect(dashboardPageTwo.deviceStatus).toHaveText('Connected'); + await expect(dashboardPage.deviceStatus).toHaveText('Refresh'); + }, + ); }); diff --git a/packages/suite-web/e2e/tests/suite/database-migration.test.ts b/packages/suite-web/e2e/tests/suite/database-migration.test.ts index 44c071c25e5..4bfd8e6eb47 100644 --- a/packages/suite-web/e2e/tests/suite/database-migration.test.ts +++ b/packages/suite-web/e2e/tests/suite/database-migration.test.ts @@ -119,7 +119,7 @@ describe('Database migration', () => { cy.getTestElement('@dashboard/graph', { timeout: 40000 }).should('be.visible'); cy.getTestElement('@account-menu/btc/normal/0').click(); cy.getTestElement('@menu/switch-device').click(); - cy.getTestElement('@deviceStatus').should('have.text', 'Disconnected'); + cy.getTestElement('@deviceStatus-disconnected'); cy.contains('[data-testid^="@switch-device/wallet-on-index"]', 'Passphrase wallet #1') .find('input') .should('be.checked'); @@ -152,7 +152,7 @@ describe('Database migration', () => { cy.task('startEmu'); cy.disableFirmwareHashCheck(); // only applicable for the `to` version, not the older `from` version - cy.getTestElement('@deviceStatus').should('have.text', 'Connected'); + cy.getTestElement('@deviceStatus-connected').should('be.visible'); cy.getTestElement('@account-subpage/back').last().click(); // checking the Send form diff --git a/packages/suite-web/e2e/tests/suite/passphrase-cardano.test.ts b/packages/suite-web/e2e/tests/suite/passphrase-cardano.test.ts index 0772fb8fd98..2696d7d42c6 100644 --- a/packages/suite-web/e2e/tests/suite/passphrase-cardano.test.ts +++ b/packages/suite-web/e2e/tests/suite/passphrase-cardano.test.ts @@ -49,9 +49,9 @@ describe('Passphrase with cardano', () => { // restart device cy.task('stopEmu'); - cy.getTestElement('@deviceStatus').should('have.text', 'Disconnected'); + cy.getTestElement('@deviceStatus-disconnected'); cy.task('startEmu'); - cy.getTestElement('@deviceStatus').should('have.text', 'Connected'); + cy.getTestElement('@deviceStatus-connected'); // reveal cardano address cy.getTestElement('@account-menu/ada/normal/0').click(); @@ -77,9 +77,9 @@ describe('Passphrase with cardano', () => { // restart device again // restart device cy.task('stopEmu'); - cy.getTestElement('@deviceStatus').should('have.text', 'Disconnected'); + cy.getTestElement('@deviceStatus-disconnected'); cy.task('startEmu'); - cy.getTestElement('@deviceStatus').should('have.text', 'Connected'); + cy.getTestElement('@deviceStatus-connected'); // reveal cardano address, now enter wrong passphrase cy.getTestElement('@wallet/receive/reveal-address-button').click(); diff --git a/packages/suite/src/views/suite/SwitchDevice/DeviceItem/DeviceStatusText.tsx b/packages/suite/src/views/suite/SwitchDevice/DeviceItem/DeviceStatusText.tsx index cd45cf8bc89..c27a6a8b51d 100644 --- a/packages/suite/src/views/suite/SwitchDevice/DeviceItem/DeviceStatusText.tsx +++ b/packages/suite/src/views/suite/SwitchDevice/DeviceItem/DeviceStatusText.tsx @@ -38,7 +38,8 @@ const DeviceStatusVisible = ({ device, connected, forceConnectionInfo }: DeviceS {walletText && !forceConnectionInfo ? ( @@ -65,7 +66,8 @@ export const DeviceStatusText = ({