Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(e2e): Migrated more wallet tests #17232

Merged
merged 4 commits into from
Feb 26, 2025
Merged

feat(e2e): Migrated more wallet tests #17232

merged 4 commits into from
Feb 26, 2025

Conversation

HajekOndrej
Copy link
Contributor

Description

Migrated more wallet tests

Related Issue

Resolve

Screenshots:

Copy link

coderabbitai bot commented Feb 25, 2025

Walkthrough

The pull request primarily introduces changes to the wallet testing setup and related functionalities. It re-enables a wallet test group in the continuous integration workflow by updating the configuration to include specific container environments. Additionally, new utility and action methods have been added to support CSV to JSON conversion and transaction exports within the wallet module. The end-to-end test suites have been expanded in the desktop project to cover scenarios such as account type additions, transaction exports in multiple formats, CSV imports for Bitcoin, and Bitcoin send actions in a regtest environment. Concurrently, similar tests in the web project have been removed. The commit also updates a submodule reference to point to a newer commit of a common library, ensuring that an updated version is used across the project.

Tip

CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 43b1428 and c5a06c8.

⛔ Files ignored due to path filters (1)
  • packages/suite-desktop-core/e2e/fixtures/btcTest.csv is excluded by !**/*.csv
📒 Files selected for processing (13)
  • .github/workflows/test-suite-web-e2e-pw.yml (1 hunks)
  • packages/suite-desktop-core/e2e/support/csvToJson.ts (1 hunks)
  • packages/suite-desktop-core/e2e/support/pageActions/walletActions.ts (2 hunks)
  • packages/suite-desktop-core/e2e/tests/metadata/output-labeling.test.ts (2 hunks)
  • packages/suite-desktop-core/e2e/tests/wallet/add-account-types.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/wallet/export-transactions.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/wallet/import-btc-csv.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/wallet/send-form-regtest.test.ts (1 hunks)
  • packages/suite-web/e2e/tests/wallet/add-account-types.test.ts (0 hunks)
  • packages/suite-web/e2e/tests/wallet/export-transactions.test.ts (0 hunks)
  • packages/suite-web/e2e/tests/wallet/import-btc-csv.test.ts (0 hunks)
  • packages/suite-web/e2e/tests/wallet/send-form-regtest.test.ts (0 hunks)
  • submodules/trezor-common (1 hunks)
💤 Files with no reviewable changes (4)
  • packages/suite-web/e2e/tests/wallet/send-form-regtest.test.ts
  • packages/suite-web/e2e/tests/wallet/add-account-types.test.ts
  • packages/suite-web/e2e/tests/wallet/export-transactions.test.ts
  • packages/suite-web/e2e/tests/wallet/import-btc-csv.test.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • submodules/trezor-common
  • packages/suite-desktop-core/e2e/support/csvToJson.ts
  • .github/workflows/test-suite-web-e2e-pw.yml
  • packages/suite-desktop-core/e2e/tests/wallet/export-transactions.test.ts
  • packages/suite-desktop-core/e2e/tests/metadata/output-labeling.test.ts
  • packages/suite-desktop-core/e2e/tests/wallet/import-btc-csv.test.ts
  • packages/suite-desktop-core/e2e/tests/wallet/send-form-regtest.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: build-web
  • GitHub Check: build-web
🔇 Additional comments (8)
packages/suite-desktop-core/e2e/support/pageActions/walletActions.ts (2)

7-7: Good type definition that improves code readability.

The ExportType type provides a clear contract for the allowed export formats and makes the code more maintainable. If more export types are added in the future, they can be added to this single definition.


141-145: Clean implementation of transaction export functionality.

The method follows the established pattern with the @step() decorator and provides a consistent interface for exporting transactions in different formats. The use of the dedicated type parameter makes the API clear and type-safe.

packages/suite-desktop-core/e2e/tests/wallet/add-account-types.test.ts (6)

7-16: Well-structured test suite setup.

The test suite is properly tagged with @group=wallet and has appropriate setup configuration with a predefined mnemonic. The beforeEach hook ensures that all tests start with a properly onboarded device and completed discovery.


68-73: Good approach to exclude skeleton elements from account counting.

The selector properly excludes skeleton elements when counting accounts, which prevents false positives during loading states.


79-80: Avoid arbitrary timeouts in tests.

While I understand from previous comments that the click method doesn't implicitly wait as expected in this case, using a hardcoded timeout is still not ideal as it can lead to flaky tests depending on system performance.

Consider exploring alternative approaches such as:

  1. Implementing a custom utility function that polls for element visibility with a timeout
  2. Using a combination of waitForSelector with a state check before clicking
#!/bin/bash
# Check if Playwright has built-in solutions for this scenario
grep -r "waitForSelector" --include="*.ts" packages/suite-desktop-core/e2e/
grep -r "waitForLoadState" --include="*.ts" packages/suite-desktop-core/e2e/

114-117: Great test data organization with path information.

Including the derivation paths in the test data is excellent for verifying the analytics events. This approach ensures that the test is comprehensive and validates both UI behavior and the corresponding analytics events.


128-132: Good analytics verification setup.

Intercepting analytics and resetting the requests array before each coin test ensures accurate verification of the events triggered by each specific action.


150-156: Thorough analytics event verification.

The test properly validates all relevant properties of the analytics event, ensuring that the correct information is being tracked when new accounts are created.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (12)
packages/suite-desktop-core/e2e/support/csvToJson.ts (1)

1-16: Add error handling and support for more complex CSV formats.

The current implementation makes several assumptions about the CSV format that might not hold true in all cases. Consider enhancing this function with:

  1. Input validation to ensure the CSV is properly formatted
  2. Handling for cases where row length doesn't match header length
  3. Support for quoted values that may contain commas
  4. Handling for empty lines, especially at the end of the file
export const csvToJson = (data: string) => {
+    if (!data || typeof data !== 'string') {
+        return [];
+    }
+    
    const lines = data.split('\n');
+    // Filter out empty lines
+    const nonEmptyLines = lines.filter(line => line.trim().length > 0);
+    
+    if (nonEmptyLines.length < 2) {
+        return [];
+    }
+    
    const result = [];
-    const headers = lines[0].split(',');
+    const headers = nonEmptyLines[0].split(',').map(header => header.trim());
-    for (let i = 1; i < lines.length; i++) {
+    for (let i = 1; i < nonEmptyLines.length; i++) {
        const obj: Record<string, string> = {};
-        const currentline = lines[i].split(',');
+        const currentline = nonEmptyLines[i].split(',').map(value => value.trim());

-        for (let j = 0; j < headers.length; j++) {
+        for (let j = 0; j < Math.min(headers.length, currentline.length); j++) {
            obj[headers[j]] = currentline[j];
        }
        result.push(obj);
    }

    return result;
};
packages/suite-desktop-core/e2e/support/pageActions/walletActions.ts (1)

139-143: Add type safety and documentation for exportTransactions method.

The method currently accepts any string without validation. Consider:

  1. Creating an enum or union type for valid export formats (CSV, PDF, JSON)
  2. Adding JSDoc to document the purpose and allowed values
+/**
+ * Export types supported by the wallet
+ */
+export type ExportType = 'csv' | 'pdf' | 'json';

 @step()
