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

test(suite-native): app settings e2e #17494

Merged
merged 1 commit into from
Mar 19, 2025
Merged

Conversation

PeKne
Copy link
Contributor

@PeKne PeKne commented Mar 10, 2025

Description

E2E tests added for following app settings feature:

  • - coin enabling
  • - view only mode
  • - discreet mode
  • - localization
    • change of currency
    • change of bitcoin units

Screenshots:

Screen.Recording.2025-03-10.at.7.50.07.AM720.mov

@PeKne PeKne added e2e End-to-end tests builded in CI mobile Suite Lite issues and PRs labels Mar 10, 2025
@PeKne PeKne requested a review from a team as a code owner March 10, 2025 06:58
@PeKne PeKne removed the e2e End-to-end tests builded in CI label Mar 10, 2025
Copy link

coderabbitai bot commented Mar 10, 2025

Walkthrough

The pull request implements a series of code refactorings and enhancements across end-to-end tests, page objects, utilities, and UI components. In several page object files, element selectors have been updated to consistently use the element wrapper, and method names have been refactored (for example, renaming waitForScreen to waitForInitScreen and enableNetwork to toggleNetwork). A new SettingsActions class was introduced to encapsulate settings-related interactions, and new navigation methods were added to support settings access via the tab bar. Test suites have been updated for consistency with these changes, including modifications to import statements and removal of platform-specific logic. Additionally, multiple files have been updated to include testID properties on components, improving their identifiability in testing, while utility functions were also adjusted for more flexible parameter handling.

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 (5)
suite-native/app/e2e/pageObjects/settingsActions.ts (1)

68-83: View-only mode toggle with error handling

The toggleWalletViewOnly method handles toggling the view-only mode with appropriate error handling for the alert sheet. The try-catch block gracefully handles the case where no alert appears when enabling view-only mode.

Consider splitting this into two more explicit methods for better clarity:

-    async toggleWalletViewOnly(
-        deviceName: string = TREZOR_E2E_DEVICE_LABEL,
-        walletIndex: number = 0,
-    ) {
-        const toggleButtonElement = element(
-            by.id(`@settings/view-only/toggle-button/${deviceName}/${walletIndex}`),
-        );
-        await waitFor(toggleButtonElement).toBeVisible().withTimeout(10000);
-        await toggleButtonElement.tap();
-
-        try {
-            await onAlertSheet.tapPrimaryButton();
-        } catch {
-            // Do nothing. In case of enabling view only mode, there is no alert sheet.
-        }
-    }
+    async enableWalletViewOnly(
+        deviceName: string = TREZOR_E2E_DEVICE_LABEL,
+        walletIndex: number = 0,
+    ) {
+        const toggleButtonElement = element(
+            by.id(`@settings/view-only/toggle-button/${deviceName}/${walletIndex}`),
+        );
+        await waitFor(toggleButtonElement).toBeVisible().withTimeout(10000);
+        await toggleButtonElement.tap();
+        // No alert sheet is shown when enabling view-only mode
+    }
+
+    async disableWalletViewOnly(
+        deviceName: string = TREZOR_E2E_DEVICE_LABEL,
+        walletIndex: number = 0,
+    ) {
+        const toggleButtonElement = element(
+            by.id(`@settings/view-only/toggle-button/${deviceName}/${walletIndex}`),
+        );
+        await waitFor(toggleButtonElement).toBeVisible().withTimeout(10000);
+        await toggleButtonElement.tap();
+        
+        // Alert sheet is shown when disabling view-only mode
+        await onAlertSheet.tapPrimaryButton();
+    }
+
+    // Keep the original method for backward compatibility
+    async toggleWalletViewOnly(
+        deviceName: string = TREZOR_E2E_DEVICE_LABEL,
+        walletIndex: number = 0,
+    ) {
+        const toggleButtonElement = element(
+            by.id(`@settings/view-only/toggle-button/${deviceName}/${walletIndex}`),
+        );
+        await waitFor(toggleButtonElement).toBeVisible().withTimeout(10000);
+        await toggleButtonElement.tap();
+
+        try {
+            await onAlertSheet.tapPrimaryButton();
+        } catch {
+            // Do nothing. In case of enabling view only mode, there is no alert sheet.
+        }
+    }
suite-native/app/e2e/tests/appSettingsWithDevice.test.ts (4)

37-41: Consider replacing fixed wait with deterministic alternative

Using a fixed wait time might lead to flaky tests if the device connection takes longer than expected.

