Skip to content

test(core): add createKeyEvent unit tests#1922

Merged
Karanjot786 merged 1 commit into
Karanjot786:mainfrom
Harshithk951:test-createkeyevent
Jul 3, 2026
Merged

test(core): add createKeyEvent unit tests#1922
Karanjot786 merged 1 commit into
Karanjot786:mainfrom
Harshithk951:test-createkeyevent

Conversation

@Harshithk951

@Harshithk951 Harshithk951 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds comprehensive unit tests for createKeyEvent helper function in packages/core/src/events/types.ts to verify its functional correctness and prevent regressions.

Related Issue

Closes #1920

Which package(s)?

@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

  • You are a GSSoC 2026 contributor.
  • Your GSSoC profile: https://gssoc.girlscript.org/profile/Harshithk951

Screenshots / Recordings (UI changes)

N/A

Notes for the Reviewer

None

Summary by CodeRabbit

  • Tests
    • Added coverage for keyboard event creation behavior.
    • Verified that key events include the expected base properties and modifier flags.
    • Confirmed that stopping propagation and preventing default correctly update the event’s internal state.

@Harshithk951 Harshithk951 requested a review from Karanjot786 as a code owner July 1, 2026 15:42
@github-actions github-actions Bot added type:testing +10 pts. Tests. area:core @termuijs/core labels Jul 1, 2026
@coderabbitai

coderabbitai Bot commented Jul 1, 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: 9e73662e-c95e-4013-9e42-46817e1a20ed

📥 Commits

Reviewing files that changed from the base of the PR and between 85e8d36 and 83049a1.

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

📝 Walkthrough

Walkthrough

Adds a new Vitest test suite for createKeyEvent in packages/core/src/events/types.test.ts, verifying construction of base key event properties and that stopPropagation() and preventDefault() correctly flip internal flags from false to true.

Changes

createKeyEvent test coverage

Layer / File(s) Summary
createKeyEvent unit tests
packages/core/src/events/types.test.ts
New test suite verifies key event field construction (key, raw, modifier flags, targetId) and that stopPropagation()/preventDefault() set _propagationStopped/_defaultPrevented to true.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

  • Karanjot786/TermUI#1073: Both PRs add Vitest tests using createKeyEvent to verify key-handling behavior.
  • Karanjot786/TermUI#1162: Both PRs center on createKeyEvent, with the retrieved PR constructing KeyEvent objects via this helper instead of unsafe casts.
  • Karanjot786/TermUI#1598: Both PRs add coverage involving createKeyEvent-based key event construction in tests.

Suggested labels: gssoc:approved, quality:clean, level:beginner

Suggested reviewers: Karanjot786

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and accurately describes the main change as adding createKeyEvent tests.
Description check ✅ Passed The PR description matches the template and includes the required sections, linked issue, package, change type, and checklist.
Linked Issues check ✅ Passed The added tests cover the object shape and both propagation/default-prevention flags required by issue #1920.
Out of Scope Changes check ✅ Passed The change is limited to a new unit test file and does not introduce unrelated code.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@Karanjot786 Karanjot786 added gssoc:approved Approved PR. Earns +50 base points. quality:clean x 1.2 multiplier. Clean implementation. level:beginner +20 pts. Entry-level task. labels Jul 3, 2026
@Karanjot786 Karanjot786 merged commit 833667f into Karanjot786:main Jul 3, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core @termuijs/core gssoc:approved Approved PR. Earns +50 base points. level:beginner +20 pts. Entry-level task. quality:clean x 1.2 multiplier. Clean implementation. type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Unit Tests for createKeyEvent in packages/core/src/events/types.ts

2 participants