-async exportTransactions(typeOfExport: string) {
+/**
+ * Exports transactions in the specified format
+ * @param typeOfExport The format to export (csv, pdf, json)
+ */
+async exportTransactions(typeOfExport: ExportType) {
     await this.page.getByTestId('@wallet/accounts/export-transactions/dropdown').click();
     await this.page.getByTestId(`@wallet/accounts/export-transactions/${typeOfExport}`).click();
 }
packages/suite-desktop-core/e2e/tests/wallet/import-btc-csv.test.ts (2)

31-37: Consider adding error handling for file operations.

The test assumes that the CSV file exists and is accessible. Consider adding error handling for the file operations to make the test more robust.

- const csvFilePath = path.join(__dirname, '../../fixtures/btcTest.csv');
- await dashboardPage.modal.locator('input[type=file]').setInputFiles(csvFilePath);
- await dashboardPage.modal.waitFor({ state: 'detached' });
-
- const csvData = fs.readFileSync(csvFilePath, 'utf8');
+ const csvFilePath = path.join(__dirname, '../../fixtures/btcTest.csv');
+ try {
+   await dashboardPage.modal.locator('input[type=file]').setInputFiles(csvFilePath);
+   await dashboardPage.modal.waitFor({ state: 'detached' });
+   
+   const csvData = fs.readFileSync(csvFilePath, 'utf8');
+   const convertedData = csvToJson(csvData);
+   // Continue with assertions...
+ } catch (error) {
+   throw new Error(`Error during CSV file operations: ${error.message}`);
+ }

37-41: Consider verifying all CSV entries, not just the first two.

The test only verifies the first two addresses from the CSV file. If the file contains more entries, consider either:

  1. Verifying all entries in a loop
  2. Adding a comment explaining why only the first two are verified

This would make the test more comprehensive and clear about its intent.

packages/suite-desktop-core/e2e/tests/wallet/export-transactions.test.ts (3)

34-38: Inconsistent BTC filter logic.

The code filters out BTC when enabling networks but includes it in the testing loop. This might be intentional if BTC is enabled by default, but a clarifying comment would improve readability.

const symbols: NetworkSymbol[] = ['btc', 'ltc', 'eth', 'ada'];
await settingsPage.navigateTo('coins');
+ // BTC is enabled by default, so we only need to enable other networks
for (const symbol of symbols.filter(s => s !== 'btc')) {
    await settingsPage.coins.enableNetwork(symbol);
}

46-58: Extract export types to a constant and improve file verification.

The export types are defined inline and the file verification only checks that the size is greater than 0. Consider:

  1. Moving the export types to a constant at the top of the file
  2. Adding more specific content verification for each export type

This would improve maintainability and test robustness.

+ const EXPORT_TYPES = ['pdf', 'csv', 'json'];
+
test.describe('Export transactions', { tag: ['@group=wallet', '@webOnly'] }, () => {
    // ...
    test('Go to account and try to export all possible variants (pdf, csv, json)', async ({
        // ...
    }) => {
        // ...
        for (const symbol of symbols) {
            await walletPage.accountButton({ symbol }).click();

-            const typesOfExport = ['pdf', 'csv', 'json'];
-            for (const type of typesOfExport) {
+            for (const type of EXPORT_TYPES) {
                // ...

55-57: Add cleanup for downloaded files.

The test downloads files but doesn't clean them up afterward. Consider adding cleanup logic to avoid accumulating files during multiple test runs.

const downloadPath = await download.path();
const stats = fs.statSync(downloadPath);
expect(stats.size).toBeGreaterThan(0);
+ // Clean up downloaded file
+ fs.unlinkSync(downloadPath);
packages/suite-desktop-core/e2e/tests/wallet/add-account-types.test.ts (2)

68-73: Reduce code duplication in account counting logic.

There's repetition in how accounts are counted before and after addition. Consider extracting this into a helper function.

+ async function getAccountCount(page, selector) {
+     return await page
+         .getByTestId(selector)
+         .locator(':scope > *:not([data-testid="@account-menu/account-item-skeleton"])')
+         .count();
+ }
+
// Then use it like:
- const numberOfAccountsBefore = await page
-     .getByTestId(`@account-menu/${type}/group`)
-     .locator(':scope > *:not([data-testid="@account-menu/account-item-skeleton"])')
-     .count();
+ const numberOfAccountsBefore = await getAccountCount(page, `@account-menu/${type}/group`);

Also applies to: 83-88, 133-137, 145-149


114-117: Document the purpose of hardcoded derivation paths.

The test uses specific derivation paths for ADA and ETH. It would be helpful to include a comment explaining why these specific paths are used and what they represent.

const coins = [
+   // Using standard derivation paths for ADA and ETH to verify account creation
    { symbol: 'ada', path: `m/1852'/1815'/1'` },
    { symbol: 'eth', path: `m/44'/60'/0'/0/1` },
];
packages/suite-desktop-core/e2e/tests/wallet/send-form-regtest.test.ts (3)

3-5: Document the purpose of hardcoded address constant.

The ADDRESS_INDEX_1 constant is used throughout the tests. Include a comment explaining what this address represents and why it's used.

test.describe('Send form for bitcoin', { tag: ['@group=wallet'] }, () => {
+   // Test address used for sending and receiving BTC in regtest environment
    const ADDRESS_INDEX_1 = 'bcrt1qkvwu9g3k2pdxewfqr7syz89r3gj557l374sg5v';

89-90: Use more descriptive OP_RETURN data.

The test uses meow as the OP_RETURN data, which is not descriptive of the test's intent. Consider using a more meaningful string.

- await page.getByTestId('outputs.1.dataAscii').fill('meow');
+ await page.getByTestId('outputs.1.dataAscii').fill('test_opreturn_data');

Similarly, update the assertion on line 101:

- await expect(page.getByTestId('@wallet/accounts/transaction-list/pending/group/0')).toContainText('OP_RETURN (meow)');
+ await expect(page.getByTestId('@wallet/accounts/transaction-list/pending/group/0')).toContainText('OP_RETURN (test_opreturn_data)');

98-102: Add verification for transaction confirmation.

The test verifies that the transaction appears in the pending list but doesn't verify that it gets confirmed. Consider mining a block and checking that the transaction moves from pending to confirmed status.

await devicePrompt.sendButton.click();
await expect(
    page.getByTestId('@wallet/accounts/transaction-list/pending/group/0'),
).toContainText('OP_RETURN (meow)');
+
+ // Mine a block and verify transaction confirmation
+ await trezorUserEnvLink.mineBlocks({ block_amount: 1 });
+ await expect(
+     page.getByTestId('@wallet/accounts/transaction-list/pending/group/0'),
+ ).not.toBeVisible({ timeout: 10000 });
+ await expect(
+     page.getByTestId('@wallet/accounts/transaction-list/confirmed/group/0'),
+ ).toBeVisible();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between feb5e3e and 89f4c67.

⛔ Files ignored due to path filters (1)
  • packages/suite-desktop-core/e2e/fixtures/btcTest.csv is excluded by !**/*.csv
📒 Files selected for processing (12)
  • .github/workflows/test-suite-web-e2e-pw.yml (1 hunks)
  • packages/suite-desktop-core/e2e/support/csvToJson.ts (1 hunks)
  • packages/suite-desktop-core/e2e/support/pageActions/walletActions.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/metadata/output-labeling.test.ts (2 hunks)
  • packages/suite-desktop-core/e2e/tests/wallet/add-account-types.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/wallet/export-transactions.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/wallet/import-btc-csv.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/wallet/send-form-regtest.test.ts (1 hunks)
  • packages/suite-web/e2e/tests/wallet/add-account-types.test.ts (0 hunks)
  • packages/suite-web/e2e/tests/wallet/export-transactions.test.ts (0 hunks)
  • packages/suite-web/e2e/tests/wallet/send-form-regtest.test.ts (0 hunks)
  • submodules/trezor-common (1 hunks)
💤 Files with no reviewable changes (3)
  • packages/suite-web/e2e/tests/wallet/add-account-types.test.ts
  • packages/suite-web/e2e/tests/wallet/send-form-regtest.test.ts
  • packages/suite-web/e2e/tests/wallet/export-transactions.test.ts
✅ Files skipped from review due to trivial changes (1)
  • submodules/trezor-common
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=other, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=passphrase, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: build-web
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: build-web
🔇 Additional comments (9)
.github/workflows/test-suite-web-e2e-pw.yml (1)

119-120: LGTM! Re-enabling wallet tests with appropriate containers.

The re-enabling of the wallet test group with the required containers looks good. This change allows for running wallet-related tests as part of the web e2e test suite.

packages/suite-desktop-core/e2e/tests/metadata/output-labeling.test.ts (2)

13-19: LGTM! Adding walletPage parameter to utilize the new exportTransactions method.

Good refactoring to utilize the new method from the WalletActions class.


82-82: LGTM! Using abstracted method instead of direct element interaction.

This change improves maintainability by leveraging the new exportTransactions method.

packages/suite-desktop-core/e2e/tests/wallet/import-btc-csv.test.ts (2)

1-6: Good import organization and separation of concerns.

The imports are well organized with clear separation between standard Node.js modules and application-specific imports. The use of the custom csvToJson utility function is appropriate for this test case.


9-14: Test setup looks good with proper initialization sequence.

The test setup follows best practices by:

  1. Starting the metadata provider mock
  2. Completing onboarding
  3. Ensuring discovery finishes before each test

This provides a consistent starting state for all tests in the suite.

packages/suite-desktop-core/e2e/tests/wallet/export-transactions.test.ts (1)

7-17: Good test setup with clear configuration.

The test uses a specific mnemonic for deterministic testing and properly sets up the initial state with onboarding completion and discovery finishing. This provides a reliable test environment.

packages/suite-desktop-core/e2e/tests/wallet/add-account-types.test.ts (1)

152-158: Good use of analytics verification.

The test properly verifies that the expected analytics events are fired with the correct parameters. This ensures that the application correctly tracks user actions.

packages/suite-desktop-core/e2e/tests/wallet/send-form-regtest.test.ts (2)

32-58: Good test structure with clear actions and verifications.

The test has a clear structure with descriptive comments, appropriate inputs, and verifications of UI elements and application state.


60-75: Complete the transaction sending process in the second test.

Unlike the first and third tests, the second test doesn't complete the transaction sending process. Either add the missing steps to complete the transaction or add a comment explaining why the transaction is not sent.

Is it intentional that the second test doesn't complete the transaction sending process? If not, consider adding the following steps:

await marketPage.sendAddressInput.fill(ADDRESS_INDEX_1);
+ 
+ // Send the transaction
+ await marketPage.sendButton.click();
+ await trezorUserEnvLink.pressYes();
+ await trezorUserEnvLink.pressYes();
+ await trezorUserEnvLink.pressYes();
+ 
+ await expect(page.getByTestId('@send/copy-raw-transaction')).toBeVisible();

Comment on lines +79 to +80
await page.waitForTimeout(500);
await page.getByTestId(`@add-account-type/select/option/${type}`).click();
Copy link

@coderabbitai coderabbitai bot Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid arbitrary timeouts in tests.

Using a hardcoded timeout is not recommended as it can lead to flaky tests. Wait for a specific UI event or element instead.

- await page.getByTestId('@add-account-type/select/input').click();
- await page.waitForTimeout(500);
- await page.getByTestId(`@add-account-type/select/option/${type}`).click();
+ await page.getByTestId('@add-account-type/select/input').click();
+ await page.getByTestId(`@add-account-type/select/option/${type}`).waitFor({ state: 'visible' });
+ await page.getByTestId(`@add-account-type/select/option/${type}`).click();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await page.waitForTimeout(500);
await page.getByTestId(`@add-account-type/select/option/${type}`).click();
await page.getByTestId('@add-account-type/select/input').click();
await page.getByTestId(`@add-account-type/select/option/${type}`).waitFor({ state: 'visible' });
await page.getByTestId(`@add-account-type/select/option/${type}`).click();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is happening without it?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vere-Grey Without the timeout, the test likely tries to click on the dropdown option (@add-account-type/select/option/${type}) before the dropdown menu has fully opened or rendered. This would cause the test to fail intermittently because the element might not be clickable yet.

The suggested approach (waitFor({ state: 'visible' })) is more reliable because it explicitly waits for the dropdown option to become visible before attempting to click it, rather than using an arbitrary timeout which might be too short or unnecessarily long depending on system performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the click method does this implicitly. This doesn't help unfortunately.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
packages/suite-desktop-core/e2e/tests/wallet/add-account-types.test.ts (1)

79-80: 🛠️ Refactor suggestion

Avoid arbitrary timeouts in tests.

Using a hardcoded timeout is not recommended as it can lead to flaky tests. Wait for a specific UI event or element instead.

- await page.getByTestId('@add-account-type/select/input').click();
- await page.waitForTimeout(500);
- await page.getByTestId(`@add-account-type/select/option/${type}`).click();
+ await page.getByTestId('@add-account-type/select/input').click();
+ await page.getByTestId(`@add-account-type/select/option/${type}`).waitFor({ state: 'visible' });
+ await page.getByTestId(`@add-account-type/select/option/${type}`).click();
🧹 Nitpick comments (2)
packages/suite-desktop-core/e2e/tests/wallet/add-account-types.test.ts (2)

59-62: Consider more explicit waiting for chevrons.

When expanding all account chevrons, it might be more robust to ensure each expansion is complete before clicking the next one.

 const chevrons = await walletPage.accountChevron.all();
 for (const chevron of chevrons) {
     await chevron.click();
+    // Consider waiting for expansion to complete
+    await page.waitForTimeout(100); // Or better, wait for a specific element to appear
 }

27-94: Consider refactoring common test logic into helper functions.

Both test cases contain similar patterns for adding accounts and verifying counts. Consider extracting this logic into helper functions to improve maintainability and reduce duplication.

You could create a helper function like:

async function addAndVerifyAccount(
  page: Page, 
  coin: string, 
  type: string = 'normal', 
  analytics?: any
) {
  // Get count before
  const numberOfAccountsBefore = await getAccountCount(page, coin, type);
  
  // Add account
  await page.getByTestId('@account-menu/add-account').click();
  await expect(page.getByTestId('@modal')).toBeVisible();
  await page.getByTestId(`@settings/wallet/network/${coin}`).click();
  
  // Select type if not normal
  if (type !== 'normal') {
    await page.getByTestId('@add-account-type/select/input').click();
    await page.getByTestId(`@add-account-type/select/option/${type}`).waitFor({ state: 'visible' });
    await page.getByTestId(`@add-account-type/select/option/${type}`).click();
  }
  
  await page.getByTestId('@add-account').click();
  
  // Get count after and verify
  const numberOfAccountsAfter = await getAccountCount(page, coin, type);
  expect(numberOfAccountsAfter).toEqual(numberOfAccountsBefore + 1);
  
  // Verify analytics if provided
  if (analytics) {
    // Analytics verification logic
  }
}

Also applies to: 107-161

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9de320c and 43b1428.

⛔ Files ignored due to path filters (1)
  • packages/suite-desktop-core/e2e/fixtures/btcTest.csv is excluded by !**/*.csv
📒 Files selected for processing (13)
  • .github/workflows/test-suite-web-e2e-pw.yml (1 hunks)
  • packages/suite-desktop-core/e2e/support/csvToJson.ts (1 hunks)
  • packages/suite-desktop-core/e2e/support/pageActions/walletActions.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/metadata/output-labeling.test.ts (2 hunks)
  • packages/suite-desktop-core/e2e/tests/wallet/add-account-types.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/wallet/export-transactions.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/wallet/import-btc-csv.test.ts (1 hunks)
  • packages/suite-desktop-core/e2e/tests/wallet/send-form-regtest.test.ts (1 hunks)
  • packages/suite-web/e2e/tests/wallet/add-account-types.test.ts (0 hunks)
  • packages/suite-web/e2e/tests/wallet/export-transactions.test.ts (0 hunks)
  • packages/suite-web/e2e/tests/wallet/import-btc-csv.test.ts (0 hunks)
  • packages/suite-web/e2e/tests/wallet/send-form-regtest.test.ts (0 hunks)
  • submodules/trezor-common (1 hunks)
💤 Files with no reviewable changes (4)
  • packages/suite-web/e2e/tests/wallet/import-btc-csv.test.ts
  • packages/suite-web/e2e/tests/wallet/export-transactions.test.ts
  • packages/suite-web/e2e/tests/wallet/add-account-types.test.ts
  • packages/suite-web/e2e/tests/wallet/send-form-regtest.test.ts
🚧 Files skipped from review as they are similar to previous changes (8)
  • submodules/trezor-common
  • packages/suite-desktop-core/e2e/support/pageActions/walletActions.ts
  • .github/workflows/test-suite-web-e2e-pw.yml
  • packages/suite-desktop-core/e2e/tests/metadata/output-labeling.test.ts
  • packages/suite-desktop-core/e2e/tests/wallet/import-btc-csv.test.ts
  • packages/suite-desktop-core/e2e/tests/wallet/export-transactions.test.ts
  • packages/suite-desktop-core/e2e/tests/wallet/send-form-regtest.test.ts
  • packages/suite-desktop-core/e2e/support/csvToJson.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-web
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: build-web
  • GitHub Check: Analyze with CodeQL (javascript)
🔇 Additional comments (4)
packages/suite-desktop-core/e2e/tests/wallet/add-account-types.test.ts (4)

1-16: Good test setup with comprehensive preparation.

The setup looks well-structured with appropriate imports, emulator configuration, and proper onboarding completion before each test. The use of a predefined mnemonic ensures consistent testing environment.


18-26: Well-documented test case with clear steps.

The test case documentation clearly outlines the test steps and verification strategy, which improves readability and maintainability.


33-47: Good data-driven test approach.

Using structured data to define test scenarios makes the test more maintainable and allows for easy extension to include additional currencies or account types in the future.


107-161: Great integration of analytics validation.

The test properly verifies analytics events when adding accounts, which ensures both UI functionality and analytics tracking work correctly. The test also appropriately resets analytics requests between different coin tests.

Comment on lines +70 to +72
.locator(
':scope > *:not([data-testid="@account-menu/account-item-skeleton"])',
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one took me a while to understand.

Copy link
Contributor

@Vere-Grey Vere-Grey Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a method in walletPage for something similiar with little bit nicer locator

getAccountsCount(symbol: NetworkSymbol) {
        return await this.page
            .locator(`[data-testid*="@account-menu/${symbol}"][tabindex]`)
            .count();
    }
```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are different coins so it can't be used, unless I iterate through them and then make a sum...

Copy link
Contributor

@Vere-Grey Vere-Grey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one question and two suggestion, LGTM

@HajekOndrej HajekOndrej enabled auto-merge (squash) February 26, 2025 06:39
@HajekOndrej HajekOndrej merged commit 8cc80b0 into develop Feb 26, 2025
28 checks passed
@HajekOndrej HajekOndrej deleted the migrate-wallet-2 branch February 26, 2025 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants