Skip to content

test(timeline): add regression tests for cursor-anchored zoom (#847)#866

Open
TimeToBuildBob wants to merge 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:test/timeline-zoom-cursor-anchor
Open

test(timeline): add regression tests for cursor-anchored zoom (#847)#866
TimeToBuildBob wants to merge 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:test/timeline-zoom-cursor-anchor

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Summary

PR #860 fixed timeline zoom drifting away from the cursor position (issue #847) but included no automated tests. This PR adds 8 unit tests to guard against that regression being reintroduced.

What the tests cover

  • preferZoom: true is present in the vis-timeline options (prevents the pan-after-zoom drift)
  • onHorizontalWheel returns early when this.timeline is not yet initialised
  • onHorizontalWheel returns early when vertical scroll dominates (deltaY >= deltaX)
  • onHorizontalWheel pans the window by the correct amount when horizontal scroll dominates
  • preventDefault and stopImmediatePropagation are called on every handled event
  • DOM_DELTA_LINE mode scales deltaX by 40 px/line
  • DOM_DELTA_PAGE mode scales deltaX by 800 px/page

Approach

The tests call component methods directly on a mock vm object (VisTimeline.methods.onHorizontalWheel.call(vm, event)) and stub vis-timeline/esnext so they run in jsdom without a real browser layout or resize-observer stack. All 8 tests pass (npm test -- --testPathPattern VisTimeline).

Test plan

  • npm run test:unit -- --testPathPattern VisTimeline — all 8 tests pass
  • Full suite (npm test) remains green

…tyWatch#847)

PR ActivityWatch#860 fixed timeline zoom drifting from the cursor position but did not
include automated tests. These eight unit tests guard against regressions:

- preferZoom: true is present in VisTimeline's vis-timeline options
- onHorizontalWheel returns early when timeline is uninitialised
- onHorizontalWheel returns early when vertical scroll dominates (deltaY >= deltaX)
- onHorizontalWheel pans the window correctly when deltaX > deltaY
- preventDefault and stopImmediatePropagation are called on a handled event
- DOM_DELTA_LINE and DOM_DELTA_PAGE scaling factors (40 px/line, 800 px/page)

Tests call component methods directly via VisTimeline.methods without mounting
the full vis-timeline widget (which requires a real browser layout context).
@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 35.59%. Comparing base (8768475) to head (75c4f72).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #866      +/-   ##
==========================================
+ Coverage   35.50%   35.59%   +0.09%     
==========================================
  Files          36       36              
  Lines        2152     2152              
  Branches      417      398      -19     
==========================================
+ Hits          764      766       +2     
- Misses       1309     1365      +56     
+ Partials       79       21      -58     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@greptile-apps

greptile-apps Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds 8 regression tests for the cursor-anchored zoom fix (PR #860 / issue #847), covering the preferZoom option and the onHorizontalWheel handler's early-exit and panning logic. The tests call component methods directly on a mock vm and stub vis-timeline/esnext so they run cleanly in jsdom.

  • preferZoom: true assertion verifies the option is present in data().options, directly guarding against that field being accidentally dropped.
  • onHorizontalWheel tests cover all four branches (null timeline, vertical-dominated scroll, equal-magnitude scroll, and horizontal-dominated scroll) plus event propagation suppression and both non-pixel delta-mode scale factors — the computed diff values in the tests match the implementation's formula exactly.

Confidence Score: 5/5

Test-only change with no production code modified; the new tests correctly model the existing implementation and run in the established jsdom project.

All changes are in a new test file. The test math was verified against the actual onHorizontalWheel implementation — window offsets, delta-mode scale factors, and early-exit conditions all match. The vis-timeline mock is minimal and correct. No production paths are affected.

No files require special attention.

Important Files Changed

Filename Overview
test/unit/VisTimeline.test.js Adds 8 unit tests covering preferZoom option and onHorizontalWheel guard/pan logic; test math correctly matches the implementation, vis-timeline is cleanly mocked for jsdom, two minor assertion-completeness gaps.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[wheel event fired] --> B{this.timeline null?}
    B -- yes --> Z[return early]
    B -- no --> C{abs deltaY >= abs deltaX?}
    C -- yes --> Z
    C -- no --> D{deltaMode?}
    D -- DOM_DELTA_LINE --> E[deltaX x= 40]
    D -- DOM_DELTA_PAGE --> F[deltaX x= 800]
    D -- DOM_DELTA_PIXEL --> G[no scaling]
    E --> H[diff = deltaX/120 * windowMs/20]
    F --> H
    G --> H
    H --> I[setWindow start+diff end+diff]
    I --> J[preventDefault + stopImmediatePropagation]
Loading

Reviews (2): Last reviewed commit: "test(timeline): address Greptile review ..." | Re-trigger Greptile

Comment thread test/unit/VisTimeline.test.js
Comment thread test/unit/VisTimeline.test.js
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

@greptileai review

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

CI is green and the PR is mergeable.

I tried to squash-merge it from the monitoring lane, but the TimeToBuildBob token doesn't have MergePullRequest permission on ActivityWatch/aw-webui, so this is waiting on a maintainer merge.

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

Bumping — this has been idle 5 days. CI is green, ready for review/merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant