Skip to content

test(widgets): add unit tests for FileExplorer widget#1731

Open
pranvxag wants to merge 1 commit into
Karanjot786:mainfrom
pranvxag:test/file-explorer-unit-tests
Open

test(widgets): add unit tests for FileExplorer widget#1731
pranvxag wants to merge 1 commit into
Karanjot786:mainfrom
pranvxag:test/file-explorer-unit-tests

Conversation

@pranvxag

@pranvxag pranvxag commented Jun 21, 2026

Copy link
Copy Markdown

Description

Adds a comprehensive unit test file for the FileExplorer widget
(packages/widgets/src/FileExplorer.ts), which had no test coverage.
14 tests cover navigation, selection, search, callbacks, and edge cases.

Related Issue

Closes #1730

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

I reviewed each test case against the source code and verified all pass locally
with bun vitest run packages/widgets/.

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for FileExplorer component, including file selection, navigation, filtering, and callback behavior.

@pranvxag pranvxag requested a review from Karanjot786 as a code owner June 21, 2026 13:11
@github-actions github-actions Bot added type:testing +10 pts. Tests. area:widgets @termuijs/widgets labels Jun 21, 2026
@coderabbitai

coderabbitai Bot commented Jun 21, 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: c667acc1-c60d-4558-aaf9-9a2269b0e4ee

📥 Commits

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

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

📝 Walkthrough

Walkthrough

Adds packages/widgets/src/FileExplorer.test.ts, a new Vitest suite that covers all public behaviors of FileExplorer: constructor defaults, setFiles, next()/previous() navigation with bounds clamping, select() with callback and no-op, search() with case-insensitive filtering, and the current/selected getters.

Changes

FileExplorer Test Suite

Layer / File(s) Summary
Test fixture and constructor tests
packages/widgets/src/FileExplorer.test.ts
Adds the makeFiles helper returning a FileItem[] fixture; verifies root defaults to "./" and that a provided root option is stored correctly.
setFiles, next(), and previous() navigation
packages/widgets/src/FileExplorer.test.ts
Verifies setFiles loads the file list and resets selectedIndex to 0; tests next() and previous() cursor movement including clamping at both ends.
select() and search() behavior
packages/widgets/src/FileExplorer.test.ts
Tests select() accumulating paths, firing onSelect with the correct path, and being a no-op on an empty list; tests search() for case-insensitive filtering and empty-result returns.
current and selected getters
packages/widgets/src/FileExplorer.test.ts
Asserts current is undefined with no files loaded and selected correctly aggregates all paths across multiple navigation and select() calls.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Suggested labels

gssoc:approved, quality:clean, type:testing, area:widgets, level:beginner

Suggested reviewers

  • Karanjot786

Poem

🐇 A rabbit hopped through files one day,
Checking next() and previous() along the way.
select() fired—the callback rang true,
search() found matches (case-insensitive too)!
With every getter tested and green,
The cleanest explorer the warren has seen. 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding unit tests for the FileExplorer widget. It follows the repository's format and directly summarizes the changeset.
Description check ✅ Passed The description includes all required sections from the template: Description, Related Issue, Which package(s), Type of Change, Checklist, and GSSoC participation. All sections are properly filled out.
Linked Issues check ✅ Passed All requirements from issue #1730 are met: setFiles resetting index, next/previous navigation with clamping, select() adding paths and firing callbacks, select() handling empty lists, search() filtering case-insensitively, and getter methods returning correct values.
Out of Scope Changes check ✅ Passed All changes are focused on adding test coverage for FileExplorer as specified in issue #1730. No unrelated modifications or refactors are present.
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 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.

🎉 Thanks for your first PR to TermUI, @pranvxag.

Before your PR merges:

  1. Star the repo. Required. The star-check job blocks your merge otherwise.
  2. ✅ All checks green: build, test, typecheck.
  3. 🏷 PR title follows type: short description. Example: fix: handle empty list.
  4. 🔗 Link your closing issue in the description.

GSSoC 2026 points come from labels after merge:

  • gssoc:approved. +50 base points.
  • level:beginner / intermediate / advanced / critical. +20 / +35 / +55 / +80.
  • quality:clean / exceptional. x 1.2 / x 1.5.
  • type:*. Stackable bonus.

Your reviewer responds within 48 hours. Ping @Karanjot786 on Discord for urgent help.

🚀 Welcome to the cohort.

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 FileExplorer widget

1 participant