- await wait(5000); // wait for trezor device to start communicating with the app
+ // Consider using a deterministic wait that checks for device readiness
+ await waitFor(element(by.id('@device-manager/device-switch').withDescendant(by.text('Connected'))))
+   .toBeVisible()
+   .withTimeout(10000);

48-65: Remove outdated TODO comment and consider extracting navigation patterns

The test effectively validates coin enabling functionality, but has an outdated TODO.

- // TODO: rename to onCoinEnabling

Also, consider extracting the repeated back navigation pattern into a utility function for better maintainability:

async function navigateBackToHome(times = 2) {
  for (let i = 0; i < times; i++) {
    await device.pressBack();
  }
}

67-119: Comprehensive view-only mode test with detailed state verification

The test thoroughly validates the view-only mode functionality with appropriate checks at each state transition. The test correctly verifies device connection states before and after toggling view-only mode and restarting the app.

However, the test contains multiple timeout values that are duplicated. Consider defining a constant for timeout values.

+ const DEVICE_CONNECTION_TIMEOUT = 10000;

  await waitFor(
      element(
          by.id('@device-manager/device-switch').withDescendant(by.text('Connected')),
      ),
  )
      .toBeVisible()
-     .withTimeout(10000);
+     .withTimeout(DEVICE_CONNECTION_TIMEOUT);

108-119: Add a comment explaining the "Hi there!" expectation

The test checks for the text "Hi there!" but it's not immediately clear why this text appears after stopping the bridge in view-only mode.

  await TrezorUserEnvLink.stopBridge();

+ // In view-only mode, disconnecting shows the welcome message instead of "Disconnected"
  await waitFor(
      element(
          by.id('@device-manager/device-switch').withDescendant(by.text('Hi there!')),
      ),
  )
      .toBeVisible()
      .withTimeout(10000);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 41828bd and a25cd1d.

📒 Files selected for processing (32)
  • suite-native/app/e2e/pageObjects/accountImportActions.ts (1 hunks)
  • suite-native/app/e2e/pageObjects/coinEnablingActions.ts (1 hunks)
  • suite-native/app/e2e/pageObjects/deviceSettingsActions.ts (2 hunks)
  • suite-native/app/e2e/pageObjects/homeActions.ts (2 hunks)
  • suite-native/app/e2e/pageObjects/send/sendOutputsReviewActions.ts (1 hunks)
  • suite-native/app/e2e/pageObjects/settingsActions.ts (1 hunks)
  • suite-native/app/e2e/pageObjects/tabBarActions.ts (1 hunks)
  • suite-native/app/e2e/tests/appSettings.test.ts (1 hunks)
  • suite-native/app/e2e/tests/appSettingsWithDevice.test.ts (1 hunks)
  • suite-native/app/e2e/tests/deeplinkPopup.test.ts (2 hunks)
  • suite-native/app/e2e/tests/deviceSettings.test.ts (2 hunks)
  • suite-native/app/e2e/tests/onboardAndConnect.test.ts (2 hunks)
  • suite-native/app/e2e/tests/passphraseFlow.test.ts (2 hunks)
  • suite-native/app/e2e/tests/receive.test.ts (2 hunks)
  • suite-native/app/e2e/tests/send.test.ts (2 hunks)
  • suite-native/app/e2e/utils.ts (3 hunks)
  • suite-native/atoms/src/DiscreetText/DiscreetText.tsx (1 hunks)
  • suite-native/atoms/src/DiscreetText/DiscreetTextTrigger.tsx (1 hunks)
  • suite-native/atoms/src/Select/Select.tsx (2 hunks)
  • suite-native/atoms/src/Select/SelectItem.tsx (1 hunks)
  • suite-native/atoms/src/Select/SelectTrigger.tsx (2 hunks)
  • suite-native/atoms/src/Sheet/BottomSheet.tsx (1 hunks)
  • suite-native/formatters/src/components/FiatBalanceFormatter.tsx (2 hunks)
  • suite-native/formatters/src/utils.ts (1 hunks)
  • suite-native/graph/src/components/GraphFiatBalance.tsx (1 hunks)
  • suite-native/module-settings/src/components/CryptoUnitsSelector.tsx (1 hunks)
  • suite-native/module-settings/src/components/CurrencySelector.tsx (1 hunks)
  • suite-native/module-settings/src/components/TouchableSwitchRow.tsx (3 hunks)
  • suite-native/module-settings/src/components/ViewOnly/WalletRow.tsx (1 hunks)
  • suite-native/module-settings/src/navigation/SettingsStackNavigator.tsx (2 hunks)
  • suite-native/module-settings/src/screens/SettingsPrivacyAndSecurityScreen.tsx (2 hunks)
  • suite-native/module-settings/src/screens/SettingsViewOnlyScreen.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: prepare_android_test_app
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: Setup and Cache Dependencies
🔇 Additional comments (63)
suite-native/module-settings/src/components/ViewOnly/WalletRow.tsx (1)

