b3a7f98e5a
CI / E2E Cloudflare (4/8) (push) Failing after 0s
CI / E2E Cloudflare (8/8) (push) Failing after 1s
CI / Lint (push) Failing after 1s
Auto Extract / Extract (push) Failing after 4s
CI / Version Check (push) Failing after 9s
CI / Integration Tests (push) Failing after 1s
CI / E2E tests (1/8) (push) Failing after 1s
CI / E2E tests (2/8) (push) Failing after 2s
CI / E2E tests (3/8) (push) Failing after 2s
CI / Browser Tests (push) Failing after 1s
CI / E2E tests (5/8) (push) Failing after 1s
CI / E2E Cloudflare (2/8) (push) Failing after 2s
CI / Typecheck (push) Failing after 1s
CI / Changeset Validation (push) Failing after 2s
CI / E2E Cloudflare (5/8) (push) Failing after 1s
CI / E2E Cloudflare (6/8) (push) Failing after 1s
CI / E2E Cloudflare (7/8) (push) Failing after 1s
CodeQL / Analyze (javascript-typescript) (push) Failing after 1s
Format / Format (push) Failing after 0s
CodeQL / Analyze (actions) (push) Failing after 4s
CI / E2E tests (4/8) (push) Failing after 1s
CI / E2E tests (6/8) (push) Failing after 1s
CI / E2E tests (7/8) (push) Failing after 2s
CI / E2E tests (8/8) (push) Failing after 1s
CI / E2E Cloudflare (1/8) (push) Failing after 1s
CI / E2E Cloudflare (3/8) (push) Failing after 2s
Preview Releases / Publish Preview (push) Failing after 0s
zizmor / Run zizmor (push) Failing after 1s
Release / Release (push) Failing after 2s
CI / Smoke Tests (push) Failing after 5m36s
CI / Tests (push) Failing after 6m36s
Release / Sync Templates (push) Has been skipped
CI / E2E Tests (push) Has been cancelled
74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
|
|
import { renderPlaygroundToolbar } from "../../src/db/playground-toolbar.js";
|
|
|
|
const BASE_CONFIG = {
|
|
createdAt: "2026-03-16T12:00:00.000Z",
|
|
ttl: 3600,
|
|
editMode: false,
|
|
};
|
|
|
|
describe("renderPlaygroundToolbar", () => {
|
|
it("renders HTML with data attributes", () => {
|
|
const html = renderPlaygroundToolbar(BASE_CONFIG);
|
|
|
|
expect(html).toContain('id="emdash-playground-toolbar"');
|
|
expect(html).toContain('data-created-at="2026-03-16T12:00:00.000Z"');
|
|
expect(html).toContain('data-ttl="3600"');
|
|
});
|
|
|
|
it("renders the playground badge", () => {
|
|
const html = renderPlaygroundToolbar(BASE_CONFIG);
|
|
expect(html).toContain("Playground");
|
|
});
|
|
|
|
it("renders the deploy CTA link", () => {
|
|
const html = renderPlaygroundToolbar(BASE_CONFIG);
|
|
expect(html).toContain("Deploy your own");
|
|
expect(html).toContain("github.com/emdash-cms/emdash");
|
|
});
|
|
|
|
it("renders reset and dismiss buttons", () => {
|
|
const html = renderPlaygroundToolbar(BASE_CONFIG);
|
|
expect(html).toContain('id="ec-pg-reset"');
|
|
expect(html).toContain('id="ec-pg-dismiss"');
|
|
expect(html).toContain("/_playground/reset");
|
|
});
|
|
|
|
it("escapes HTML in data attributes", () => {
|
|
const html = renderPlaygroundToolbar({
|
|
...BASE_CONFIG,
|
|
createdAt: '"<script>alert(1)</script>',
|
|
});
|
|
|
|
expect(html).toContain("<script>alert(1)</script>");
|
|
expect(html).not.toContain('data-created-at="<script>');
|
|
});
|
|
|
|
it("includes countdown script", () => {
|
|
const html = renderPlaygroundToolbar(BASE_CONFIG);
|
|
expect(html).toContain("<script>");
|
|
expect(html).toContain("getRemaining");
|
|
expect(html).toContain("formatRemaining");
|
|
});
|
|
|
|
it("renders edit toggle unchecked when editMode is false", () => {
|
|
const html = renderPlaygroundToolbar({ ...BASE_CONFIG, editMode: false });
|
|
expect(html).toContain('id="ec-pg-edit-toggle"');
|
|
expect(html).toContain('data-edit-mode="false"');
|
|
expect(html).not.toContain('id="ec-pg-edit-toggle" checked');
|
|
});
|
|
|
|
it("renders edit toggle checked when editMode is true", () => {
|
|
const html = renderPlaygroundToolbar({ ...BASE_CONFIG, editMode: true });
|
|
expect(html).toContain('data-edit-mode="true"');
|
|
expect(html).toContain('id="ec-pg-edit-toggle" checked');
|
|
});
|
|
|
|
it("includes edit mode hover styles for data-emdash-ref elements", () => {
|
|
const html = renderPlaygroundToolbar(BASE_CONFIG);
|
|
expect(html).toContain("[data-emdash-ref]");
|
|
expect(html).toContain('data-edit-mode="true"');
|
|
});
|
|
});
|