|
| 1 | +import { test, describe, afterEach, expect } from "vitest"; |
| 2 | +import { cleanup, render } from "@self/tootils/render"; |
| 3 | + |
| 4 | +import Column from "./Index.svelte"; |
| 5 | +import ColumnWithChild from "./WithChild.svelte"; |
| 6 | + |
| 7 | +describe("Column", () => { |
| 8 | + afterEach(() => cleanup()); |
| 9 | + |
| 10 | + test("renders the column container", async () => { |
| 11 | + const { container } = await render(Column, {}); |
| 12 | + // No role, label, or text available for a bare layout container — |
| 13 | + // querySelector(".column") is the appropriate query here. |
| 14 | + expect(container.querySelector(".column")).not.toBeNull(); |
| 15 | + }); |
| 16 | + |
| 17 | + test("elem_id is applied to the root div", async () => { |
| 18 | + const { container } = await render(Column, { elem_id: "my-column" }); |
| 19 | + expect(container.querySelector("#my-column")).not.toBeNull(); |
| 20 | + }); |
| 21 | + |
| 22 | + test("elem_classes are applied to the root div", async () => { |
| 23 | + const { container } = await render(Column, { |
| 24 | + elem_classes: ["my-col-class"] |
| 25 | + }); |
| 26 | + expect(container.querySelector(".my-col-class")).not.toBeNull(); |
| 27 | + }); |
| 28 | + |
| 29 | + test("visible: true → container is visible", async () => { |
| 30 | + const { container } = await render(Column, { |
| 31 | + visible: true, |
| 32 | + elem_id: "col-visible" |
| 33 | + }); |
| 34 | + expect(container.querySelector("#col-visible")).toBeVisible(); |
| 35 | + }); |
| 36 | + |
| 37 | + test("visible: false → container is hidden in the DOM", async () => { |
| 38 | + const { container } = await render(Column, { |
| 39 | + visible: false, |
| 40 | + elem_id: "col-false" |
| 41 | + }); |
| 42 | + const el = container.querySelector("#col-false"); |
| 43 | + expect(el).not.toBeNull(); |
| 44 | + expect(el).not.toBeVisible(); |
| 45 | + }); |
| 46 | + |
| 47 | + test("visible: 'hidden' does NOT hide the container (Column uses !visible — 'hidden' is truthy)", async () => { |
| 48 | + // BaseColumn uses class:hide={!visible}. "hidden" is a non-empty string and |
| 49 | + // therefore truthy, so !("hidden") === false — .hide is not applied. |
| 50 | + // Same pattern as Row. |
| 51 | + const { container } = await render(Column, { |
| 52 | + visible: "hidden", |
| 53 | + elem_id: "col-str-hidden" |
| 54 | + }); |
| 55 | + const el = container.querySelector("#col-str-hidden"); |
| 56 | + expect(el).not.toBeNull(); |
| 57 | + expect(el).toBeVisible(); |
| 58 | + }); |
| 59 | +}); |
| 60 | + |
| 61 | +describe("Children / slot", () => { |
| 62 | + afterEach(() => cleanup()); |
| 63 | + |
| 64 | + test("renders slot children inside the column container", async () => { |
| 65 | + const { getByTestId } = await render(ColumnWithChild, {}); |
| 66 | + expect(getByTestId("slot-content")).not.toBeNull(); |
| 67 | + }); |
| 68 | + |
| 69 | + test("slot children are visible when column is visible", async () => { |
| 70 | + const { getByTestId } = await render(ColumnWithChild, { visible: true }); |
| 71 | + expect(getByTestId("slot-content")).toBeVisible(); |
| 72 | + }); |
| 73 | + |
| 74 | + test("slot children are hidden when column is hidden (visible: false)", async () => { |
| 75 | + const { getByTestId } = await render(ColumnWithChild, { visible: false }); |
| 76 | + // Column applies display:none via .hide class — children inherit the hidden state |
| 77 | + expect(getByTestId("slot-content")).not.toBeVisible(); |
| 78 | + }); |
| 79 | +}); |
| 80 | + |
| 81 | +test.todo( |
| 82 | + "VISUAL: variant='panel' applies panel border, background fill, and padding to the column container — needs Playwright visual regression screenshot comparison" |
| 83 | +); |
| 84 | +test.todo( |
| 85 | + "VISUAL: variant='compact' removes border-radius from direct child elements — needs Playwright visual regression screenshot comparison" |
| 86 | +); |
| 87 | +test.todo( |
| 88 | + "VISUAL: scale prop controls flex-grow, making the column proportionally wider when scale > 1 — needs Playwright visual regression screenshot comparison" |
| 89 | +); |
| 90 | +test.todo( |
| 91 | + "VISUAL: min_width prop enforces a minimum pixel width before the column wraps to a new row — needs Playwright visual regression screenshot comparison" |
| 92 | +); |
0 commit comments