124-124: Good addition of testID for automated testing purposes.

This change enhances testability by adding a unique identifier to the Button component, making it easier to select this specific element during E2E tests. The construction of the testID follows a sensible hierarchical pattern and handles potential undefined values gracefully with the nullish coalescing operator.

suite-native/module-settings/src/components/TouchableSwitchRow.tsx (3)

14-14: Good addition of testID property to props type

Adding the optional testID to TouchableSwitchRowProps enhances testability, which aligns well with the PR objectives of implementing E2E tests for app settings.


32-32: Properly destructured the testID parameter

The parameter destructuring has been correctly updated to include the new testID property.


46-46: Correctly implemented testID on TouchableOpacity

The testID is properly passed to the TouchableOpacity component, which will allow for reliable element selection in E2E tests.

suite-native/module-settings/src/components/CryptoUnitsSelector.tsx (1)

33-33: Well-formatted testID for Bitcoin units selector

The testID follows a clear naming convention with "@settings/localization/bitcoin-units-selector", making it easily identifiable in E2E tests. This directly supports the localization testing objectives mentioned in the PR summary.

suite-native/module-settings/src/components/CurrencySelector.tsx (1)

34-34: Consistent testID for currency selector

The testID "@settings/localization/currency-selector" follows the same pattern as other selectors in the codebase, maintaining consistency for testing. This supports the localization testing for currency changes mentioned in the PR objectives.

suite-native/module-settings/src/screens/SettingsViewOnlyScreen.tsx (1)

14-14: Component renamed for better consistency

Renaming from SettingsViewOnly to SettingsViewOnlyScreen improves naming consistency with other screen components, making the codebase more maintainable. This change supports the view-only mode testing objective mentioned in the PR.

suite-native/module-settings/src/screens/SettingsPrivacyAndSecurityScreen.tsx (2)

50-50: Added testID for E2E testing

Adding a testID to the DiscreetMode toggle is good for E2E test accessibility. This aligns with the PR objectives of implementing end-to-end tests for app settings, specifically for the discreet mode feature.


112-112: Renamed component for consistency

The component has been renamed from SettingsPrivacyAndSecurity to SettingsPrivacyAndSecurityScreen, maintaining a consistent naming convention with other screen components in the codebase. This improves code readability and maintenance.

suite-native/module-settings/src/navigation/SettingsStackNavigator.tsx (2)

15-16: Updated component imports after renaming

The import statements have been updated to reflect the renamed screen components, maintaining consistency with the component name changes in their respective files.


36-36: Updated component references in navigator

The component references in the navigator have been correctly updated to use the renamed screen components, ensuring the navigation functionality remains intact after the component renames.

Also applies to: 41-41

suite-native/atoms/src/Sheet/BottomSheet.tsx (1)

123-123: Good addition of testID for improved testability.

The addition of the testID property to the ScrollView component enables more reliable selection of this element in end-to-end tests, which aligns with the PR's objectives of enhancing the testing framework.

suite-native/atoms/src/Select/SelectItem.tsx (1)

77-77: Excellent implementation of dynamic testID for Select items.

The dynamic testID pattern @select/item/${value} allows for precise targeting of specific select items in automated tests based on their values, which will be valuable for testing selection-based interactions like currency and Bitcoin unit changes.

suite-native/formatters/src/utils.ts (1)

18-18: Good improvement to currency symbol handling.

Adding the trim() method improves the handling of whitespace in currency symbols, ensuring consistent currency display in the UI. The fallback to null for falsy values also provides more predictable behavior than passing the falsy value directly.

suite-native/atoms/src/DiscreetText/DiscreetText.tsx (1)

61-61: Well-implemented conditional testID for discreet mode testing.

The conditional testID that switches between 'discreet-text' and 'plain-text' based on the current state is particularly valuable for testing the discreet mode functionality, which is specifically mentioned as one of the features targeted by this PR's test suite.

suite-native/app/e2e/pageObjects/send/sendOutputsReviewActions.ts (1)

