test: add tests for useLiquidity hook and theme store (#760 #762)#782
Merged
Mosas2000 merged 1 commit intoJun 29, 2026
Merged
Conversation
|
@Amas-01 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: test: add tests for useLiquidity hook and theme store
Closes #760
Closes #762
What changed
frontend/src/hooks/useLiquidity.test.tsx(new): 9 tests covering loading state, happy path, aggregation correctness (share calculation, venue name mapping), error states, empty response, and refetch functionalityfrontend/src/stores/themeStore.test.ts(new): 17 tests covering initial state, setMode, toggleMode, setDensity, localStorage persistence, store initialization from persisted values, storage key correctness, animation settings, and resetThemeConventions followed
useLiquidity tests: MSW v2 + renderHook pattern from
useServiceHealth.test.tsxanduseBridgeSummary.test.tsxhttp.get()andHttpResponse.json()(MSW v2.12.14 API)QueryClientProviderwrapper with retry disabled for deterministic testsbeforeAll/afterEach/afterAlllifecycle for MSW server managementwaitForfor async assertionsuseWebSocketto avoid WebSocket setup complexity in teststhemeStore tests: Exact pattern from
notificationStore.test.tsuseThemeStore.getInitialState()+setState(initialState, true)useThemeStore.getState()useThemeStore.getState().actionName()localStorage.clear()+resetStoreState()inbeforeEachlocalStorage.getItem(PERSIST_KEY)await useThemeStore.persist.rehydrate()MSW handler added
URL:
GET /api/v1/assets/:symbol/liquidityResponse shape (used in tests):
{ "symbol": "XLM", "totalLiquidity": 300, "sources": [ { "dex": "StellarX AMM", "totalLiquidity": 200, "bidDepth": 100, "askDepth": 100, "priceLevels": [...] } ], "bestBid": { "price": 1.0 }, "bestAsk": { "price": 1.02 }, "lastUpdated": "2024-01-01T00:00:00Z" }Note: No shared MSW handler file was modified. Handlers are defined per-test using
server.use()following the pattern fromuseServiceHealth.test.tsx.Persistence key tested
themeStore localStorage key:
"bridge-watch-theme"(line 5 ofthemeStore.test.ts, verified in test "persistence key matches the exact key in themeStore.ts")How to verify
npm run test --workspace=frontend -- src/hooks/useLiquidity.test.tsx src/stores/themeStore.test.tsExpected: All 26 tests pass (9 for useLiquidity + 17 for themeStore)
Actual result:
Test coverage summary
useLiquidity.test.tsx (9 tests)
Key aggregation logic tested:
(source.totalLiquidity / totalLiquidity) * 100round7()to 7 decimal placesthemeStore.test.ts (17 tests)
Vacuousness confirmation
useLiquidity (Test 5: "toggleMode switches from light to dark")
Non-vacuous verification:
resolvedMode === "dark"after toggle from "light"Confirmed: The test detects incorrect toggle behavior.
themeStore (Test 10: "store initialises from persisted value")
Non-vacuous verification:
mode: "light", expects rehydrated state to be "light"await useThemeStore.persist.rehydrate())Confirmed: The test detects when persistence rehydration is broken.
CI Checks
✅
npm run test --workspace=frontend— All 26 new tests pass✅ Zero type errors in new test files (pre-existing type errors in other files unrelated)
✅ Zero lint errors in new test files (pre-existing lint errors in other files unrelated)
✅ Both vacuousness checks performed locally and confirmed
✅ No source files modified — only test files added
✅ Branch rebased on latest main