Files
driver.js/packages/driver/tests/skip-missing.test.ts
Kamran Ahmed 75edd1b4bc Restructure as a Turborepo monorepo
packages/driver is the library (still published as driver.js, with
repository.directory set); playground and docs move to apps/. One root
pnpm workspace and lockfile replace the three standalone projects, with
turbo orchestrating build/test/lint:package (apps depend on the library
build; local + CI caching via .turbo).

Apps keep importing the library from source for HMR — the aliases now
point at ../../packages/driver/src and each app gains a workspace:*
dependency so the task graph knows the edge. The dev-server fs scope
widens to the repo root accordingly.

Releases run from packages/driver (root `pnpm release` delegates). The
changelog still lives in the docs app, so the release scripts reach it
via ../../../apps/docs and the after:bump hook stages it explicitly —
release-it no longer sits above both directories.

The merged workspace settings keep sharp unbuilt on purpose (prebuilt
binaries; building from source needs node-gyp and fails) — the docs app
had this right and the playground setting was the accident. postcss and
postcss-scss were unreferenced devDependencies and are dropped; prettier
moves to the root as the only shared tool.
2026-07-16 19:45:23 +01:00

122 lines
3.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { createDriver, popoverTitle, useDriverHarness } from "./utils";
useDriverHarness();
// #intro and #card-1 exist in DEMO_HTML; #missing never does.
const STEPS = [
{ element: "#intro", popover: { title: "Step 1" } },
{ element: "#missing", popover: { title: "Step 2" } },
{ element: "#card-1", popover: { title: "Step 3" } },
];
describe("skipMissingElement", () => {
it("skips a step whose element is missing when moving forward", () => {
const d = createDriver({ animate: false, skipMissingElement: true, steps: STEPS });
d.drive();
expect(popoverTitle()).toBe("Step 1");
d.moveNext();
expect(popoverTitle()).toBe("Step 3");
expect(d.getActiveIndex()).toBe(2);
});
it("skips a step whose element is missing when moving backward", () => {
const d = createDriver({ animate: false, skipMissingElement: true, steps: STEPS });
d.drive(2);
expect(popoverTitle()).toBe("Step 3");
d.movePrevious();
expect(popoverTitle()).toBe("Step 1");
expect(d.getActiveIndex()).toBe(0);
});
it("skips a missing first step on initial drive", () => {
const d = createDriver({
animate: false,
skipMissingElement: true,
steps: [{ element: "#missing", popover: { title: "Step 1" } }, ...STEPS.slice(2)],
});
d.drive();
expect(d.getActiveIndex()).toBe(1);
expect(popoverTitle()).toBe("Step 3");
});
it("does not skip when the option is off (shows the centered popover)", () => {
const d = createDriver({ animate: false, steps: STEPS });
d.drive();
d.moveNext();
expect(d.getActiveIndex()).toBe(1);
expect(popoverTitle()).toBe("Step 2");
});
it("never skips an intentional element-less step", () => {
const d = createDriver({
animate: false,
skipMissingElement: true,
steps: [
{ element: "#intro", popover: { title: "Step 1" } },
{ popover: { title: "Centered" } },
{ element: "#card-1", popover: { title: "Step 3" } },
],
});
d.drive();
d.moveNext();
expect(d.getActiveIndex()).toBe(1);
expect(popoverTitle()).toBe("Centered");
});
it("honours a step-level skipMissingElement over the driver default", () => {
const d = createDriver({
animate: false,
steps: [
{ element: "#intro", popover: { title: "Step 1" } },
{ element: "#missing", skipMissingElement: true, popover: { title: "Step 2" } },
{ element: "#card-1", popover: { title: "Step 3" } },
],
});
d.drive();
d.moveNext();
expect(d.getActiveIndex()).toBe(2);
expect(popoverTitle()).toBe("Step 3");
});
it("ends the tour when the remaining forward steps are all missing", () => {
const d = createDriver({
animate: false,
skipMissingElement: true,
steps: [
{ element: "#intro", popover: { title: "Step 1" } },
{ element: "#missing", popover: { title: "Step 2" } },
{ element: "#missing-too", popover: { title: "Step 3" } },
],
});
d.drive();
d.moveNext();
expect(d.isActive()).toBe(false);
});
it("stays put when moving backward finds no earlier present step", () => {
const d = createDriver({
animate: false,
skipMissingElement: true,
steps: [
{ element: "#missing", popover: { title: "Step 1" } },
{ element: "#missing-too", popover: { title: "Step 2" } },
{ element: "#card-1", popover: { title: "Step 3" } },
],
});
d.drive(2);
expect(d.getActiveIndex()).toBe(2);
d.movePrevious();
expect(d.isActive()).toBe(true);
expect(d.getActiveIndex()).toBe(2);
expect(popoverTitle()).toBe("Step 3");
});
});