9-9: Appropriate timeout increase for E2E test reliability

Increasing the timeout from the default to 10 seconds is a good improvement for test stability. This change reduces the likelihood of flaky tests due to timing issues, especially when the SendOutputsReview screen might take longer to load under certain conditions.

suite-native/app/e2e/pageObjects/tabBarActions.ts (1)

12-18: Well-implemented navigation method for settings

This new method follows the same pattern as the existing navigation methods, maintaining code consistency. The 10-second timeout aligns with other navigation methods, and the implementation correctly verifies that navigation was successful by checking the visibility of the Settings screen.

This addition supports the PR objective of implementing E2E tests for app settings features.

suite-native/atoms/src/Select/Select.tsx (2)

17-17: Good addition of testID to component props

Adding the optional testID property to the SelectProps type enhances component testability without changing functionality. This is a best practice for making components easily identifiable in automated tests.


25-25: Proper implementation of testID prop passing

The testID is correctly added to the props destructuring and properly passed to the SelectTrigger component, completing the implementation for test identification.

Also applies to: 56-56

suite-native/graph/src/components/GraphFiatBalance.tsx (1)

47-48: Well-structured testIDs for financial components

The addition of descriptive testIDs to both the DiscreetTextTrigger and FiatBalanceFormatter components follows good testing practices. The hierarchical naming convention (@home/portfolio/...) clearly identifies these components in the UI tree, making tests more maintainable and readable.

This is particularly important for financial components where accurate testing is critical.

suite-native/app/e2e/tests/deeplinkPopup.test.ts (2)

9-9: Import refactored to use the new class name.

The import has been updated from onCoinEnablingInit to onCoinEnabling to reflect the class renaming in the coin enabling actions page object.


65-67: Method names updated for clarity and consistency.

The method calls have been updated to match the refactored implementation:

  • waitForScreen()waitForInitScreen() - more clearly indicates this is for the initialization screen
  • enableNetwork()toggleNetwork() - better reflects the toggle functionality

These changes align with the class renaming from OnCoinEnablingInit to OnCoinEnabling.

suite-native/app/e2e/tests/receive.test.ts (2)

7-7: Import updated to use refactored coin enabling class.

The import has been updated from onCoinEnablingInit to onCoinEnabling to match the renamed class in the page objects.


20-22: Method calls updated to match the refactored implementation.

The method calls have been updated to match the refactored coin enabling page object:

  • waitForScreen()waitForInitScreen() - provides more specific naming
  • enableNetwork()toggleNetwork() - better describes the action being performed

These changes are part of the broader refactoring effort to standardize test interactions.

suite-native/app/e2e/tests/deviceSettings.test.ts (2)

5-5: Import statement updated to use refactored page object.

The import has been updated from onCoinEnablingInit to onCoinEnabling to reflect the refactored class name.


26-28: Method calls updated to match the refactored page object implementation.

The method calls have been updated for consistency with the refactored coin enabling page object:

  • waitForScreen()waitForInitScreen() - more descriptive of the specific screen
  • enableNetwork()toggleNetwork() - better reflects the toggle functionality

This consistency across test files improves maintainability.

suite-native/app/e2e/tests/passphraseFlow.test.ts (2)

8-8: Import statement updated to use refactored coin enabling class.

The import has been updated from onCoinEnablingInit to onCoinEnabling to reflect the renamed class.


77-79: Method calls updated to align with refactored implementation.

The method calls have been updated to match the refactored coin enabling page object:

  • waitForScreen()waitForInitScreen() - more specific naming
  • enableNetwork()toggleNetwork() - better reflects the action's purpose

These changes are consistent with the updates in other test files, ensuring uniformity across the test suite.

suite-native/atoms/src/Select/SelectTrigger.tsx (3)

15-15: Good addition of testID property.

Adding the optional testID property to SelectTriggerProps enables better component testability in automated testing.


36-36: Function signature properly updated.

The function signature has been correctly updated to include the new testID parameter in the destructured props.


40-40: TestID properly applied to TouchableOpacity.

The testID is correctly passed to the TouchableOpacity component, making it identifiable in end-to-end tests.

suite-native/app/e2e/pageObjects/homeActions.ts (3)

3-5: Good element selector definition.

The constant graphHeaderDiscreetTextElement is well-defined and reusable, following proper Detox patterns for element selection with descendants.


21-23: Well-implemented discreet mode assertion.

