Skip to content

Conversation

@transphorm
Copy link
Member

@transphorm transphorm commented Oct 3, 2025

Summary

  • restore the Vitest test scripts and Testing Library dependencies for the mobile SDK demo workspace
  • expand the shared test setup to mock React Native primitives, suppress console noise, and provide SDK helpers
  • add integration, component, screen, and utility suites covering navigation flows, document actions, and formatting helpers

Testing

  • yarn workspace mobile-sdk-demo test

https://chatgpt.com/codex/tasks/task_b_68e05a597d20832d9291d4bad4f256c6

Summary by CodeRabbit

  • Bug Fixes

    • Improved cryptography reliability with safer runtime fallbacks for environments lacking native support.
  • Tests

    • Added comprehensive test suites and mocks covering core flows, screens, components, utilities, and integration scenarios to validate navigation, error handling, and interactions.
  • Chores

    • Shifted build/tooling items to dev dependencies, expanded testing devDependencies, and enhanced test setup and shims for React Native and crypto.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 3, 2025

Walkthrough

Adds test infrastructure and comprehensive test suites across the mobile SDK demo. Extends test setup with React Native DOM shims and SDK mocks. Updates crypto polyfill to prefer shared implementations with runtime fallbacks to Node.js and Web Crypto, and adds a default export. Updates package.json dev dependencies for testing.

Changes

Cohort / File(s) Summary of changes
Dev dependencies
packages/mobile-sdk-demo/package.json
Adds testing-related devDependencies: Testing Library packages, @types/react-dom, react-dom.
Crypto polyfill resolution
packages/mobile-sdk-demo/src/polyfills/cryptoPolyfill.js
Builds an exportedPolyfill selecting shared implementations from @selfxyz/common or falling back to Node.js crypto/Web Crypto; adds CommonJS default export alias. Updates imports to include createHash/createHmac/randomBytes/pbkdf2Sync.
Test setup and global mocks
packages/mobile-sdk-demo/tests/setup.ts
Introduces Vitest/RTL setup, RN-to-DOM shims, AsyncStorage and Keychain in-memory mocks, crypto shims, SVG and media mocks, console suppression, and exposes global sdkMocks.
SDK test mocks
packages/mobile-sdk-demo/tests/mocks/sdk.ts
Adds comprehensive SDK mocks (self client, proving store, utilities) and vi.mock for @selfxyz/mobile-sdk-alpha; exposes sdkMocks and reset helpers.
App integration tests
packages/mobile-sdk-demo/tests/App.test.tsx
Adds end-to-end app flow tests for mounting, navigation, fallback, and refresh error handling with mocked screens and provider.
Component tests
packages/mobile-sdk-demo/tests/components/MenuButton.test.tsx, packages/mobile-sdk-demo/tests/components/ScreenLayout.test.tsx
Adds rendering, accessibility, interaction, and disabled-state tests for UI components.
Screen tests — navigation and UI
packages/mobile-sdk-demo/tests/screens/DocumentCamera.test.tsx, .../DocumentNFCScan.test.tsx, .../QRCodeViewFinder.test.tsx, .../ProofHistory.test.tsx, .../HomeScreen.test.tsx
Adds basic render and back-navigation tests; verifies menu-driven navigation actions in HomeScreen.
Screen tests — data flows
packages/mobile-sdk-demo/tests/screens/DocumentsList.test.tsx, .../GenerateMock.test.tsx, .../RegisterDocument.test.tsx
Adds tests for loading/error/empty states, document CRUD flows, registration lifecycle (start/onComplete/reset), alerts, and validation.
Screen descriptors tests
packages/mobile-sdk-demo/tests/screens/index.test.ts
Verifies descriptor exposure via screenMap, section grouping, and prop generation hooks including navigation and refresh wiring.
Utils tests updates
packages/mobile-sdk-demo/tests/utils/document.test.ts
Updates expectations and wording for document type humanization, data preview formatting, newline normalization, and ID masking rules.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App as Mobile SDK Demo
  participant Polyfill as cryptoPolyfill.js
  participant Common as @selfxyz/common
  participant Node as Node.js crypto
  participant Web as globalThis.crypto

  App->>Polyfill: require("./polyfills/cryptoPolyfill")
  Note over Polyfill: Build exportedPolyfill
  Polyfill->>Common: import {cryptoPolyfill, createHash, createHmac, randomBytes, pbkdf2Sync}
  alt cryptoPolyfill available
    Polyfill-->>App: export cryptoPolyfill
  else fallback path
    Polyfill->>Node: use createHash/createHmac/pbkdf2Sync
    Polyfill->>Web: use getRandomValues for randomBytes (if available)
    Polyfill-->>App: export composed fallback
  end
  Note right of App: Uses module.exports and default alias
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • remicolin

