Skip to content

Add unit-test suite for pure-logic helpers #5

Description

@mogul

Restored from slopsmith/slopsmith-plugin-splitscreen#37 — original issue, opened by @topkoa on 2026-05-05.
[restored-from: slopsmith/slopsmith-plugin-splitscreen#37]

Why

Plugin has real state machine (panel modes, focus model, prefs migration). PR #36 hit multiple regressions during review iteration — JT ↔ viz ↔ 2D transitions, pop-out/dock state preservation, _starting/active ordering, pref-shape migration. Easy to break again on next refactor.

Current state: no tests. Adding a small unit-test suite covers ~60% of regression risk without needing browser/DOM/WebSocket mocks.

Scope

JSDOM + vitest (or jest), runs in < 1 second. Test ONLY pure logic — no canvas, no WebSocket, no real DOM layout.

Suggested coverage:

  • migratePanelPrefs — version gate honored (v < 2 force-resets lyrics: false, v >= 2 preserves user toggle), __3d_highway__:__viz__:highway_3d: legacy migration
  • _modeToArrNamelyrics, jt, viz:<id>, 3d (legacy), arbitrary mode → arrName encoding
  • resolveArrIndex — sentinel rejection (__lyrics__, __jumping_tab__:*, __viz__:*), case-insensitive name match
  • Pref shape round-trip — savePanelPrefs → loadPanelPrefs → migratePanelPrefs idempotency
  • Pop-out URL params round-trip — _captureFollowerConfig → URL serialise → FOLLOWER parse → _followerCfgToPrefs
  • Sentinel constants stable — guard against accidental edits to LYRICS_VALUE / JUMPING_TAB_VALUE / VIZ_PREFIX (would invalidate existing localStorage prefs)

Out of scope

  • Canvas context-lock (browser-only behavior)
  • Highway WebSocket integration
  • Layout / sizing races
  • Renderer pre-install ordering (canvas swap)
  • Focus border / pointerdown wiring

These need Playwright. Not worth setting up for one plugin; covered by manual testing or upstream slopsmith e2e if/when added.

Setup notes

Plugin loads as a single IIFE today. To unit-test, expose helpers via a test-only window assignment guarded by process.env.NODE_ENV === 'test', OR refactor pure helpers into a separate lib.js that screen.js imports. Latter is cleaner but adds the first build step to the repo.

Slopsmith core uses pytest; no convention for plugin-side JS tests yet. Splitscreen would set the precedent — worth coordinating with byrongamatos/slopsmith maintainers before adding CI.

Risk if not done

Each new feature in this plugin (recently: viz picker, lyrics overlay, focus model) is one bot-review round away from breaking pref migrations or sentinels. Tests would catch those locally instead of after merge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions