test: add unit tests for themes utility functions (#2718)#2737
test: add unit tests for themes utility functions (#2718)#2737desireddymohithreddy0925 wants to merge 1 commit into
Conversation
GSSoC Label Checklist 🏷️@Umbrella-io — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
Legit-Ox
left a comment
There was a problem hiding this comment.
Logic is correct — all assertions match the source. Two things to fix before merging.
| getThemeDefinition, | ||
| isDarkTheme, | ||
| nextThemeId, | ||
| THEME_OPTIONS, |
There was a problem hiding this comment.
Wrong import path. Other test files in this project use the @/ alias (e.g. @/lib/streak, @/lib/streak-utils). This should be:
import { ... } from '@/lib/themes';'../src/lib/themes' is a relative path that breaks if the test file moves and diverges from the established convention.
|
|
||
| describe('themes utilities', () => { | ||
| describe('Constants', () => { | ||
| it('has exactly 4 entries in THEME_OPTIONS', () => { |
There was a problem hiding this comment.
Fragile length assertion. expect(THEME_OPTIONS).toHaveLength(4) will fail the moment a fifth theme is added — even if the new theme is perfectly valid and all other tests pass. This is testing an incidental implementation detail, not a behavioral contract.
Better approach — assert the known IDs are present rather than the exact count:
it('contains all expected theme IDs', () => {
const ids = THEME_OPTIONS.map((t) => t.id);
expect(ids).toContain('classic-dark');
expect(ids).toContain('modern-light-blue');
expect(ids).toContain('nordic-frost');
expect(ids).toContain('cyberpunk-matrix');
});|
Closing as duplicate. #2774 was selected as the themes test winner for its maintainability (uses loops over THEME_OPTIONS). Thanks for contributing! |
Description
Resolves #2718
This PR adds comprehensive unit testing for the pure utility functions exported from
src/lib/themes.tsusing Vitest. It ensures predictable theme resolution and safeguards the core behavior of the theme selection logic.Changes Made
test/themes.test.ts:isThemeId: Validated parsing behavior for all known theme IDs and appropriately handlednull,undefined, empty, and mis-cased strings.getThemeDefinition: Confirmed it consistently retrieves the correctThemeDefinitionand provides a safe fallback (classic-dark) for unknown identifiers.isDarkTheme: Verified expected boolean resolution for the app's three dark modes (classic-dark,nordic-frost,cyberpunk-matrix) and the single light mode (modern-light-blue).nextThemeId: Assured deterministic cycling through theTHEME_OPTIONSarray, including sequential iteration, list wrap-around, and handling of unknown starting inputs.THEME_OPTIONSmaintains exactly 4 valid entries and thatDEFAULT_THEMEremains pinned toclassic-dark.Acceptance Criteria
isThemeId,getThemeDefinition,isDarkTheme, andnextThemeIdcover all theme variants alongside fallback scenarios.vitest.