Poem

New tests assemble, a chorus in green,
Mocked chains hum softly in the in-between.
Crypto finds footing—fallbacks in tow,
Screens click and whisper, “ready to go.”
With dom-shimmed dreams and tidy asserts,
The demo now dances in confident bursts.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly conveys that this pull request adds Vitest tests for the mobile SDK demo workspace and follows a clear conventional commit style prefix, which accurately reflects the primary change without unnecessary detail or noise.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/reapply-vitest/jsdom-setup-for-mobile-sdk-demo

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@transphorm transphorm marked this pull request as ready for review October 4, 2025 04:00
@transphorm transphorm changed the title test: restore mobile sdk demo vitest suites test: add mobile sdk demo vitest tests Oct 4, 2025
Copy link
Contributor

@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: 2

🧹 Nitpick comments (5)
packages/mobile-sdk-demo/tests/screens/ProofHistory.test.tsx (1)

16-19: Consider more flexible assertions for mock data.

Hardcoding specific demo bank names (DemoBank, VerifyMe, TravelCheck) creates brittleness. If the mock data structure changes, the test breaks unnecessarily.

Consider refactoring to verify the presence of any proof history items rather than specific names, or verify the data structure without hardcoded strings:

-    expect(screen.getByText('DemoBank')).toBeInTheDocument();
-    expect(screen.getByText('VerifyMe')).toBeInTheDocument();
-    expect(screen.getByText('TravelCheck')).toBeInTheDocument();
+    // Verify at least one proof history item is rendered
+    const historyItems = screen.getAllByRole('listitem'); // adjust selector as needed
+    expect(historyItems.length).toBeGreaterThan(0);
packages/mobile-sdk-demo/tests/screens/HomeScreen.test.tsx (1)

18-31: Consider testing descriptor status and disabled states.

The test verifies rendering of sections and items but doesn't exercise the getStatus or isDisabled logic from descriptors. The HomeScreen implementation uses these to control button states dynamically.

Add a test case for disabled and working states:

it('respects descriptor status and disabled state', () => {
  const context = createContext();
  render(<HomeScreen screenContext={context} />);
  
  // Find a descriptor that uses status/disabled logic
  // Example: if a descriptor is disabled based on context
  const disabledButton = screen.getByRole('button', { name: /some disabled feature/i });
  expect(disabledButton).toBeDisabled();
  
  // Verify working state shows appropriate loading indicator
  const workingButton = screen.getByRole('button', { name: /some working feature/i });
  expect(workingButton).toHaveClass('workingButton'); // adjust assertion as needed
});
packages/mobile-sdk-demo/tests/App.test.tsx (1)

15-15: Module-level mutable state may cause test isolation issues.

The latestContext variable is declared at module scope and mutated by the HomeScreen mock (line 53). If tests run in parallel or don't properly reset this variable, they may observe stale context from previous tests, leading to flaky assertions.

Consider either:

  1. Moving latestContext inside the beforeEach block or each test to ensure isolation, or
  2. Documenting that tests must run serially and always reset latestContext in beforeEach (which you do on line 98).

Since you already reset in beforeEach, this is mitigated for serial execution, but parallel test runs could still be problematic.

packages/mobile-sdk-demo/tests/setup.ts (2)

22-28: calculateContentHash fallback may be inconsistent with actual implementation.

Lines 22-28 provide a fallback for calculateContentHash if not present in the actual module. The fallback creates a SHA-256 hash of the stringified value. If the actual implementation uses a different hashing strategy or serialization format, tests using this fallback could pass while production code fails.

Verify that the actual calculateContentHash in @selfxyz/common uses the same hashing and serialization logic. If the actual implementation is unavailable or differs, document this fallback's limitations and consider whether tests should fail loudly if the real implementation is missing.


361-395: Keychain mock lacks error simulation for testing failure paths.

The keychain mock (lines 363-379) always returns true or false synchronously and uses an in-memory store. While this works for happy-path tests, it doesn't allow simulating failures like keychain access denied, biometric auth failures, or OS-level errors.

