mirror of
https://github.com/home-assistant/frontend.git
synced 2026-08-15 01:22:40 +01:00
* Skip empty cells on the narrow data table secondary line
In narrow mode the main column renders every other visible column on a
secondary line, but the dot separator was inserted based on the column
index instead of whether the cell rendered anything. A row whose extra
columns are all empty showed a secondary line consisting only of dots,
and an empty column between two filled ones produced a double dot.
Filter empty cells out before joining, and return `nothing` instead of
`html`${nothing}`` for missing timestamps so those cells are detectably
empty too.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Extract / clarify data table column visibility
* Fix unbound method and add all-empty secondary line test
Co-authored-by: timmo001 <28114703+timmo001@users.noreply.github.com>
* Fix prettier formatting in ha-data-table test
Co-authored-by: timmo001 <28114703+timmo001@users.noreply.github.com>
---------
Co-authored-by: marcinbauer85 <marcinbauer85@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
53 lines
2.0 KiB
TypeScript
53 lines
2.0 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { html, nothing, render } from "lit";
|
|
import "../../src/components/data-table/ha-data-table";
|
|
import type {
|
|
DataTableColumnContainer,
|
|
DataTableRowData,
|
|
HaDataTable,
|
|
} from "../../src/components/data-table/ha-data-table";
|
|
|
|
const columns: DataTableColumnContainer = {
|
|
name: { title: "Name", main: true },
|
|
area: { title: "Area" },
|
|
category: { title: "Category" },
|
|
empty_template: { title: "Empty", template: () => nothing },
|
|
filled_template: { title: "Filled", template: () => html`filled` },
|
|
};
|
|
|
|
// The narrow row puts every non-main column on a secondary line, joined by dots.
|
|
const renderNarrowSecondary = (row: DataTableRowData) => {
|
|
const el = document.createElement("ha-data-table") as HaDataTable;
|
|
const container = document.createElement("div");
|
|
render((el as any)._renderRow(columns, true, row, 0), container);
|
|
return container.querySelector(".secondary")!.textContent!.trim();
|
|
};
|
|
|
|
describe("ha-data-table narrow secondary line", () => {
|
|
it("does not render separators for empty columns", () => {
|
|
expect(renderNarrowSecondary({ id: "1", name: "Test" })).toBe("filled");
|
|
});
|
|
|
|
it("separates only the columns that have a value", () => {
|
|
expect(
|
|
renderNarrowSecondary({ id: "1", name: "Test", area: "Kitchen" })
|
|
).toBe("Kitchen · filled");
|
|
});
|
|
|
|
it("renders a blank secondary line when all secondary columns are empty", () => {
|
|
const emptyColumns: DataTableColumnContainer = {
|
|
name: { title: "Name", main: true },
|
|
area: { title: "Area" },
|
|
category: { title: "Category" },
|
|
empty_template: { title: "Empty", template: () => nothing },
|
|
};
|
|
const el = document.createElement("ha-data-table") as HaDataTable;
|
|
const container = document.createElement("div");
|
|
render(
|
|
(el as any)._renderRow(emptyColumns, true, { id: "1", name: "Test" }, 0),
|
|
container
|
|
);
|
|
expect(container.querySelector(".secondary")!.textContent!.trim()).toBe("");
|
|
});
|
|
});
|