Skip to content

test: add unit tests for useListState functionality#1751

Open
pranvxag wants to merge 1 commit into
Karanjot786:mainfrom
pranvxag:test/use-list-state-unit-tests
Open

test: add unit tests for useListState functionality#1751
pranvxag wants to merge 1 commit into
Karanjot786:mainfrom
pranvxag:test/use-list-state-unit-tests

Conversation

@pranvxag

@pranvxag pranvxag commented Jun 22, 2026

Copy link
Copy Markdown

Description

Adds 15 unit tests for useListState in @termuijs/widgets which had no
test coverage. Tests cover initialization, setItems with boundary
clamping, selectNext/selectPrev navigation, disabled item skipping,
scrollOffset updates, and confirm no-op behavior.

Related Issue

Closes #1749

Which package(s)?

@termuijs/widgets

Type of Change

  • 🐛 Bug fix (type:bug)
  • ✨ Feature (type:feature)
  • 📝 Docs (type:docs)
  • 🧪 Tests (type:testing)
  • ♻️ Refactor (type:refactor)
  • 🎨 Design / UX (type:design)
  • ♿ Accessibility (type:accessibility)
  • ⚡ Performance (type:performance)
  • 🔧 DevOps / CI (type:devops)
  • 🔒 Security (type:security)

Checklist

  • ⭐ You starred the repo. The needs-star check blocks your merge otherwise.
  • Tests pass locally: bun vitest run
  • Build passes: bun run build
  • Typecheck passes: bun run typecheck
  • You read CONTRIBUTING.md.
  • Your PR title follows type: short description.
  • Widget state mutators call markDirty() (if your change affects rendering).
  • No new any types without an inline comment explaining why.
  • No unrelated refactors bundled into this PR.

GSSoC 2026 Participation

Notes for the Reviewer

ListState.ts had zero test coverage. All 15 tests pass locally.
Full widgets suite (125 files, 1375 tests) passes with no regressions.

I reviewed each test case against the source code manually and verified all pass locally.

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for list state management functionality, including initialization, item selection navigation, boundary conditions, handling of disabled items, and scroll offset behavior.

@pranvxag pranvxag requested a review from Karanjot786 as a code owner June 22, 2026 09:47
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cb73d7c3-5ea9-4c98-8139-8953fff09ae9

📥 Commits

Reviewing files that changed from the base of the PR and between 35c2213 and 65247a4.

📒 Files selected for processing (1)
  • packages/widgets/src/data/ListState.test.ts

📝 Walkthrough

Walkthrough

Adds a new Vitest test file packages/widgets/src/data/ListState.test.ts for the useListState hook. The file includes item factory helpers and a describe suite covering initialization defaults, setItems() clamping, selectNext/selectPrev navigation with boundary and disabled-item handling, scrollOffset adjustment, and confirm() callability.

Changes

useListState Test Suite

Layer / File(s) Summary
useListState test suite
packages/widgets/src/data/ListState.test.ts
Introduces factory helpers (makeItems, makeItemsWithDisabled) and a complete describe('useListState') block asserting: initial selectedIndex/scrollOffset defaults, setItems() updating and clamping the index for shorter or empty lists, selectNext()/selectPrev() clamping at boundaries and skipping disabled items, scrollOffset decrement when selection moves above it, and confirm() executing without throwing.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Suggested labels

gssoc:approved, quality:clean, area:data, level:beginner

Suggested reviewers

  • Karanjot786

Poem

🐇 A test file hops in, fresh and bright,
Each assertion checked with careful might.
selectNext skips what's disabled, you see,
scrollOffset adjusts so smoothly — whee!
The bunny confirms: no errors thrown here,
useListState is tested, crystal clear! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'test: add unit tests for useListState functionality' is clear, concise, and directly describes the main change—adding comprehensive unit tests for the useListState hook.
Description check ✅ Passed The description is complete and follows the template structure with all required sections: Description, Related Issue (#1749), Which package (@termuijs/widgets), Type of Change (Tests selected), Checklist all marked, and GSSoC participation confirmed.
Linked Issues check ✅ Passed The PR successfully meets all requirements from issue #1749: tests cover initialization defaults, setItems() updates and clamping, selectNext/selectPrev navigation with disabled item skipping and boundary enforcement, and confirm() behavior.
Out of Scope Changes check ✅ Passed All changes are scoped to adding unit tests for useListState in ListState.test.ts, with no unrelated refactoring or modifications to source code outside the testing objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added type:testing +10 pts. Tests. area:widgets @termuijs/widgets labels Jun 22, 2026
@pranvxag pranvxag marked this pull request as draft June 22, 2026 09:48
@pranvxag pranvxag marked this pull request as ready for review June 22, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:widgets @termuijs/widgets type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[test] Add unit tests for useListState in @termuijs/widgets

1 participant