Consider adding a mechanism to inject errors into the keychain mock (e.g., a flag or environment variable) to enable testing of error handling paths in code that uses the keychain.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ad00939 and 69bbf32.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (17)
  • packages/mobile-sdk-demo/package.json (2 hunks)
  • packages/mobile-sdk-demo/src/polyfills/cryptoPolyfill.js (1 hunks)
  • packages/mobile-sdk-demo/tests/App.test.tsx (1 hunks)
  • packages/mobile-sdk-demo/tests/components/MenuButton.test.tsx (1 hunks)
  • packages/mobile-sdk-demo/tests/components/ScreenLayout.test.tsx (1 hunks)
  • packages/mobile-sdk-demo/tests/mocks/sdk.ts (1 hunks)
  • packages/mobile-sdk-demo/tests/screens/DocumentCamera.test.tsx (1 hunks)
  • packages/mobile-sdk-demo/tests/screens/DocumentNFCScan.test.tsx (1 hunks)
  • packages/mobile-sdk-demo/tests/screens/DocumentsList.test.tsx (1 hunks)
  • packages/mobile-sdk-demo/tests/screens/GenerateMock.test.tsx (1 hunks)
  • packages/mobile-sdk-demo/tests/screens/HomeScreen.test.tsx (1 hunks)
  • packages/mobile-sdk-demo/tests/screens/ProofHistory.test.tsx (1 hunks)
  • packages/mobile-sdk-demo/tests/screens/QRCodeViewFinder.test.tsx (1 hunks)
  • packages/mobile-sdk-demo/tests/screens/RegisterDocument.test.tsx (1 hunks)
  • packages/mobile-sdk-demo/tests/screens/index.test.ts (1 hunks)
  • packages/mobile-sdk-demo/tests/setup.ts (5 hunks)
  • packages/mobile-sdk-demo/tests/utils/document.test.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{js,ts,tsx,jsx,sol,nr}

📄 CodeRabbit inference engine (.cursorrules)

**/*.{js,ts,tsx,jsx,sol,nr}: NEVER log sensitive data including PII (names, DOB, passport numbers, addresses), credentials, tokens, API keys, private keys, or session identifiers.
ALWAYS redact/mask sensitive fields in logs using consistent patterns (e.g., ***-***-1234 for passport numbers, J*** D*** for names).

Files:

  • packages/mobile-sdk-demo/tests/screens/DocumentNFCScan.test.tsx
  • packages/mobile-sdk-demo/tests/screens/GenerateMock.test.tsx
  • packages/mobile-sdk-demo/tests/mocks/sdk.ts
  • packages/mobile-sdk-demo/tests/screens/DocumentsList.test.tsx
  • packages/mobile-sdk-demo/tests/screens/index.test.ts
  • packages/mobile-sdk-demo/src/polyfills/cryptoPolyfill.js
  • packages/mobile-sdk-demo/tests/components/MenuButton.test.tsx
  • packages/mobile-sdk-demo/tests/utils/document.test.ts
  • packages/mobile-sdk-demo/tests/screens/QRCodeViewFinder.test.tsx
  • packages/mobile-sdk-demo/tests/screens/ProofHistory.test.tsx
  • packages/mobile-sdk-demo/tests/screens/HomeScreen.test.tsx
  • packages/mobile-sdk-demo/tests/App.test.tsx
  • packages/mobile-sdk-demo/tests/screens/DocumentCamera.test.tsx
  • packages/mobile-sdk-demo/tests/components/ScreenLayout.test.tsx
  • packages/mobile-sdk-demo/tests/screens/RegisterDocument.test.tsx
  • packages/mobile-sdk-demo/tests/setup.ts
**/*.{test,spec}.{ts,js,tsx,jsx}

⚙️ CodeRabbit configuration file