The method correctly checks that discreet mode is disabled by verifying the discreet text element is not visible, with an appropriate timeout.


25-27: Good implementation of discreet mode enabled assertion.

The method correctly verifies that discreet mode is enabled by checking for the visibility of the discreet text element, maintaining consistency with the disabled check.

suite-native/app/e2e/pageObjects/accountImportActions.ts (1)

28-33: Improved element handling.

Good refactoring to create a reusable element variable instead of duplicating the element selector. This approach is more maintainable and follows better practices for Detox testing.

suite-native/app/e2e/tests/send.test.ts (2)

6-6: Updated import for renamed module.

Import statement correctly updated to use the renamed module onCoinEnabling instead of onCoinEnablingInit.


80-82: Updated method calls for refactored API.

Method calls have been properly updated to match the refactored API:

  1. waitForScreen()waitForInitScreen()
  2. enableNetwork('regtest')toggleNetwork('regtest')
  3. Using the new onCoinEnabling object

These changes align with the broader refactoring of coin enabling functionality in the codebase.

suite-native/atoms/src/DiscreetText/DiscreetTextTrigger.tsx (3)

6-6: Props interface enhancement for testability

Adding the optional testID property to DiscreetTextTriggerProps is a good approach for improving the component's testability in E2E tests.


8-8: Function signature updated appropriately

The function signature has been updated to correctly destructure the new testID prop from the component props.


15-19: Test identifier correctly applied

The testID prop is properly passed to the Pressable component, allowing it to be targeted in end-to-end tests. This change will help with testing the discreet mode functionality as mentioned in the PR objectives.

suite-native/app/e2e/pageObjects/deviceSettingsActions.ts (2)

3-3: Improved element reference pattern

The change from checkAuthenticityButtonId to checkAuthenticityButtonElement using the element(by.id()) pattern improves consistency with the rest of the file, where other button elements follow the same pattern.


34-34: Consistent element reference usage

The methods have been updated to use the checkAuthenticityButtonElement variable, maintaining the same functionality while improving code consistency. This approach creates a more consistent pattern throughout the test utilities.

Also applies to: 38-39

suite-native/app/e2e/pageObjects/settingsActions.ts (4)

7-35: Well-structured settings navigation methods

The new SettingsActions class provides essential methods for navigating to different settings sections. Each method follows a consistent pattern of waiting for an element to be visible and then tapping it, which is a good practice for reliable end-to-end tests.

These methods directly support the PR objectives by enabling tests to navigate to localization, privacy settings (discreet mode), coin enabling, and view-only mode sections.


36-42: Discreet mode toggle implementation

The toggleDiscreetMode method allows tests to interact with the discreet mode toggle, which is one of the specific features mentioned in the PR objectives. The implementation follows the same consistent pattern as other methods in this class.


44-66: Localization settings methods

The methods for changing localization currency and Bitcoin units enable testing of the localization features mentioned in the PR objectives. Both methods follow a similar pattern:

  1. Tap on the selector trigger
  2. Find the desired option
  3. Tap the option

This implementation will allow for comprehensive testing of the localization functionality.


85-86: Properly exported instance

Exporting a singleton instance of the SettingsActions class as onSettings follows the pattern used by other page object files in the codebase, ensuring consistency.

suite-native/formatters/src/components/FiatBalanceFormatter.tsx (3)

12-15: Props interface enhancement for testability

Adding the optional testID property to BalanceFormatterProps type is a good approach for improving the component's testability in E2E tests. The type definition is properly structured with the new property being optional.


23-27: Function signature updated appropriately

The function signature has been updated to correctly destructure the new testID prop from the component props.


40-40: Test identifier correctly applied

The testID prop is properly passed to the Box component, allowing it to be targeted in end-to-end tests. This change will help with testing localization features and potentially discreet mode functionality as mentioned in the PR objectives.

suite-native/app/e2e/tests/appSettings.test.ts (1)

1-84: Well-structured and comprehensive test suite for app settings!

This new test suite provides good coverage for app settings functionality without requiring device interactions. It tests localization settings (both currency and Bitcoin units) and discreet mode, which aligns well with the PR objectives.

Some suggestions for minor improvements:

  1. Consider extracting the repeated timeout value of 10000ms into a constant to make maintenance easier
  2. The assertions rely on specific text values like "0 BTC" which could be brittle if the UI changes
  3. You might want to add a test for the View Only Mode mentioned in the PR objectives

Overall, the tests are well-organized with proper setup/teardown and clear assertions.

