test(settings): cover theme application effect and system media-query sync#471
Merged
Baskarayelu merged 1 commit intoJun 29, 2026
Merged
Conversation
… sync Asserts data-theme for light/dark/system, OS-theme-change flips, and listener cleanup, locking down the dark-mode glue. New test file: src/context/SettingsContext.theme.test.tsx - Explicit light mode: data-theme="light" set on mount, no listener attached - Explicit dark mode: data-theme="dark" set on mount, no listener attached - System mode (initial mount): resolves OS preference to light or dark - System + OS change flip: dark→light, light→dark, and multi-flip tracking - Listener cleanup: removed on mode change (same fn reference verified) and on unmount; no response to OS changes after leaving system mode; listener re-attached when switching back to system - Persistence: setThemeMode() updates both data-theme attribute and the credence:settings localStorage payload simultaneously - Double mount / Strict Mode: data-theme consistent across rerenders; listener count does not grow unboundedly A custom createMatchMediaMock helper tracks add/removeEventListener calls and exposes a simulateChange() method so OS theme transitions are deterministic. Closes CredenceOrg#448
|
@samjay8 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! 🚀 |
4 tasks
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.
Closes #448
Summary
Adds a focused Vitest + RTL suite in
src/context/SettingsContext.theme.test.tsxthat directly asserts thedata-themeattribute and matchMedia listener lifecycle - locking down the dark-mode glue between settings state and CSS tokens.What is tested
Explicit modes
themeMode="light"setsdata-theme="light"on mount, no listener attachedthemeMode="dark"setsdata-theme="dark"on mount, no listener attachedSystem mode
data-theme="light"on mountdata-theme="dark"on mountchangeevent in system modeOS theme-change flip
data-theme="dark"; light flip ?data-theme="light"; multi-flip trackingListener cleanup
Persistence
setThemeMode()updates bothdata-themeattribute and thecredence:settingslocalStorage payload simultaneously for all three modesStrict Mode resilience
data-themeconsistent across rerender cyclesMock approach
A custom
createMatchMediaMock()helper tracksadd/removeEventListenercalls and exposessimulateChange()for deterministic OS theme transitions - no global jsdom patching required.Test plan
npm run testpasses (all new assertions green)npm run lintpassesnpm run buildpasses