**/*.{test,spec}.{ts,js,tsx,jsx}: Review test files for:

  • Test coverage completeness
  • Test case quality and edge cases
  • Mock usage appropriateness
  • Test readability and maintainability

Files:

  • packages/mobile-sdk-demo/tests/screens/DocumentNFCScan.test.tsx
  • packages/mobile-sdk-demo/tests/screens/GenerateMock.test.tsx
  • packages/mobile-sdk-demo/tests/screens/DocumentsList.test.tsx
  • packages/mobile-sdk-demo/tests/screens/index.test.ts
  • packages/mobile-sdk-demo/tests/components/MenuButton.test.tsx
  • packages/mobile-sdk-demo/tests/utils/document.test.ts
  • packages/mobile-sdk-demo/tests/screens/QRCodeViewFinder.test.tsx
  • packages/mobile-sdk-demo/tests/screens/ProofHistory.test.tsx
  • packages/mobile-sdk-demo/tests/screens/HomeScreen.test.tsx
  • packages/mobile-sdk-demo/tests/App.test.tsx
  • packages/mobile-sdk-demo/tests/screens/DocumentCamera.test.tsx
  • packages/mobile-sdk-demo/tests/components/ScreenLayout.test.tsx
  • packages/mobile-sdk-demo/tests/screens/RegisterDocument.test.tsx
🧠 Learnings (15)
📓 Common learnings
Learnt from: CR
PR: selfxyz/self#0
File: .cursor/rules/mobile-sdk-migration.mdc:0-0
Timestamp: 2025-08-24T18:54:04.809Z
Learning: Applies to packages/mobile-sdk-alpha/demo/** : Provide an in-SDK lightweight React Native demo under packages/mobile-sdk-alpha/demo/
Learnt from: CR
PR: selfxyz/self#0
File: packages/mobile-sdk-alpha/AGENTS.md:0-0
Timestamp: 2025-08-29T15:31:15.924Z
Learning: Applies to packages/mobile-sdk-alpha/{**/*.test.{ts,tsx},**/__tests__/**/*.{ts,tsx}} : Use actual imports from selfxyz/mobile-sdk-alpha in tests
Learnt from: CR
PR: selfxyz/self#0
File: packages/mobile-sdk-alpha/AGENTS.md:0-0
Timestamp: 2025-08-29T15:31:15.924Z
Learning: Applies to packages/mobile-sdk-alpha/{**/*.test.{ts,tsx},**/__tests__/**/*.{ts,tsx}} : Write integration tests that exercise the real validation logic (not mocks)
Learnt from: CR
PR: selfxyz/self#0
File: packages/mobile-sdk-alpha/AGENTS.md:0-0
Timestamp: 2025-08-29T15:31:15.924Z
Learning: Applies to packages/mobile-sdk-alpha/{**/*.test.{ts,tsx},**/__tests__/**/*.{ts,tsx}} : Ensure parseNFCResponse() works with representative, synthetic NFC data
Learnt from: CR
PR: selfxyz/self#0
File: .cursor/rules/mobile-sdk-migration.mdc:0-0
Timestamp: 2025-08-24T18:54:04.809Z
Learning: Applies to packages/mobile-sdk-alpha/package.json : Expose a 'test:build' script in the SDK's package.json that runs build, test, types, and lint
Learnt from: CR
PR: selfxyz/self#0
File: .cursor/rules/mobile-sdk-migration.mdc:0-0
Timestamp: 2025-08-24T18:54:04.809Z
Learning: Applies to app/jest.setup.js : Provide comprehensive Jest setup in app/jest.setup.js with required mocks
📚 Learning: 2025-08-29T15:31:15.924Z
Learnt from: CR
PR: selfxyz/self#0
File: packages/mobile-sdk-alpha/AGENTS.md:0-0
Timestamp: 2025-08-29T15:31:15.924Z
Learning: Applies to packages/mobile-sdk-alpha/{**/*.test.{ts,tsx},**/__tests__/**/*.{ts,tsx}} : Ensure parseNFCResponse() works with representative, synthetic NFC data

Applied to files:

  • packages/mobile-sdk-demo/tests/screens/DocumentNFCScan.test.tsx
  • packages/mobile-sdk-demo/tests/setup.ts
📚 Learning: 2025-08-29T15:31:15.924Z
Learnt from: CR
PR: selfxyz/self#0
File: packages/mobile-sdk-alpha/AGENTS.md:0-0
Timestamp: 2025-08-29T15:31:15.924Z
Learning: Applies to packages/mobile-sdk-alpha/{**/*.test.{ts,tsx},**/__tests__/**/*.{ts,tsx}} : Write integration tests that exercise the real validation logic (not mocks)

Applied to files:

  • packages/mobile-sdk-demo/tests/screens/GenerateMock.test.tsx
  • packages/mobile-sdk-demo/tests/mocks/sdk.ts
  • packages/mobile-sdk-demo/tests/screens/index.test.ts
  • packages/mobile-sdk-demo/tests/App.test.tsx
  • packages/mobile-sdk-demo/tests/screens/RegisterDocument.test.tsx
  • packages/mobile-sdk-demo/tests/setup.ts
📚 Learning: 2025-08-29T15:31:15.924Z
Learnt from: CR
PR: selfxyz/self#0
File: packages/mobile-sdk-alpha/AGENTS.md:0-0
Timestamp: 2025-08-29T15:31:15.924Z
Learning: Applies to packages/mobile-sdk-alpha/{**/*.test.{ts,tsx},**/__tests__/**/*.{ts,tsx}} : Do NOT mock selfxyz/mobile-sdk-alpha in tests (avoid jest.mock('selfxyz/mobile-sdk-alpha') and replacing real functions with mocks)

