import { resolve } from "node:path";
import { describe, expect, it } from "vitest";
import { render } from "@testing-library/preact";
import { snapshotFixtures } from "../../test/snapshot.js";
import { snapshotStylesheet } from "../../test/stylesheet.js";
import { Settle } from "./Settle.js";
import { fixtures } from "./Settle.fixtures.js";
snapshotFixtures(Settle, fixtures);
// jsdom runs no animations; the motion tier proves the fade. What jsdom can
// prove is the identity contract the fade rests on (DL 6.9.1): a changed `on`
// replaces the node, an unchanged one keeps it.
describe("Settle identity", () => {
it("replaces the node when the value changes", () => {
const { container, rerender } = render(6 people);
const before = container.firstElementChild;
rerender(7 people);
expect(container.firstElementChild).not.toBe(before);
expect(container.textContent).toContain("7 people");
});
it("keeps the node when the value did not change", () => {
const { container, rerender } = render(6 people);
const before = container.firstElementChild;
rerender(6 people);
expect(container.firstElementChild).toBe(before);
});
it("treats a changed branch name and a count falling to zero as changes", () => {
const a = render(Join);
const before = a.container.firstElementChild;
a.rerender(Joined);
expect(a.container.firstElementChild).not.toBe(before);
const b = render(1);
const one = b.container.firstElementChild;
b.rerender(0);
expect(b.container.firstElementChild).not.toBe(one);
});
});
snapshotStylesheet(resolve(__dirname, "./Settle.css"));