mirror of
https://github.com/kamranahmedse/driver.js.git
synced 2026-10-31 20:31:43 +08:00
Replaces the placeholder test with focused, maintainable suites that encode the documented API behaviour as a regression net for the upcoming API migration: - lifecycle: activate/highlight/destroy, active element, modal popovers - navigation: drive, moveNext/movePrevious/moveTo, first/last, getters - popover: buttons, progress text, custom class, onPopoverRender - interactions: next/prev/close clicks and onNextClick/onPrevClick overrides - keyboard: escape + arrow keys, allowClose/allowKeyboardControl - hooks: onHighlightStarted/onHighlighted/onDeselected/onDestroyed - config: getConfig/setConfig/setSteps/getState/refresh Shared setup lives in tests/utils.ts. Also add test:run and test:coverage scripts.
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { createDriver, nextFrame, popoverTitle, pressKey, SAMPLE_STEPS, useDriverHarness } from "./utils";
|
|
|
|
useDriverHarness();
|
|
|
|
describe("keyboard control", () => {
|
|
it("closes the tour when Escape is pressed", () => {
|
|
const d = createDriver({ animate: false, steps: SAMPLE_STEPS });
|
|
d.drive();
|
|
pressKey("Escape");
|
|
|
|
expect(d.isActive()).toBe(false);
|
|
});
|
|
|
|
it("ignores Escape when allowClose is false", () => {
|
|
const d = createDriver({ animate: false, allowClose: false, steps: SAMPLE_STEPS });
|
|
d.drive();
|
|
pressKey("Escape");
|
|
|
|
expect(d.isActive()).toBe(true);
|
|
});
|
|
|
|
it("navigates with the arrow keys", async () => {
|
|
const d = createDriver({ animate: false, steps: SAMPLE_STEPS });
|
|
d.drive();
|
|
// Arrow handlers no-op mid-transition, so let the highlight settle first.
|
|
await nextFrame();
|
|
|
|
pressKey("ArrowRight");
|
|
await nextFrame();
|
|
expect(d.getActiveIndex()).toBe(1);
|
|
expect(popoverTitle()).toBe("Step 2");
|
|
|
|
pressKey("ArrowLeft");
|
|
await nextFrame();
|
|
expect(d.getActiveIndex()).toBe(0);
|
|
});
|
|
|
|
it("ignores keys when allowKeyboardControl is false", () => {
|
|
const d = createDriver({ animate: false, allowKeyboardControl: false, steps: SAMPLE_STEPS });
|
|
d.drive();
|
|
|
|
pressKey("ArrowRight");
|
|
expect(d.getActiveIndex()).toBe(0);
|
|
|
|
pressKey("Escape");
|
|
expect(d.isActive()).toBe(true);
|
|
});
|
|
});
|