Applied to files:

  • packages/mobile-sdk-demo/tests/screens/GenerateMock.test.tsx
  • packages/mobile-sdk-demo/tests/mocks/sdk.ts
  • packages/mobile-sdk-demo/tests/App.test.tsx
  • packages/mobile-sdk-demo/tests/setup.ts
📚 Learning: 2025-08-29T15:31:15.924Z
Learnt from: CR
PR: selfxyz/self#0
File: packages/mobile-sdk-alpha/AGENTS.md:0-0
Timestamp: 2025-08-29T15:31:15.924Z
Learning: Applies to packages/mobile-sdk-alpha/{**/*.test.{ts,tsx},**/__tests__/**/*.{ts,tsx}} : Test isPassportDataValid() with realistic synthetic passport data (never real user data)

Applied to files:

  • packages/mobile-sdk-demo/tests/screens/GenerateMock.test.tsx
  • packages/mobile-sdk-demo/tests/utils/document.test.ts
  • packages/mobile-sdk-demo/tests/screens/RegisterDocument.test.tsx
📚 Learning: 2025-08-29T15:31:15.924Z
Learnt from: CR
PR: selfxyz/self#0
File: packages/mobile-sdk-alpha/AGENTS.md:0-0
Timestamp: 2025-08-29T15:31:15.924Z
Learning: Applies to packages/mobile-sdk-alpha/{**/*.test.{ts,tsx},**/__tests__/**/*.{ts,tsx}} : Use actual imports from selfxyz/mobile-sdk-alpha in tests

Applied to files:

  • packages/mobile-sdk-demo/tests/mocks/sdk.ts
  • packages/mobile-sdk-demo/tests/screens/index.test.ts
  • packages/mobile-sdk-demo/tests/App.test.tsx
  • packages/mobile-sdk-demo/package.json
  • packages/mobile-sdk-demo/tests/setup.ts
📚 Learning: 2025-08-24T18:54:04.809Z
Learnt from: CR
PR: selfxyz/self#0
File: .cursor/rules/mobile-sdk-migration.mdc:0-0
Timestamp: 2025-08-24T18:54:04.809Z
Learning: Applies to packages/mobile-sdk-alpha/src/index.ts : Re-export new SDK modules via packages/mobile-sdk-alpha/src/index.ts

Applied to files:

  • packages/mobile-sdk-demo/tests/mocks/sdk.ts
📚 Learning: 2025-08-29T15:31:15.924Z
Learnt from: CR
PR: selfxyz/self#0
File: packages/mobile-sdk-alpha/AGENTS.md:0-0
Timestamp: 2025-08-29T15:31:15.924Z
Learning: Applies to packages/mobile-sdk-alpha/{**/*.test.{ts,tsx},**/__tests__/**/*.{ts,tsx}} : Verify extractMRZInfo() using published sample MRZ strings (e.g., ICAO examples)

Applied to files:

  • packages/mobile-sdk-demo/tests/utils/document.test.ts
  • packages/mobile-sdk-demo/tests/screens/QRCodeViewFinder.test.tsx
  • packages/mobile-sdk-demo/tests/screens/DocumentCamera.test.tsx
📚 Learning: 2025-08-26T14:49:11.190Z
Learnt from: shazarre
PR: selfxyz/self#936
File: app/src/screens/passport/PassportNFCScanScreen.tsx:28-31
Timestamp: 2025-08-26T14:49:11.190Z
Learning: The main App.tsx file is located at app/App.tsx (not in app/src), and it properly wraps the entire app with SelfClientProvider at the top of the provider hierarchy, enabling useSelfClient() hook usage throughout all navigation screens.

Applied to files:

  • packages/mobile-sdk-demo/tests/App.test.tsx
