diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index e0d54c5d6b..57d57a4338 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -91,4 +91,29 @@ jobs: - name: Run Unit tests working-directory: ${{ env.PLUGIN_DIR }} - run: pnpm test:unit + run: pnpm test:unit:php + + js-unit-tests: + name: Vitest Unit Tests + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 24 + cache: 'pnpm' + cache-dependency-path: pnpm-lock.yaml + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Run Vitest unit tests + run: pnpm test:unit:js diff --git a/.scratch/declarative-player/issues/01-registry-service-registration.md b/.scratch/declarative-player/issues/01-registry-service-registration.md new file mode 100644 index 0000000000..61a05bb00b --- /dev/null +++ b/.scratch/declarative-player/issues/01-registry-service-registration.md @@ -0,0 +1,41 @@ +Type: task +Status: done +Blocked by: — + +## Question + +Register the player service through `ComponentRegistry` instead of the hand-rolled +`Object.assign` in `assets/core/ts/services/player/index.ts` (ADR-0010, grilling Q8): + +- Move `window.TutorComponentRegistry = TutorComponentRegistry` from inside + `initializePlugin()` to module scope in `assets/core/ts/index.ts`. The deferred engine + module executes before `initializePlugin` runs, so the window bridge must exist by + then. Confirm no consumer depends on the registry appearing later — existing + registrants run on `alpine:init` or later and only guard with `if`. +- Add `playerServiceMeta: ServiceMeta` next to the service + (`{ name: 'player', instance }`). +- Engine `index.ts`: register via + `window.TutorComponentRegistry?.register({ type: 'service', meta: playerServiceMeta })`, + falling back to the imported registry instance when the bridge is absent; delete the + `Object.assign` exposure. `window.TutorCore.player` must be set by + `exposeToWindow` like every other service. +- Add `window.TutorComponentRegistry` typing if missing. + +Verify: `tsc` / `eslint` / `rspack --mode=production` green; +`window.TutorComponentRegistry.has({ name: 'player', type: 'service' })` is true after +the engine boots; `TutorCore.player` is set on a lesson page; dashboard + +learning-area smoke (the earlier exposure must be inert). + +## Outcome + +Done. `window.TutorComponentRegistry = TutorComponentRegistry` moved to module scope in +`assets/core/ts/index.ts`; `playerServiceMeta` added in `PlayerService.ts`; the engine +registers via `window.TutorComponentRegistry ?? imported instance` and the `Object.assign` +exposure is deleted. Typing already existed (`declaration.d.ts:58`). + +Verified: player vitest suite, `tsc`, eslint, production build green. Built +`tutor-player.js` carries the `name:"player"` meta; `tutor-core.js` sets the bridge at +module scope. Since the delivery change (ADR-0011) the engine is a classic script too: +registration uses the bridge when `tutor-core` is already loaded (learning-area pages) +and the imported instance when the engine runs first (course pages); either path exposes +`window.TutorCore.player`. Browser smoke in 04. diff --git a/.scratch/declarative-player/issues/02-self-boot-element-and-service-tracking.md b/.scratch/declarative-player/issues/02-self-boot-element-and-service-tracking.md new file mode 100644 index 0000000000..893ada72c1 --- /dev/null +++ b/.scratch/declarative-player/issues/02-self-boot-element-and-service-tracking.md @@ -0,0 +1,55 @@ +Type: task +Status: done +Blocked by: 01 + +## Question + +Self-boot the declared element and move ownership to the element (ADR-0010, grilling +Q6/Q9). Templates are untouched in this ticket — today's markup must run through the +new path via the shim. + +- The element creates its handle on connect (`createTutorPlayer` over its store), + exposes it as `element.player`, and registers with the service. +- Service tracks instances: `getActive()` = most recent live instance; dispose clears + the active slot; `on()` late-binds when a player appears (research F1). Public shape + frozen (`create`/`getActive`/`on`/proxies). +- `create()` becomes an idempotent "ensure a handle for legacy markup": detect → + replace with the declarative tree → element self-boots → return `element.player` + (used by the shim and the Alpine component). +- Adapter loading: subtree tag scan for `youtube-video`/`vimeo-video` → lazy import. + Keep the define-player-before-adapters order (ADR-0010 hard contract). +- The element removes a `controls` attribute if present (no-op today; the stage-2 + templates keep `controls` as the no-JS fallback). +- Keep wiring injectable (fake store) so happy-dom tests stay meaningful; extend + `PlayerService.test.ts`; add element-boot tests. Decide the element ↔ service + plumbing (wired callback vs DOM event) — avoid the `elements.ts` ↔ `PlayerService.ts` + import cycle. + +Verify: unit tests + `tsc` + build green; smoke learning-area lesson, legacy lesson, +course intro, Alpine path — behavior identical to pre-change. + +## Outcome + +Done. Plumbing decision: **wired callback** — `elements.ts` exposes +`setPlayerElementHooks({ onMount, onDispose })`, wired by the engine entry to +`playerServiceMeta.instance.track/untrack`; no `elements ↔ PlayerService` import cycle. + +- `TutorVideoPlayerElement` (subclass of the vendor `PlayerElement`) boots in + `connectedCallback`: sets the default `content-title`, drops the no-JS `controls` + fallback, resolves the provider from its subtree (`resolveProvider`: embed tag scan, + then `providerFromUrl` on the native source), lazy-loads the adapter for yt/vimeo, and + creates the handle as `element.player`. `destroyCallback` releases it too, so the + vendor's two-frame auto-destroy after removal cannot leave a dead handle active. +- Service: `track`/`untrack` (dispose clears the active slot), `on()` late-binds to the + first player that appears, `create()` = detect → build tree → replace → return + `element.player` (idempotent ensure). Dependencies reduced to injectable + `createElement`. +- Adapter loading moved out of `createPlayerElement`; it now always appends the media + immediately (the deferred-append dance is gone) and the element owns the import. + Define-player-before-adapters order preserved (hard contract). +- `legacy.ts` subscribes through `service.on` and retries on `PLAYER_ENGINE_READY` when + the engine is absent (F1). + +Tests: 46 in the player suite (boot/dispose/reconnect/destroy, provider resolution, +late-bind, untrack, `onDispose`); full suite 66 green. `tsc`, eslint, production build +green. Browser smoke owed in 04. diff --git a/.scratch/declarative-player/issues/03-space-reservation-css.md b/.scratch/declarative-player/issues/03-space-reservation-css.md new file mode 100644 index 0000000000..49ad5448e5 --- /dev/null +++ b/.scratch/declarative-player/issues/03-space-reservation-css.md @@ -0,0 +1,28 @@ +Type: task +Status: done +Blocked by: — + +## Question + +Reserve the player's space before upgrade (ADR-0010, grilling Q10) in +`assets/src/scss/frontend/components/_videojs-player.scss`: + +- `tutor-video-player { display: block; width: 100%; }` + wrapper aspect-ratio so an + unupgraded element occupies the same box as the skinned player (no CLS). +- Keep the spinner visible pre-upgrade (it is removed on ready). +- Size the pre-upgrade slotted media (light-DOM `