suite-native/app/e2e/tests/onboardAndConnect.test.ts (4)

7-7: Import updated to use the renamed page object.

The import has been successfully updated from onCoinEnablingInit to onCoinEnabling to match the refactored class name.


29-31: Simplified screen waiting logic is cleaner.

The refactored code removes platform-specific conditional logic, making the test more consistent and easier to maintain.


33-39: Method names updated to match refactored API.

The changes from waitForScreen() to waitForInitScreen() and enableNetwork() to toggleNetwork() make the API more descriptive and better reflect the actual functionality.


40-42: Streamlined assertions with no platform dependency.

Removing the platform-specific condition for the assertion makes the test more maintainable and consistent across platforms.

suite-native/app/e2e/pageObjects/coinEnablingActions.ts (3)

3-8: Class and method names refactored for clarity and consistency.

Renaming the class from OnCoinEnablingInit to OnCoinEnabling and the method from waitForScreen to waitForInitScreen makes the API more descriptive and better reflects its specific functionality.


10-14: Method renamed and implementation improved.

The method has been appropriately renamed from enableNetwork to toggleNetwork which better reflects its functionality - toggling rather than just enabling. The implementation has also been improved by directly using the element reference rather than creating an intermediate matcher.


21-21: Updated export to match the new class name.

The export has been correctly updated to reflect the new class name.

suite-native/app/e2e/utils.ts (3)

18-18: Improved constant naming and visibility.

Renaming TREZOR_DEVICE_LABEL to TREZOR_E2E_DEVICE_LABEL clarifies that this label is specifically for E2E testing. Making it exported also increases its reusability across the codebase.


81-95: Enhanced flexibility in the scrollUntilVisible function.

The function has been improved in several ways:

  1. Parameter changed from Detox.NativeMatcher to Detox.IndexableNativeElement for more direct usage
  2. Added optional scrollViewTestId parameter with a sensible default value
  3. Updated implementation to use the element parameter directly
  4. More consistent with how elements are handled throughout the codebase

These changes make the function more flexible and easier to use in different contexts.


114-114: Updated constant usage for consistency.

The code now uses the renamed TREZOR_E2E_DEVICE_LABEL constant, maintaining consistency with the earlier change.

suite-native/app/e2e/tests/appSettingsWithDevice.test.ts (3)

1-19: Well-structured imports and organized dependencies

The imports are well-organized, correctly separated by source (detox, common utilities, page objects, and local utilities). This makes the file structure clear and maintainable.


20-23: Appropriate platform-specific test isolation

Using conditionalDescribe to run these tests only on Android is a good approach since some test actions (like device.pressBack()) are platform-specific.


24-35: Comprehensive test setup with appropriate validation

The setup logic appropriately initializes the environment, skips onboarding, and verifies initial state. The baseline check that Ethereum is not enabled initially (line 34) is particularly good as it establishes a clear starting point for the tests.

@PeKne PeKne self-assigned this Mar 10, 2025
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

🧹 Nitpick comments (6)
suite-native/app/e2e/tests/appSettings.test.ts (3)

34-50: Consider extracting the timeout value to a constant

The hardcoded timeout value of 10000ms is used in multiple places throughout the tests. Extracting this to a named constant would improve maintainability and make it easier to adjust all timeouts at once if needed.

+const DEFAULT_ELEMENT_TIMEOUT = 10000;

 it('Localization - Currency', async () => {
     await waitFor(
         element(by.id('@home/portfolio/fiat-balance-header').withDescendant(by.text('$'))),
     )
         .toBeVisible()
-        .withTimeout(10000);
+        .withTimeout(DEFAULT_ELEMENT_TIMEOUT);

     await onTabBar.navigateToSettings();
     await onSettings.tapLocalization();
     await onSettings.changeLocalizationCurrency('czk');
     await device.pressBack();
     await device.pressBack();

     await waitFor(
         element(by.id('@home/portfolio/fiat-balance-header').withDescendant(by.text('CZK'))),
     )
         .toBeVisible()
-        .withTimeout(10000);
+        .withTimeout(DEFAULT_ELEMENT_TIMEOUT);
 });

42-42: Consider using constants for currency codes

Using string literals like 'czk' directly in the code makes it harder to maintain. Consider creating an enum or constant object for currency codes to improve type safety and readability.

+// At the top of the file or in a separate constants file
+enum Currency {
+  CZK = 'czk',
+  USD = 'usd',
+  // Add other currencies as needed
+}