📚 Learning: 2025-08-24T18:54:04.809Z
Learnt from: CR
PR: selfxyz/self#0
File: .cursor/rules/mobile-sdk-migration.mdc:0-0
Timestamp: 2025-08-24T18:54:04.809Z
Learning: Applies to packages/mobile-sdk-alpha/demo/** : Provide an in-SDK lightweight React Native demo under packages/mobile-sdk-alpha/demo/

Applied to files:

  • packages/mobile-sdk-demo/package.json
  • packages/mobile-sdk-demo/tests/setup.ts
📚 Learning: 2025-08-24T18:54:04.809Z
Learnt from: CR
PR: selfxyz/self#0
File: .cursor/rules/mobile-sdk-migration.mdc:0-0
Timestamp: 2025-08-24T18:54:04.809Z
Learning: Applies to packages/mobile-sdk-alpha/tests/setup.ts : Provide Vitest setup file at packages/mobile-sdk-alpha/tests/setup.ts to suppress console noise

Applied to files:

  • packages/mobile-sdk-demo/tests/setup.ts
📚 Learning: 2025-08-24T18:54:04.809Z
Learnt from: CR
PR: selfxyz/self#0
File: .cursor/rules/mobile-sdk-migration.mdc:0-0
Timestamp: 2025-08-24T18:54:04.809Z
Learning: Applies to app/jest.setup.js : Provide comprehensive Jest setup in app/jest.setup.js with required mocks

Applied to files:

  • packages/mobile-sdk-demo/tests/setup.ts
📚 Learning: 2025-08-29T15:31:15.924Z
Learnt from: CR
PR: selfxyz/self#0
File: packages/mobile-sdk-alpha/AGENTS.md:0-0
Timestamp: 2025-08-29T15:31:15.924Z
Learning: Applies to packages/mobile-sdk-alpha/{**/*.test.{ts,tsx},**/__tests__/**/*.{ts,tsx}} : Never use real user PII in tests; use only synthetic, anonymized, or approved test vectors

Applied to files:

  • packages/mobile-sdk-demo/tests/setup.ts
📚 Learning: 2025-08-24T18:54:04.809Z
Learnt from: CR
PR: selfxyz/self#0
File: .cursor/rules/mobile-sdk-migration.mdc:0-0
Timestamp: 2025-08-24T18:54:04.809Z
Learning: Applies to packages/mobile-sdk-alpha/vitest.config.ts : Use Vitest in the SDK with a Node environment configured in packages/mobile-sdk-alpha/vitest.config.ts

Applied to files:

  • packages/mobile-sdk-demo/tests/setup.ts
📚 Learning: 2025-09-22T11:10:22.019Z
Learnt from: CR
PR: selfxyz/self#0
File: .cursorrules:0-0
Timestamp: 2025-09-22T11:10:22.019Z
Learning: Applies to jest.setup.js : Comprehensive mocks for all native modules must be set up in `jest.setup.js`.

Applied to files:

  • packages/mobile-sdk-demo/tests/setup.ts
🧬 Code graph analysis (14)
packages/mobile-sdk-demo/tests/screens/DocumentNFCScan.test.tsx (1)
packages/mobile-sdk-demo/src/screens/DocumentNFCScan.tsx (1)
  • DocumentNFCScan (13-28)
packages/mobile-sdk-demo/tests/screens/GenerateMock.test.tsx (2)
packages/mobile-sdk-demo/tests/mocks/sdk.ts (1)
  • sdkMocks (72-96)
packages/mobile-sdk-demo/src/screens/GenerateMock.tsx (1)
  • GenerateMock (34-211)
packages/mobile-sdk-demo/tests/mocks/sdk.ts (1)
packages/mobile-sdk-alpha/src/proving/provingMachine.ts (1)
  • useProvingStore (382-1532)
packages/mobile-sdk-demo/tests/screens/DocumentsList.test.tsx (2)
packages/mobile-sdk-demo/tests/mocks/sdk.ts (1)
  • sdkMocks (72-96)
packages/mobile-sdk-demo/src/screens/DocumentsList.tsx (1)
  • DocumentsList (24-192)
packages/mobile-sdk-demo/tests/screens/index.test.ts (1)
packages/mobile-sdk-demo/src/screens/index.ts (4)
  • ScreenContext (11-17)
  • screenDescriptors (35-92)
  • screenMap (94-100)
  • orderedSectionEntries (102-115)
packages/mobile-sdk-demo/tests/components/MenuButton.test.tsx (1)
packages/mobile-sdk-demo/src/components/MenuButton.tsx (1)
  • MenuButton (16-53)
packages/mobile-sdk-demo/tests/utils/document.test.ts (1)
packages/mobile-sdk-demo/src/utils/document.ts (3)
  • humanizeDocumentType (7-16)
  • formatDataPreview (18-31)
  • maskId (33-40)
packages/mobile-sdk-demo/tests/screens/QRCodeViewFinder.test.tsx (1)
packages/mobile-sdk-demo/src/screens/QRCodeViewFinder.tsx (1)
  • QRCodeViewFinder (13-28)
packages/mobile-sdk-demo/tests/screens/HomeScreen.test.tsx (2)
packages/mobile-sdk-demo/src/screens/index.ts (2)
  • ScreenContext (11-17)
  • orderedSectionEntries (102-115)
