Skip to content

test: add unit tests for themes utility functions (#2718)#2737

Closed
desireddymohithreddy0925 wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
desireddymohithreddy0925:test/themes-2718
Closed

test: add unit tests for themes utility functions (#2718)#2737
desireddymohithreddy0925 wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
desireddymohithreddy0925:test/themes-2718

Conversation

@desireddymohithreddy0925

Copy link
Copy Markdown
Contributor

Description

Resolves #2718

This PR adds comprehensive unit testing for the pure utility functions exported from src/lib/themes.ts using Vitest. It ensures predictable theme resolution and safeguards the core behavior of the theme selection logic.

Changes Made

  • Created test/themes.test.ts:
    • isThemeId: Validated parsing behavior for all known theme IDs and appropriately handled null, undefined, empty, and mis-cased strings.
    • getThemeDefinition: Confirmed it consistently retrieves the correct ThemeDefinition and 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 the THEME_OPTIONS array, including sequential iteration, list wrap-around, and handling of unknown starting inputs.
    • Constants Validation: Assured THEME_OPTIONS maintains exactly 4 valid entries and that DEFAULT_THEME remains pinned to classic-dark.

Acceptance Criteria

  • Unit tests for isThemeId, getThemeDefinition, isDarkTheme, and nextThemeId cover all theme variants alongside fallback scenarios.
  • Core module constants are asserted correctly, providing documentation-through-tests.
  • The module now achieves 100% test coverage.
  • All 12 tests run successfully and deterministically with vitest.

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:design GSSoC type bonus: UI/design (+10 pts) type:feature GSSoC type bonus: new feature type:testing GSSoC type bonus: tests (+10 pts) and removed gssoc26 GSSoC 2026 contribution type:feature GSSoC type bonus: new feature type:design GSSoC type bonus: UI/design (+10 pts) labels Jun 23, 2026
@github-actions

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Umbrella-io — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

@Legit-Ox Legit-Ox left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic is correct — all assertions match the source. Two things to fix before merging.

Comment thread test/themes.test.ts
getThemeDefinition,
isDarkTheme,
nextThemeId,
THEME_OPTIONS,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread test/themes.test.ts

describe('themes utilities', () => {
describe('Constants', () => {
it('has exactly 4 entries in THEME_OPTIONS', () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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');
});

@Priyanshu-byte-coder

Copy link
Copy Markdown
Owner

Closing as duplicate. #2774 was selected as the themes test winner for its maintainability (uses loops over THEME_OPTIONS). Thanks for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test : add unit tests for themes utility functions

3 participants