mirror of
https://github.com/kamranahmedse/driver.js.git
synced 2026-11-01 05:07:12 +08:00
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.
101 lines
2.9 KiB
TypeScript
101 lines
2.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { createDriver, nextFrame, popoverTitle, SAMPLE_STEPS, useDriverHarness } from "./utils";
|
|
|
|
useDriverHarness();
|
|
|
|
describe("tour navigation", () => {
|
|
it("starts at the first step", () => {
|
|
const d = createDriver({ animate: false, steps: SAMPLE_STEPS });
|
|
d.drive();
|
|
|
|
expect(d.getActiveIndex()).toBe(0);
|
|
expect(d.isFirstStep()).toBe(true);
|
|
expect(d.isLastStep()).toBe(false);
|
|
expect(d.hasPreviousStep()).toBeFalsy();
|
|
expect(d.hasNextStep()).toBeTruthy();
|
|
expect(popoverTitle()).toBe("Step 1");
|
|
});
|
|
|
|
it("can start at a given index", () => {
|
|
const d = createDriver({ animate: false, steps: SAMPLE_STEPS });
|
|
d.drive(1);
|
|
|
|
expect(d.getActiveIndex()).toBe(1);
|
|
expect(popoverTitle()).toBe("Step 2");
|
|
});
|
|
|
|
it("moves to the next and previous steps", () => {
|
|
const d = createDriver({ animate: false, steps: SAMPLE_STEPS });
|
|
d.drive();
|
|
|
|
d.moveNext();
|
|
expect(d.getActiveIndex()).toBe(1);
|
|
expect(popoverTitle()).toBe("Step 2");
|
|
|
|
d.movePrevious();
|
|
expect(d.getActiveIndex()).toBe(0);
|
|
expect(popoverTitle()).toBe("Step 1");
|
|
});
|
|
|
|
it("detects the last step", () => {
|
|
const d = createDriver({ animate: false, steps: SAMPLE_STEPS });
|
|
d.drive();
|
|
d.moveTo(2);
|
|
|
|
expect(d.getActiveIndex()).toBe(2);
|
|
expect(d.isLastStep()).toBe(true);
|
|
expect(d.hasNextStep()).toBeFalsy();
|
|
expect(popoverTitle()).toBe("Step 3");
|
|
});
|
|
|
|
it("exposes the next step", () => {
|
|
const d = createDriver({ animate: false, steps: SAMPLE_STEPS });
|
|
d.drive();
|
|
|
|
expect(d.getNextStep()?.popover?.title).toBe("Step 2");
|
|
|
|
d.moveTo(SAMPLE_STEPS.length - 1);
|
|
expect(d.getNextStep()).toBeUndefined();
|
|
});
|
|
|
|
it("destroys the tour when moving next past the last step", () => {
|
|
const d = createDriver({ animate: false, steps: SAMPLE_STEPS });
|
|
d.drive(SAMPLE_STEPS.length - 1);
|
|
|
|
d.moveNext();
|
|
|
|
expect(d.isActive()).toBe(false);
|
|
});
|
|
|
|
it("destroys the tour when moving previous before the first step", () => {
|
|
const d = createDriver({ animate: false, steps: SAMPLE_STEPS });
|
|
d.drive();
|
|
|
|
d.movePrevious();
|
|
|
|
expect(d.isActive()).toBe(false);
|
|
});
|
|
|
|
it("destroys the tour when moving to an out-of-range index", () => {
|
|
const d = createDriver({ animate: false, steps: SAMPLE_STEPS });
|
|
d.drive();
|
|
|
|
d.moveTo(99);
|
|
|
|
expect(d.isActive()).toBe(false);
|
|
});
|
|
|
|
it("exposes the active and previous step and element", async () => {
|
|
const d = createDriver({ animate: false, steps: SAMPLE_STEPS });
|
|
d.drive();
|
|
await nextFrame();
|
|
d.moveNext();
|
|
await nextFrame();
|
|
|
|
expect(d.getActiveStep()?.popover?.title).toBe("Step 2");
|
|
expect(d.getPreviousStep()?.popover?.title).toBe("Step 1");
|
|
expect(d.getActiveElement()).toBe(document.querySelector("#card-1"));
|
|
expect(d.getPreviousElement()).toBe(document.querySelector("#intro"));
|
|
});
|
|
});
|