packages/mobile-sdk-demo/src/screens/HomeScreen.tsx (1)
  • HomeScreen (17-53)
packages/mobile-sdk-demo/tests/App.test.tsx (3)
packages/mobile-sdk-demo/src/screens/index.ts (3)
  • ScreenContext (11-17)
  • screenMap (94-100)
  • orderedSectionEntries (102-115)
packages/mobile-sdk-demo/src/screens/HomeScreen.tsx (1)
  • HomeScreen (17-53)
packages/mobile-sdk-demo/tests/mocks/sdk.ts (1)
  • sdkMocks (72-96)
packages/mobile-sdk-demo/tests/screens/DocumentCamera.test.tsx (1)
packages/mobile-sdk-demo/src/screens/DocumentCamera.tsx (1)
  • DocumentCamera (13-27)
packages/mobile-sdk-demo/tests/components/ScreenLayout.test.tsx (1)
packages/mobile-sdk-demo/src/components/ScreenLayout.tsx (1)
  • ScreenLayout (19-26)
packages/mobile-sdk-demo/tests/screens/RegisterDocument.test.tsx (2)
packages/mobile-sdk-demo/tests/mocks/sdk.ts (1)
  • sdkMocks (72-96)
packages/mobile-sdk-demo/src/screens/RegisterDocument.tsx (1)
  • RegisterDocument (25-254)
packages/mobile-sdk-demo/tests/setup.ts (4)
packages/mobile-sdk-demo/src/polyfills/cryptoPolyfill.js (1)
  • nodeCrypto (14-14)
common/index.ts (1)
  • calculateContentHash (68-68)
packages/mobile-sdk-demo/tests/mocks/sdk.ts (1)
  • sdkMocks (72-96)
app/src/mocks/react-native-safe-area-context.js (1)
  • SafeAreaView (21-23)
⏰ Context from checks skipped due to timeout of 300000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: type-check
🔇 Additional comments (26)
packages/mobile-sdk-demo/tests/screens/QRCodeViewFinder.test.tsx (1)

8-22: LGTM - Basic interaction test is solid.

The test correctly verifies UI text presence and back navigation behavior. The component being tested is a PlaceholderScreen with static content, so comprehensive coverage for this screen's current implementation is appropriate.

packages/mobile-sdk-demo/tests/screens/DocumentNFCScan.test.tsx (1)

8-22: LGTM - Adequate coverage for placeholder screen.

The test appropriately validates the placeholder UI and navigation. When NFC scanning functionality is implemented, expand tests to include synthetic NFC data validation per learnings guidance on parseNFCResponse().

Based on learnings about NFC response parsing with representative data.

packages/mobile-sdk-demo/tests/components/ScreenLayout.test.tsx (1)

8-33: LGTM - Core functionality well tested.

The tests appropriately verify title rendering, children composition, right action display, and back navigation. The contentStyle prop is not exercised but is a styling concern with lower test priority.

packages/mobile-sdk-demo/tests/screens/DocumentCamera.test.tsx (1)

8-21: LGTM - Placeholder test is appropriate.

Current test coverage is suitable for the placeholder implementation. When camera and MRZ detection are implemented, expand tests to verify extractMRZInfo() using published ICAO sample MRZ strings per learnings guidance.

Based on learnings about MRZ validation with ICAO examples.

packages/mobile-sdk-demo/tests/components/MenuButton.test.tsx (1)

8-35: LGTM - Solid component interaction coverage.

The tests appropriately verify rendering, enabled interaction, and disabled state handling. The component's accessibility roles are properly tested.

packages/mobile-sdk-demo/package.json (1)

55-58: Verify peer dependencies and test suite under Yarn 4.6.0
Run yarn install and yarn test using the project’s declared Yarn version (4.6.0) to confirm there are no peer-dependency warnings or runtime test failures.

packages/mobile-sdk-demo/tests/App.test.tsx (7)

8-11: LGTM on provider mock.

Mocking SelfClientProvider to pass through children is appropriate for this integration test, as it isolates navigation and UI flows from the provider's internal logic.


16-82: LGTM on test screen descriptors and HomeScreen mock.

The createScreensModule factory provides minimal, focused test doubles for the screens module. The descriptors and HomeScreen mock are clear and support the navigation assertions without overcomplicating the setup.


84-92: Verify that mocking screens module doesn't violate learnings.