// Then in the test:
-await onSettings.changeLocalizationCurrency('czk');
+await onSettings.changeLocalizationCurrency(Currency.CZK);

69-83: Add a comment explaining the discreet mode toggle behavior

The test toggles discreet mode on by tapping the balance header, but toggles it off through settings. It would be helpful to add a comment explaining if this asymmetric approach is intentional and why both methods need to be tested.

 it('Privacy & Security - Discreet Mode', async () => {
+    // Verify discreet mode is initially disabled
     await onHome.assertIsDiscreetModeDisabled();

+    // Toggle discreet mode ON by tapping the balance header (shortcut method)
     await element(by.id('@home/portfolio/fiat-balance-header')).tap();

     await onHome.assertIsDiscreetModeEnabled();

+    // Toggle discreet mode OFF through settings (explicit method)
     await onTabBar.navigateToSettings();
     await onSettings.tapPrivacyAndSecurity();
     await onSettings.toggleDiscreetMode();
     await device.pressBack();
     await device.pressBack();

     await onHome.assertIsDiscreetModeDisabled();
 });
suite-native/app/e2e/tests/appSettingsWithDevice.test.ts (3)

40-40: Extract hardcoded wait time to a named constant

The hardcoded wait of 5000ms would be better as a named constant that explains why this specific delay is needed.

+const TREZOR_DEVICE_CONNECTION_DELAY = 5000; // Time needed for Trezor device to start communicating with the app

 beforeEach(async () => {
     await restartApp();
     await appIsFullyLoaded();
-    await wait(5000); // wait for trezor device to start communicating with the app
+    await wait(TREZOR_DEVICE_CONNECTION_DELAY); // wait for trezor device to start communicating with the app
 });

69-121: Add explanatory comments to the View Only Mode test steps

The View Only Mode test has multiple steps and state transitions that would benefit from explanatory comments to clarify the expected behavior and the purpose of each step.

 it('View Only Mode', async () => {
+    // Verify initial state: device should be connected
     await waitFor(
         element(
             by.id('@device-manager/device-switch').withDescendant(by.text('Connected')),
         ),
     )
         .toBeVisible()
         .withTimeout(10000);

+    // Navigate to settings and enable View Only Mode
     await onTabBar.navigateToSettings();
     await onSettings.tapViewOnly();
     await onSettings.toggleWalletViewOnly();

+    // Simulate device disconnection by stopping the bridge
     await TrezorUserEnvLink.stopBridge();

+    // Verify device shows as disconnected when bridge is stopped
     await waitFor(
         element(
             by.id('@device-manager/device-switch').withDescendant(by.text('Disconnected')),
         ),
     )
         .toBeVisible()
         .withTimeout(10000);

+    // Restart bridge and app to verify reconnection
     await TrezorUserEnvLink.startBridge();
     await restartApp();

+    // Verify device reconnected successfully
     await waitFor(
         element(
             by.id('@device-manager/device-switch').withDescendant(by.text('Connected')),
         ),
     )
         .toBeVisible()
         .withTimeout(10000);

+    // Disable View Only Mode
     await onTabBar.navigateToSettings();
     await onSettings.tapViewOnly();
     await onSettings.toggleWalletViewOnly();

     await device.pressBack();
     await device.pressBack();

+    // Simulate device disconnection again
     await TrezorUserEnvLink.stopBridge();

+    // Verify welcome message is shown instead of connection status
+    // when in standard mode with bridge stopped
     await waitFor(
         element(
             by.id('@device-manager/device-switch').withDescendant(by.text('Hi there!')),
         ),
     )
         .toBeVisible()
         .withTimeout(10000);

+    // Verify Ethereum is not visible when in standard mode without device connection
     await detoxExpect(element(by.text('Ethereum'))).not.toExist();
 });

70-101: Extract timeout values to constants

Similar to the other test file, the timeout value of 10000ms is used multiple times. Consider extracting this to a constant for better maintainability.

+const DEFAULT_ELEMENT_TIMEOUT = 10000;

// Then use it in all waitFor calls
.withTimeout(DEFAULT_ELEMENT_TIMEOUT);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a25cd1d and e8ec5c1.

