Skip to content

Commit

Permalink
feat(e2e): Convert to PW unaquired device test
Browse files Browse the repository at this point in the history
rename
refactor locator @deviceStatus and few cy tests
split test to viewOnly enabled and false
  • Loading branch information
Vere-Grey committed Jan 24, 2025
1 parent ec27e56 commit 6c682fd
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class DashboardActions {
readonly graphRangeSelector = (range: graphRangeOptions) =>
this.page.getByTestId(`@dashboard/graph/range-${range}`);
readonly deviceSwitchingOpenButton: Locator;
readonly deviceSwitchingCloseButton: Locator;
readonly modal: Locator;
//TODO: Refactor to wallet page object
readonly walletAtIndex = (index: number) =>
Expand All @@ -24,18 +25,27 @@ export class DashboardActions {
readonly addStandardWalletButton: Locator;
readonly hideBalanceButton: Locator;
readonly portfolioFiatAmount: Locator;
readonly deviceStatus: Locator;
readonly deviceStatusOnSwitchDevice: Locator;
readonly solveIssuesButton: Locator;

constructor(private readonly page: Page) {
this.dashboardMenuButton = this.page.getByTestId('@suite/menu/suite-index');
this.discoveryHeader = this.page.getByRole('heading', { name: 'Dashboard' });
this.discoveryBar = this.page.getByTestId('@wallet/discovery-progress-bar');
this.graph = this.page.getByTestId('@dashboard/graph');
this.deviceSwitchingOpenButton = this.page.getByTestId('@menu/switch-device');
this.deviceSwitchingCloseButton = this.page.getByTestId('@switch-device/cancel-button');
this.modal = this.page.getByTestId('@modal');
this.confirmDeviceEjectButton = this.page.getByTestId('@switch-device/eject');
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.deviceStatusOnSwitchDevice = this.page
.getByTestId('@menu/switch-device')
.getByTestId('@deviceStatus');
this.solveIssuesButton = this.page.getByTestId('@switch-device/solve-issue-button');
}

@step()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { BridgeTransport } from '@trezor/transport';
import * as messages from '@trezor/protobuf/src/messages';

import { test, expect } from '../../support/fixtures';

const stealBridgeSession = async () => {
const bridge = new BridgeTransport({ messages, id: 'foo-bar' });
await bridge.init();
const enumerateRes = await bridge.enumerate();
if (!enumerateRes.success) return null;
await bridge.acquire({
input: { path: enumerateRes.payload[0].path, previous: null },
});
};

const testCases = [
{
description: 'Multiple sessions for view-only disabled',
enableViewOnly: false,
},
{
description: 'Multiple sessions for view-only enabled',
enableViewOnly: true,
},
];

test.describe('Multiple sessions', { tag: ['@group=suite'] }, () => {
test.use({ emulatorSetupConf: { passphrase_protection: true } });

for (const { description, enableViewOnly } of testCases) {
test(description, async ({ page, onboardingPage, dashboardPage }) => {
await onboardingPage.completeOnboarding({ enableViewOnly });
await dashboardPage.discoveryShouldFinish();
await test.step('Bridge session taken by another suite session', async () => {
await stealBridgeSession();
await expect(dashboardPage.deviceStatus).toHaveText('Refresh');
await dashboardPage.deviceSwitchingOpenButton.click();
// TODO: #16601 Uncomment once fixed
// await expect(dashboardPage.deviceStatusOnSwitchDevice).toHaveText('Refresh');
await expect(dashboardPage.walletAtIndex(0)).not.toBeVisible();
});

await test.step('Take Bridge session back', async () => {
await dashboardPage.solveIssuesButton.click();
await expect(dashboardPage.deviceStatusOnSwitchDevice).toHaveText('Connected');
await expect(dashboardPage.walletAtIndex(0)).toBeVisible();
await dashboardPage.deviceSwitchingCloseButton.click();
await expect(dashboardPage.deviceStatus).toHaveText('Connected');
});

// This is where the flow ends for view-only disabled
if (!enableViewOnly) {
return;
}

await test.step('Reloading inactive suite session does not take Bridge session back', async () => {
await stealBridgeSession();
await expect(dashboardPage.deviceStatus).toHaveText('Refresh');
await page.reload();
await expect(dashboardPage.deviceStatus).toHaveText('Disconnected');
await dashboardPage.deviceSwitchingOpenButton.click();
await expect(dashboardPage.deviceStatusOnSwitchDevice).toHaveText('Disconnected');
});

await test.step('Take Bridge session back', async () => {
await dashboardPage.solveIssuesButton.click();
await expect(dashboardPage.deviceStatusOnSwitchDevice).toHaveText('Connected');
});
});
}
});
97 changes: 0 additions & 97 deletions packages/suite-desktop-core/e2e/tests/suite/stolen-device.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/suite-web/e2e/tests/suite/database-migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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-disconnected');
cy.getTestElement('@deviceStatus').should('have.text', 'Disconnected');
cy.contains('[data-testid^="@switch-device/wallet-on-index"]', 'Passphrase wallet #1')
.find('input')
.should('be.checked');
Expand Down Expand Up @@ -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-connected').should('be.visible');
cy.getTestElement('@deviceStatus').should('have.text', 'Connected');
cy.getTestElement('@account-subpage/back').last().click();

// checking the Send form
Expand Down
8 changes: 4 additions & 4 deletions packages/suite-web/e2e/tests/suite/passphrase-cardano.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ describe('Passphrase with cardano', () => {

// restart device
cy.task('stopEmu');
cy.getTestElement('@deviceStatus-disconnected');
cy.getTestElement('@deviceStatus').should('have.text', 'Disconnected');
cy.task('startEmu');
cy.getTestElement('@deviceStatus-connected');
cy.getTestElement('@deviceStatus').should('have.text', 'Connected');

// reveal cardano address
cy.getTestElement('@account-menu/ada/normal/0').click();
Expand All @@ -77,9 +77,9 @@ describe('Passphrase with cardano', () => {
// restart device again
// restart device
cy.task('stopEmu');
cy.getTestElement('@deviceStatus-disconnected');
cy.getTestElement('@deviceStatus').should('have.text', 'Disconnected');
cy.task('startEmu');
cy.getTestElement('@deviceStatus-connected');
cy.getTestElement('@deviceStatus').should('have.text', 'Connected');

// reveal cardano address, now enter wrong passphrase
cy.getTestElement('@wallet/receive/reveal-address-button').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const DeviceStatusVisible = ({ device, connected, forceConnectionInfo }: DeviceS
<DeviceConnectionText
variant={connected ? 'primary' : 'tertiary'}
icon={connected ? 'link' : 'unlink'}
data-testid={connected ? '@deviceStatus-connected' : '@deviceStatus-disconnected'}
data-testid="@deviceStatus"
>
{walletText && !forceConnectionInfo ? (
<TruncateWithTooltip delayShow={TOOLTIP_DELAY_LONG}>
Expand All @@ -65,7 +65,7 @@ export const DeviceStatusText = ({
<DeviceConnectionText
variant="warning"
icon="refresh"
data-testid={connected ? '@deviceStatus-connected' : '@deviceStatus-disconnected'}
data-testid="@deviceStatus"
isAction
>
<Translation id="TR_SOLVE_ISSUE" />
Expand Down

0 comments on commit 6c682fd

Please sign in to comment.