Skip to content

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

@pranvxag

Description

@pranvxag

What problem does this solve?

packages/widgets/src/data/ListState.ts exports useListState — a state
hook that manages list selection, scroll offset, and disabled item
skipping. It has no test file despite containing non-trivial logic
around boundary clamping and disabled item navigation.

Proposed solution

Create packages/widgets/src/data/ListState.test.ts covering:

  • useListState initializes with correct defaults
  • setItems() updates items list
  • setItems() clamps selectedIndex when new list is shorter
  • selectNext() moves selection forward
  • selectNext() skips disabled items
  • selectNext() does not go past last item
  • selectPrev() moves selection backward
  • selectPrev() skips disabled items
  • selectPrev() does not go below 0
  • confirm() is callable without error (no-op placeholder)

Which package would this belong in?

@termuijs/widgets — packages/widgets/src/data/ListState.test.ts

GSSoC contributor?

  • Yes. You contribute under GSSoC 2026 and want to work on this.
  • No. You are filing a suggestion.

Metadata

Metadata

Assignees

Labels

assignedIssue claimed by a contributor.type:feature+10 pts. New feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions