mirror of
https://github.com/home-assistant/frontend.git
synced 2026-10-01 17:29:02 +01:00
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { getDeviceClassOptions } from "../../src/components/ha-device-class-picker";
|
|
import type { LocalizeFunc } from "../../src/common/translations/localize";
|
|
|
|
const localize = ((key: string) =>
|
|
key === "component.sensor.entity_component.temperature.name"
|
|
? "Temperature"
|
|
: "") as LocalizeFunc;
|
|
|
|
describe("getDeviceClassOptions", () => {
|
|
it("labels a device class with its translated name", () => {
|
|
const options = getDeviceClassOptions("sensor", localize);
|
|
|
|
expect(options).toContainEqual({
|
|
id: "temperature",
|
|
primary: "Temperature",
|
|
sorting_label: "Temperature",
|
|
});
|
|
});
|
|
|
|
it("falls back to the device class itself when it has no translated name", () => {
|
|
const options = getDeviceClassOptions("sensor", localize);
|
|
|
|
expect(options.every((option) => option.primary)).toBe(true);
|
|
expect(options).toContainEqual({
|
|
id: "humidity",
|
|
primary: "humidity",
|
|
sorting_label: "humidity",
|
|
});
|
|
});
|
|
|
|
it("returns no option for a domain without device classes", () => {
|
|
expect(getDeviceClassOptions("light", localize)).toEqual([]);
|
|
});
|
|
});
|