📒 Files selected for processing (5)
  • suite-native/app/e2e/pageObjects/coinEnablingActions.ts (1 hunks)
  • suite-native/app/e2e/pageObjects/settingsActions.ts (1 hunks)
  • suite-native/app/e2e/pageObjects/tabBarActions.ts (1 hunks)
  • suite-native/app/e2e/tests/appSettings.test.ts (1 hunks)
  • suite-native/app/e2e/tests/appSettingsWithDevice.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • suite-native/app/e2e/pageObjects/tabBarActions.ts
  • suite-native/app/e2e/pageObjects/settingsActions.ts
  • suite-native/app/e2e/pageObjects/coinEnablingActions.ts
🧰 Additional context used
🧬 Code Definitions (2)
suite-native/app/e2e/tests/appSettings.test.ts (5)
suite-native/app/e2e/utils.ts (3) (3)
  • openApp (61:70)
  • restartApp (72:79)
  • appIsFullyLoaded (97:101)
suite-native/app/e2e/pageObjects/homeActions.ts (1) (1)
  • onHome (30:30)
suite-native/app/e2e/pageObjects/accountImportActions.ts (1) (1)
  • onAccountImport (69:69)
suite-native/app/e2e/pageObjects/tabBarActions.ts (1) (1)
  • onTabBar (21:21)
suite-native/app/e2e/pageObjects/settingsActions.ts (1) (1)
  • onSettings (86:86)
suite-native/app/e2e/tests/appSettingsWithDevice.test.ts (4)
suite-native/app/e2e/utils.ts (6) (6)
  • prepareTrezorEmulator (103:120)
  • openApp (61:70)
  • restartApp (72:79)
  • appIsFullyLoaded (97:101)
  • wait (129:131)
  • disconnectTrezorUserEnv (122:127)
suite-native/app/e2e/pageObjects/coinEnablingActions.ts (1) (1)
  • onCoinEnabling (21:21)
suite-native/app/e2e/pageObjects/tabBarActions.ts (1) (1)
  • onTabBar (21:21)
suite-native/app/e2e/pageObjects/settingsActions.ts (1) (1)
  • onSettings (86:86)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: EAS Update
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: prepare_android_test_app
🔇 Additional comments (2)
suite-native/app/e2e/tests/appSettingsWithDevice.test.ts (2)

56-66: Reuse element selectors consistently

Good job defining ethereumTextElement as a variable for reuse. This follows the recommendation from previous reviews to use constants for elements used multiple times.


120-120:

❓ Verification inconclusive

Explain why Ethereum should not be visible

Line 120 checks that Ethereum is not visible, but it's not clear why this is expected. Add a comment explaining this expectation.

Can you verify if Ethereum should be hidden when in standard mode without device connection? Is this behavior documented somewhere in your application requirements?


🏁 Script executed:

#!/bin/bash
# Search for any code that might control the visibility of Ethereum based on connection status
rg -A 10 -B 10 "Ethereum.*visibility|visible.*Ethereum|hide.*Ethereum|Ethereum.*hide" --type ts

Length of output: 97


Action Required: Clarify "Ethereum" Hidden Expectation

The test at line 120 verifies that the "Ethereum" element is not visible. However, our search did not uncover any explicit documentation or code references that explain why Ethereum must be hidden when running in standard mode without a device connection. Please add an inline comment at line 120 (or nearby) in suite-native/app/e2e/tests/appSettingsWithDevice.test.ts that clarifies this expectation—whether it’s based on design requirements or a feature flag controlling UI behavior. Additionally, confirm manually that hiding Ethereum in standard mode without an active device connection is indeed the intended behavior based on the product requirements, and reference the relevant documentation if available.

await disconnectTrezorUserEnv();
});

it('Coin Enabling', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer test to it but not a big deal.

Copy link
Contributor

@yanascz yanascz left a comment

Choose a reason for hiding this comment

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

Nice job! 👏

@PeKne
Copy link
Contributor Author

PeKne commented Mar 19, 2025

/rebase

Copy link

@trezor-ci trezor-ci force-pushed the test/native/settings-e2e branch from e8ec5c1 to 53aaa5d Compare March 19, 2025 09:53
Copy link

🚀 Expo preview is ready!

  • Project → trezor-suite-preview
  • Platforms → android, ios
  • Scheme → trezorsuitelite
  • Runtime Version → 27
  • More info

Learn more about 𝝠 Expo Github Action

@PeKne PeKne merged commit 8f20631 into develop Mar 19, 2025
15 of 16 checks passed
@PeKne PeKne deleted the test/native/settings-e2e branch March 19, 2025 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Suite Lite issues and PRs
Projects
Status: 🤝 Needs QA
Development

Successfully merging this pull request may close these issues.

2 participants