Skip to content

test(grid): coverage for virtualization, compression math, viewport priority#74

Open
merlin1de wants to merge 1 commit intomasterfrom
tests/grid-virtualization-coverage
Open

test(grid): coverage for virtualization, compression math, viewport priority#74
merlin1de wants to merge 1 commit intomasterfrom
tests/grid-virtualization-coverage

Conversation

@merlin1de
Copy link
Copy Markdown
Owner

Summary

Closes the test gaps identified after the mobile-scroll session (#73). No behavior change in production code — pure refactor + new tests.

Refactor (no-op, single source of truth)

New src/utils/gridLayout.js with pure helpers extracted from `GridView.vue`:

  • `spacerHeightForRows(n, rowHeight, gap)`
  • `computeCompressionRatio(fullLogicalHeight, maxPhysicalHeight)`
  • `computeTopSpacerHeight({...})` — both classic and continuous (compression) branches
  • `iterateViewportFirst(rangeStart, rangeEnd, vpStart, vpEnd)` generator yielding `[index, priority]` pairs

`GridView.vue` delegates to these. Existing 418 Vitest tests still green.

Vitest +24

`tests/js/gridLayout.spec.js` (20 tests)

  • `spacerHeightForRows` edge cases (n ≤ 0, N×rowHeight + (N-1)×gap match)
  • `computeCompressionRatio` cap behavior + broken-cap fallback
  • `computeTopSpacerHeight`:
    • Fallback (virtualEnabled = false) returns 0
    • Compression = 1 (classic): matches `spacerHeightForRows`, independent of scrollTop
    • Compression > 1: top-edge clamp at `visibleStartRow ≤ 0`, sub-row offset, negative-formula clamp
    • Continuity check: at Δ scrollTop = 1 within a row, Δ spacer ≈ `1 - compressionRatio` — proves the smooth scroll math
  • `iterateViewportFirst` order, edge cases (no buffer above/below, empty range), and unshift-semantics simulation showing top-of-viewport ends up at queue front

`tests/js/GridView.spec.js` (4 tests)

  • ↑/↓ keyboard navigation steps by exactly `columnsCount` items (regression guard for the `columnsEstimate` bug — was using `offsetWidth/THUMB_SIZE` returning 1 in jsdom and on mobile, which broke ↑/↓ on 2-column mobile layout)
  • Bottom-edge clamp

Cypress +3

`tests/e2e/mobile-virtualization.cy.js` at viewport 414×896

  • Virtualization activates when folder exceeds the visible range (rendered count < total, spacer present)
  • Scrolling shifts the render range (data-index of first item moves forward)
  • `topSpacer` appears after scrolling out of the top region

Skips with log message if test folder has < 20 images. Column count is not asserted — Cypress' viewport setting controls `window.innerWidth` but NC's mobile UI behavior in iframe varies; the virtualization mechanism is what matters.

Test plan

  • Vitest: 442 / 442 (was 418, + 20 gridLayout + 4 GridView)
  • Cypress: `mobile-virtualization` 3 / 3 against sixpack
  • Cypress full suite — would expect same as PR fix(grid): smooth mobile scroll in huge grids #73 (only the known guest-gallery timing flake)

…rt-Priority

Zieht die Test-Lücken nach, die in der mobile-scroll Session aufgefallen sind.

Refactor (minimaler Behavior-No-Op):
  src/utils/gridLayout.js neu — pure Helper für Spacer-Math, Compression-
  Ratio, kontinuierliche topSpacer-Formel, Viewport-First-Iterator.
  GridView.vue importiert sie und delegiert; jsdom-Vitest kann jetzt
  die Math direkt testen ohne Layout-Mocking.

Vitest +24:
  - gridLayout.spec.js (20 Tests): spacerHeightForRows Edge-Cases,
    Compression-Ratio Cap-Verhalten, topSpacer in beiden Modi inkl.
    Continuity-Check (Δ Spacer = 1 - ratio bei Sub-Row-Scroll), Viewport-
    First-Iterator komplett mit unshift-Semantik-Simulation.
  - GridView.spec.js (4 Tests): ↑/↓ Tastatur-Nav steppt um columnsCount
    Items (Bug-Wiederholungs-Schutz für den columnsEstimate-Fix), inkl.
    Bottom-Edge-Clamp.

Cypress +3:
  - mobile-virtualization.cy.js: 414×896 Viewport, prüft dass
    Virtualisierung am Mobile-Viewport aktiv ist, scrollen den Render-
    Range shiftet und topSpacer auftaucht. Spalten-Anzahl wird absichtlich
    nicht asserted (NC-Mobile-UI-Verhalten variiert in Cypress).
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