-
Notifications
You must be signed in to change notification settings - Fork 180
test: add mobile sdk demo vitest tests #1203
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: add mobile sdk demo vitest tests #1203
Conversation
WalkthroughAdds 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
…f github.com:selfxyz/self into codex/reapply-vitest/jsdom-setup-for-mobile-sdk-demo
There was a problem hiding this 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
getStatusorisDisabledlogic 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
latestContextvariable 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:
- Moving
latestContextinside thebeforeEachblock or each test to ensure isolation, or- Documenting that tests must run serially and always reset
latestContextinbeforeEach(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
calculateContentHashif 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
calculateContentHashin@selfxyz/commonuses 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
trueorfalsesynchronously 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
⛔ Files ignored due to path filters (1)
yarn.lockis 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.,***-***-1234for passport numbers,J*** D***for names).
Files:
packages/mobile-sdk-demo/tests/screens/DocumentNFCScan.test.tsxpackages/mobile-sdk-demo/tests/screens/GenerateMock.test.tsxpackages/mobile-sdk-demo/tests/mocks/sdk.tspackages/mobile-sdk-demo/tests/screens/DocumentsList.test.tsxpackages/mobile-sdk-demo/tests/screens/index.test.tspackages/mobile-sdk-demo/src/polyfills/cryptoPolyfill.jspackages/mobile-sdk-demo/tests/components/MenuButton.test.tsxpackages/mobile-sdk-demo/tests/utils/document.test.tspackages/mobile-sdk-demo/tests/screens/QRCodeViewFinder.test.tsxpackages/mobile-sdk-demo/tests/screens/ProofHistory.test.tsxpackages/mobile-sdk-demo/tests/screens/HomeScreen.test.tsxpackages/mobile-sdk-demo/tests/App.test.tsxpackages/mobile-sdk-demo/tests/screens/DocumentCamera.test.tsxpackages/mobile-sdk-demo/tests/components/ScreenLayout.test.tsxpackages/mobile-sdk-demo/tests/screens/RegisterDocument.test.tsxpackages/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.tsxpackages/mobile-sdk-demo/tests/screens/GenerateMock.test.tsxpackages/mobile-sdk-demo/tests/screens/DocumentsList.test.tsxpackages/mobile-sdk-demo/tests/screens/index.test.tspackages/mobile-sdk-demo/tests/components/MenuButton.test.tsxpackages/mobile-sdk-demo/tests/utils/document.test.tspackages/mobile-sdk-demo/tests/screens/QRCodeViewFinder.test.tsxpackages/mobile-sdk-demo/tests/screens/ProofHistory.test.tsxpackages/mobile-sdk-demo/tests/screens/HomeScreen.test.tsxpackages/mobile-sdk-demo/tests/App.test.tsxpackages/mobile-sdk-demo/tests/screens/DocumentCamera.test.tsxpackages/mobile-sdk-demo/tests/components/ScreenLayout.test.tsxpackages/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.tsxpackages/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.tsxpackages/mobile-sdk-demo/tests/mocks/sdk.tspackages/mobile-sdk-demo/tests/screens/index.test.tspackages/mobile-sdk-demo/tests/App.test.tsxpackages/mobile-sdk-demo/tests/screens/RegisterDocument.test.tsxpackages/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.tsxpackages/mobile-sdk-demo/tests/mocks/sdk.tspackages/mobile-sdk-demo/tests/App.test.tsxpackages/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.tsxpackages/mobile-sdk-demo/tests/utils/document.test.tspackages/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.tspackages/mobile-sdk-demo/tests/screens/index.test.tspackages/mobile-sdk-demo/tests/App.test.tsxpackages/mobile-sdk-demo/package.jsonpackages/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.tspackages/mobile-sdk-demo/tests/screens/QRCodeViewFinder.test.tsxpackages/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.jsonpackages/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
contentStyleprop 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
Runyarn installandyarn testusing 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
SelfClientProviderto 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
createScreensModulefactory 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/screensdon'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
userEventandwaitForis 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=trueis 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
restoreConsoleandsdkMocksonglobalThisfor 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 mutatesdkMocksstate without resetting it.
68-83: LGTM on flattenStyle utility.The
flattenStylefunction 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
createElementwith appropriate props and event handlers ensures compatibility with Testing Library queries.
244-247: LGTM on beforeEach reset.Resetting
sdkMocksandalertSpyinbeforeEachensures test isolation. This pairs well with the module-levellatestContextreset 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
flattenStyleutility forStyleSheet.flattenis 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
polyfillGlobalas 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.
Summary
Testing
https://chatgpt.com/codex/tasks/task_b_68e05a597d20832d9291d4bad4f256c6
Summary by CodeRabbit
Bug Fixes
Tests
Chores