Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/commitlint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ export default {
"subject-case": [0],
// Allow long body lines for detailed commit descriptions
"body-max-line-length": [0],
// Allow long footer lines (e.g. issue refs, BREAKING CHANGE blocks, links)
"footer-max-line-length": [0],
},
};
257 changes: 204 additions & 53 deletions custom_components/hass_datapoints/hass-datapoints-cards.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { beforeAll, describe, expect, it, vi } from "vitest";

describe("register", () => {
beforeAll(async () => {
document.body.innerHTML = "";
(window as unknown as { customCards?: unknown[] }).customCards = [];

vi.spyOn(console, "groupCollapsed").mockImplementation(() => {});
vi.spyOn(console, "log").mockImplementation(() => {});
vi.spyOn(console, "groupEnd").mockImplementation(() => {});

await import("../register");
}, 30_000);

describe("GIVEN register.ts is loaded", () => {
describe("WHEN Lovelace custom card metadata is registered", () => {
it("THEN names use Datapoints prefix (not Hass Records/Hass Datapoints)", async () => {
expect.assertions(3);

const cards = window.customCards || [];
const names = cards.map((c) => c.name).filter(Boolean) as string[];

expect(names.length).toBeGreaterThan(0);
expect(names.every((name) => name.startsWith("Datapoints – "))).toBe(
true
);
expect(
names.some(
(name) => name.includes("Hass Records") || name.includes("Hass ")
)
).toBe(false);
});
});

describe("WHEN old hass-records tags are referenced", () => {
it("THEN deprecated aliases exist for old dashboards", async () => {
expect.assertions(8);

expect(customElements.get("hass-records-action-card")).toBeTruthy();
expect(customElements.get("hass-records-quick-card")).toBeTruthy();
expect(customElements.get("hass-records-history-card")).toBeTruthy();
expect(customElements.get("hass-records-sensor-card")).toBeTruthy();
expect(customElements.get("hass-records-list-card")).toBeTruthy();
expect(customElements.get("hass-records-dev-tool-card")).toBeTruthy();

expect(customElements.get("hass-records-statistics-card")).toBeTruthy();
expect(
customElements.get("hass-datapoints-statistics-card")
).toBeTruthy();
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createMockHass } from "@/test-support/mock-hass";
import { HassRecordsActionCard } from "../action.ts";
import { HassDatapointsActionCard } from "../action.ts";

if (!customElements.get("hass-datapoints-action-card")) {
customElements.define("hass-datapoints-action-card", HassRecordsActionCard);
customElements.define(
"hass-datapoints-action-card",
HassDatapointsActionCard
);
}

function createCard(config: RecordWithUnknownValues = {}) {
Expand Down Expand Up @@ -227,15 +230,15 @@ describe("action", () => {
describe("GIVEN the static config methods", () => {
describe("WHEN getStubConfig is called", () => {
it("THEN it returns default config", () => {
expect(HassRecordsActionCard.getStubConfig()).toEqual({
expect(HassDatapointsActionCard.getStubConfig()).toEqual({
title: "Record Event",
});
});
});

describe("WHEN getConfigElement is called", () => {
it("THEN it returns the editor element tag", () => {
const editorEl = HassRecordsActionCard.getConfigElement();
const editorEl = HassDatapointsActionCard.getConfigElement();
expect(editorEl.tagName.toLowerCase()).toBe(
"hass-datapoints-action-card-editor"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { logger } from "@/lib/logger";
* - A ha-selector (target schema) lets the user add extra items per recording.
* - On submit both are merged; the selector resets to empty afterwards.
*/
export class HassRecordsActionCard extends LitElement {
export class HassDatapointsActionCard extends LitElement {
static properties = {
_config: { state: true },
_hass: { state: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type TargetPickerElement = Element & {
value?: TargetPickerValue;
};

export class HassRecordsActionCardEditor extends EditorBase {
export class HassDatapointsActionCardEditor extends EditorBase {
static styles: CSSResultGroup = [EditorBase.styles, styles];

private _configTarget(): TargetPickerValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import type { Meta, StoryObj } from "@storybook/web-components-vite";
import { expect } from "@storybook/test";
import { html } from "lit";
import { createMockHass } from "@/test-support/mock-hass";
import { HassRecordsActionCard } from "../action";
import { HassDatapointsActionCard } from "../action";

if (!customElements.get("hass-datapoints-action-card")) {
customElements.define("hass-datapoints-action-card", HassRecordsActionCard);
customElements.define(
"hass-datapoints-action-card",
HassDatapointsActionCard
);
}

type Story = StoryObj;
Expand All @@ -17,10 +20,10 @@ const meta: Meta = {

export default meta;

function getCard(canvasElement: HTMLElement): HassRecordsActionCard {
function getCard(canvasElement: HTMLElement): HassDatapointsActionCard {
return canvasElement.querySelector(
"hass-datapoints-action-card"
) as HassRecordsActionCard;
) as HassDatapointsActionCard;
}

const mockHass = createMockHass();
Expand All @@ -29,7 +32,7 @@ export const Default: Story = {
render: () =>
html`<hass-datapoints-action-card></hass-datapoints-action-card>`,
play: async ({ canvasElement }) => {
const card = getCard(canvasElement) as HassRecordsActionCard & {
const card = getCard(canvasElement) as HassDatapointsActionCard & {
updateComplete: Promise<void>;
};
card.setConfig({ title: "Record Event" });
Expand All @@ -44,7 +47,7 @@ export const WithTargetsAndAnnotation: Story = {
render: () =>
html`<hass-datapoints-action-card></hass-datapoints-action-card>`,
play: async ({ canvasElement }) => {
const card = getCard(canvasElement) as HassRecordsActionCard & {
const card = getCard(canvasElement) as HassDatapointsActionCard & {
updateComplete: Promise<void>;
};
card.setConfig({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createMockHass } from "@/test-support/mock-hass";
import { HassRecordsDevToolCard } from "../dev-tool.ts";
import { HassDatapointsDevToolCard } from "../dev-tool.ts";

vi.mock("@/helpers.js", async (importOriginal) => {
const mod = (await importOriginal()) as RecordWithUnknownValues;
Expand All @@ -14,7 +14,7 @@ vi.mock("@/helpers.js", async (importOriginal) => {
if (!customElements.get("hass-datapoints-dev-tool-card")) {
customElements.define(
"hass-datapoints-dev-tool-card",
HassRecordsDevToolCard
HassDatapointsDevToolCard
);
}

Expand Down Expand Up @@ -186,14 +186,16 @@ describe("dev-tool", () => {
describe("WHEN getStubConfig is called", () => {
it("THEN it returns default config", () => {
expect.assertions(1);
expect(HassRecordsDevToolCard.getStubConfig()).toHaveProperty("title");
expect(HassDatapointsDevToolCard.getStubConfig()).toHaveProperty(
"title"
);
});
});

describe("WHEN getConfigElement is called", () => {
it("THEN it returns the dev-tool editor element tag", () => {
expect.assertions(1);
const editorEl = HassRecordsDevToolCard.getConfigElement();
const editorEl = HassDatapointsDevToolCard.getConfigElement();
expect(editorEl.tagName.toLowerCase()).toBe(
"hass-datapoints-dev-tool-card-editor"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import type {
WindowConfig,
WindowResult,
} from "@/cards/dev-tool/types";
import { HassRecordsDevToolCardEditor } from "./editor";
import { HassDatapointsDevToolCardEditor } from "./editor";
import "@/atoms/display/feedback-banner/feedback-banner";
import "@/cards/dev-tool/dev-tool-results/dev-tool-results";
import "@/cards/dev-tool/dev-tool-windows/dev-tool-windows";

export class HassRecordsDevToolCard extends HTMLElement {
export class HassDatapointsDevToolCard extends HTMLElement {
_config: RecordWithUnknownValues = {};

_hass: Nullable<HassLike> = null;
Expand Down Expand Up @@ -625,4 +625,4 @@ export class HassRecordsDevToolCard extends HTMLElement {
}
}

export { HassRecordsDevToolCardEditor };
export { HassDatapointsDevToolCardEditor };
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CSSResultGroup, html } from "lit";
import { msg } from "@/lib/i18n/localize";
import { EditorBase } from "@/molecules/editor-base/editor-base";

export class HassRecordsDevToolCardEditor extends EditorBase {
export class HassDatapointsDevToolCardEditor extends EditorBase {
static styles: CSSResultGroup = [EditorBase.styles];

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import type { Meta, StoryObj } from "@storybook/web-components-vite";
import { expect } from "@storybook/test";
import { html } from "lit";
import { createMockHass } from "@/test-support/mock-hass";
import { HassRecordsDevToolCard } from "../dev-tool";
import { HassDatapointsDevToolCard } from "../dev-tool";

if (!customElements.get("hass-datapoints-dev-tool-card")) {
customElements.define(
"hass-datapoints-dev-tool-card",
HassRecordsDevToolCard
HassDatapointsDevToolCard
);
}

Expand All @@ -20,10 +20,10 @@ const meta: Meta = {

export default meta;

function getCard(canvasElement: HTMLElement): HassRecordsDevToolCard {
function getCard(canvasElement: HTMLElement): HassDatapointsDevToolCard {
return canvasElement.querySelector(
"hass-datapoints-dev-tool-card"
) as HassRecordsDevToolCard;
) as HassDatapointsDevToolCard;
}

function makeMockHass() {
Expand Down Expand Up @@ -87,7 +87,7 @@ export const WithResults: Story = {
render: () =>
html`<hass-datapoints-dev-tool-card></hass-datapoints-dev-tool-card>`,
play: async ({ canvasElement }) => {
const card = getCard(canvasElement) as HassRecordsDevToolCard & {
const card = getCard(canvasElement) as HassDatapointsDevToolCard & {
_entities: string[];
_analyzeHistory: () => Promise<void>;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { afterEach, describe, expect, it } from "vitest";
import { createMockHass } from "@/test-support/mock-hass";
import { HassRecordsHistoryCardEditor } from "../editor";
import { HassDatapointsHistoryCardEditor } from "../editor";

if (!customElements.get("hass-datapoints-history-card-editor")) {
customElements.define(
"hass-datapoints-history-card-editor",
HassRecordsHistoryCardEditor
HassDatapointsHistoryCardEditor
);
}

function createEditor() {
const el = document.createElement(
"hass-datapoints-history-card-editor"
) as HassRecordsHistoryCardEditor;
) as HassDatapointsHistoryCardEditor;
document.body.appendChild(el);
el.hass = createMockHass();
el.setConfig({
Expand All @@ -34,7 +34,7 @@ function createEditor() {
}

describe("history editor", () => {
let el: Nullable<HassRecordsHistoryCardEditor> = null;
let el: Nullable<HassDatapointsHistoryCardEditor> = null;

afterEach(() => {
el?.remove();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* history.spec.ts — GIVEN/WHEN/THEN tests for HassRecordsHistoryCard.
* history.spec.ts — GIVEN/WHEN/THEN tests for HassDatapointsHistoryCard.
*
* We test the public API surface: setConfig validation/normalisation,
* _entityIds getter, static helpers, and basic rendering.
Expand Down Expand Up @@ -55,10 +55,10 @@ vi.mock("@/lib/ha/navigation", async (importOriginal) => {
});

// Import the card AFTER mocks are set up
let HassRecordsHistoryCard: typeof import("../history.ts").HassRecordsHistoryCard;
let HassDatapointsHistoryCard: typeof import("../history.ts").HassDatapointsHistoryCard;

beforeAll(async () => {
({ HassRecordsHistoryCard } = await import("../history.ts"));
({ HassDatapointsHistoryCard } = await import("../history.ts"));
});

// ── Helpers ───────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -86,7 +86,7 @@ function createMockHass(overrides = {}) {
function createCard(
config: RecordWithUnknownValues = { entity: "sensor.example" }
) {
const el = new HassRecordsHistoryCard();
const el = new HassDatapointsHistoryCard();
el.setConfig(config);
return el;
}
Expand All @@ -104,7 +104,7 @@ describe("history", () => {
describe("WHEN setConfig is called", () => {
it("THEN it throws an error", () => {
expect.assertions(1);
const el = new HassRecordsHistoryCard();
const el = new HassDatapointsHistoryCard();
expect(() => el.setConfig({})).toThrow();
});
});
Expand Down Expand Up @@ -418,7 +418,7 @@ describe("history", () => {
describe("WHEN getStubConfig is called", () => {
it("THEN it returns an object with entity and hours_to_show", () => {
expect.assertions(2);
const stub = HassRecordsHistoryCard.getStubConfig();
const stub = HassDatapointsHistoryCard.getStubConfig();
expect(stub).toHaveProperty("entity");
expect(stub).toHaveProperty("hours_to_show");
});
Expand All @@ -427,7 +427,7 @@ describe("history", () => {
describe("WHEN getConfigElement is called", () => {
it("THEN it returns the editor element tag name", () => {
expect.assertions(1);
const editor = HassRecordsHistoryCard.getConfigElement();
const editor = HassDatapointsHistoryCard.getConfigElement();
expect(editor.tagName.toLowerCase()).toBe(
"hass-datapoints-history-card-editor"
);
Expand All @@ -438,7 +438,7 @@ describe("history", () => {
// ── Rendering ────────────────────────────────────────────────────────────

describe("GIVEN a card connected to the DOM with hass", () => {
let el: HassRecordsHistoryCard;
let el: HassDatapointsHistoryCard;

beforeEach(async () => {
el = createCard({ entity: "sensor.example", title: "Test Chart" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type AnalysisChangeDetail = {
value?: unknown;
};

export class HassRecordsHistoryCardEditor extends EditorBase {
export class HassDatapointsHistoryCardEditor extends EditorBase {
static styles: CSSResultGroup = [EditorBase.styles, styles];

private _configTarget(): TargetPickerValue {
Expand Down
Loading
Loading