The learnings state: "Use actual imports from selfxyz/mobile-sdk-alpha in tests" and "Do NOT mock selfxyz/mobile-sdk-alpha in tests." While this mock targets ../src/screens (not the SDK itself), ensure that the real screen implementations under ../src/screens don't exercise SDK validation logic that should be tested with actual imports per the learnings.

If the real screens import and use SDK functions (e.g., validation logic), consider whether some tests should use the actual screen modules to exercise that logic, as indicated by the learning: "Write integration tests that exercise the real validation logic (not mocks)."


101-125: LGTM on mount behavior test.

This test verifies that the app loads document catalog and selected document on mount, checks for the app title, and asserts the context state. The assertions are clear and appropriate for an integration test.


127-147: LGTM on navigation test.

This test exercises navigation from the home menu into descriptor screens and back, verifying that the correct screens render. The use of userEvent and waitFor is appropriate for simulating user interaction and async state updates.


149-168: LGTM on fallback navigation test.

This test confirms that navigating to an unknown route falls back to the home screen, demonstrating resilient routing behavior. The assertions correctly verify the fallback.


170-197: LGTM on error handling test.

This test simulates catalog and selection load failures, triggers refreshDocuments, and verifies that the context resets to an empty catalog and null selection. This is a good edge case for error recovery.

packages/mobile-sdk-demo/tests/setup.ts (13)

53-56: LGTM on console suppression.

Suppressing console output in tests unless DEBUG_TESTS=true is a good practice for reducing noise. The restore mechanism on lines 59-64 provides an escape hatch for debugging.


59-65: Exposing sdkMocks globally is a pragmatic choice.

Lines 59-65 expose restoreConsole and sdkMocks on globalThis for debugging and test reuse. While this pollutes the global namespace, it's a reasonable trade-off for test ergonomics. Ensure that tests don't accidentally mutate sdkMocks state without resetting it.


68-83: LGTM on flattenStyle utility.

The flattenStyle function correctly handles arrays, style tokens, and objects, matching React Native's StyleSheet.flatten behavior for DOM testing. This is a clean, functional implementation.


85-241: Comprehensive React Native DOM shims are well-implemented.

The DOM component mocks (TouchableOpacity, ScrollView, Pressable, TextInput, Switch, Button, Modal, SafeAreaView, FlatList, ActivityIndicator) provide good coverage of RN primitives for testing. The use of createElement with appropriate props and event handlers ensures compatibility with Testing Library queries.


244-247: LGTM on beforeEach reset.

Resetting sdkMocks and alertSpy in beforeEach ensures test isolation. This pairs well with the module-level latestContext reset in App.test.tsx.


249-312: LGTM on react-native module mock.

The mock provides comprehensive coverage of Platform, Dimensions, NativeModules, StyleSheet, and core components. The use of the flattenStyle utility for StyleSheet.flatten is consistent and correct.


314-322: LGTM on safe-area-context mock.

The mock provides a minimal SafeAreaProvider, SafeAreaView, and useSafeAreaInsets hook with zero insets, which is appropriate for unit/integration tests that don't depend on actual safe area calculations.


324-329: LGTM on vector icons mock.

The mock renders icon names as text in a <span>, which is sufficient for verifying icon presence without requiring actual icon fonts or SVGs.


332-358: LGTM on AsyncStorage mock.

The in-memory AsyncStorage mock provides a complete API surface (setItem, getItem, removeItem, clear, getAllKeys, multiGet, multiSet, multiRemove) with Vitest spies for verification. This is a solid test double for storage interactions.


398-401: LGTM on react-native-get-random-values mock.

Mocking polyfillGlobal as a no-op is appropriate for tests, as randomness should be deterministic or controlled via other means (e.g., seeded RNG if needed).


403-407: LGTM on SVG asset mock.

Mocking the logo SVG as a simple <svg> element with a testid is sufficient for tests that verify its presence without needing actual SVG rendering.


409-424: LGTM on window.matchMedia shim.

The shim provides a minimal matchMedia implementation for libraries that depend on it (e.g., responsive utilities). The mock always returns matches: false, which is reasonable for most test scenarios.


11-36: No changes needed for crypto polyfill binding. setup.ts’s .bind(nodeCrypto) calls are harmless and aren’t directly exercised by any @selfxyz/common mock in your tests; the dedicated cryptoPolyfill.js tests already validate proper binding.

@transphorm transphorm merged commit 0d3439f into dev Oct 4, 2025
23 checks passed
@transphorm transphorm deleted the codex/reapply-vitest/jsdom-setup-for-mobile-sdk-demo branch October 4, 2025 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants