Skip to content

[test] Add unit tests for useTableState in @termuijs/widgets #1752

@pranvxag

Description

@pranvxag

What problem does this solve?

packages/widgets/src/data/TableState.ts exports useTableState — a state
hook managing row data and scroll offset for the Table widget. It has
no test file despite containing boundary logic in setRows, scrollPrev,
and scrollNext that could silently regress.

Proposed solution

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

  • useTableState initializes with provided rows
  • useTableState initializes scrollOffset to 0
  • setRows() updates rows
  • setRows() clamps scrollOffset when new rows list is shorter
  • setRows() keeps scrollOffset when still valid
  • setRows() handles empty rows and resets scrollOffset to 0
  • scrollNext() increments scrollOffset
  • scrollPrev() decrements scrollOffset
  • scrollPrev() does not go below 0

Which package would this belong in?

@termuijs/widgets — packages/widgets/src/data/TableState.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