Skip to content

test: add unit tests for CommandHistory functionality#1750

Open
pranvxag wants to merge 2 commits into
Karanjot786:mainfrom
pranvxag:test/command-history-unit-tests
Open

test: add unit tests for CommandHistory functionality#1750
pranvxag wants to merge 2 commits into
Karanjot786:mainfrom
pranvxag:test/command-history-unit-tests

Conversation

@pranvxag

@pranvxag pranvxag commented Jun 22, 2026

Copy link
Copy Markdown

Description

Adds 23 unit tests for CommandHistory in @termuijs/core which had no
test coverage. Tests cover add, previous, next, search, getAll, clear,
export, and import including edge cases like empty input, clamping,
maxSize eviction, and navigation after import.

Related Issue

Closes #1748

Which package(s)?

Package: @termuijs/core

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

CommandHistory.ts had zero test coverage. All 23 tests pass locally.
Full core test suite (43 files, 471 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 automated coverage for command history, including constructor defaults and capacity-based eviction.
    • Verified add behavior (ignores empty/whitespace), navigation semantics (previous/next and boundary handling), and case-insensitive search.
    • Confirmed history ordering, immutability of returned results, clear/reset behavior, and JSON import/export round-tripping (including navigation state).

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a new Vitest test file packages/core/src/history/CommandHistory.test.ts with 186 lines covering all public methods of CommandHistory: constructor defaults and eviction, add() filtering and capacity, previous()/next() navigation, search(), getAll() copy semantics, clear(), and export()/import() JSON round-trip.

Changes

CommandHistory Test Suite

Layer / File(s) Summary
Test file setup and constructor tests
packages/core/src/history/CommandHistory.test.ts
Imports Vitest and CommandHistory, opens the top-level describe block, and asserts default maxSize of 100 with eviction and custom maxSize with oldest-entry eviction.
add(), previous(), and next() behavior tests
packages/core/src/history/CommandHistory.test.ts
Tests add() for valid storage, empty/whitespace rejection, and capacity eviction; tests previous() for empty history, reverse traversal, and lower-bound clamping; tests next() for empty, past-end null, and forward traversal after stepping back.
search(), getAll(), clear(), export()/import() tests
packages/core/src/history/CommandHistory.test.ts
Tests search() for substring matching, case-insensitivity, and empty-result; getAll() for insertion order and copy semantics; clear() for emptying history and resetting navigation state; export()/import() for JSON round-trip and navigation correctness after restore.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Suggested labels

gssoc:approved, quality:clean, level:intermediate

Suggested reviewers

  • Karanjot786

Poem

🐇 Hop, hop, history is kept!
Each command remembered, none except
The blank and the whitespace—quietly swept.
previous(), next(), forward and back,
Export and import—nothing we lack.
The tests all pass, the suite complete,
A tidy command trail, oh so neat! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'test: add unit tests for CommandHistory functionality' clearly and concisely describes the main change—adding comprehensive unit tests for CommandHistory with proper 'type: description' format.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description follows the required template with all essential sections completed: clear description of what tests were added, related issue (#1748) linked, package identified (@termuijs/core), type of change marked (Tests), comprehensive checklist completion, and GSSoC participation confirmed.

✏️ 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:core @termuijs/core labels Jun 22, 2026
@pranvxag pranvxag marked this pull request as ready for review June 22, 2026 09:26
@pranvxag pranvxag requested a review from Karanjot786 as a code owner June 22, 2026 09:26

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/src/history/CommandHistory.test.ts`:
- Around line 120-124: The case-insensitive search test only validates the count
of results but not the actual content, allowing the test to pass even if an
incorrect command is returned. In the test case for "search() is
case-insensitive", after asserting that the search results have length 1, add an
additional assertion to verify that the matched result actually contains or
equals the expected command 'Git Status'. This ensures the search method returns
the correct command, not just any command.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6e110ce0-9601-44e6-98ff-c63df3663a0a

📥 Commits

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

📒 Files selected for processing (1)
  • packages/core/src/history/CommandHistory.test.ts

Comment thread packages/core/src/history/CommandHistory.test.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[test] Add unit tests for CommandHistory in @termuijs/core

1 participant