mirror of
https://github.com/home-assistant/frontend.git
synced 2026-08-19 03:22:25 +01:00
A state condition with match "any" joins its entities with "or", but the summary kept a plural verb for multiple entities, reading "If A or B are on". With "or" English uses singular agreement: "If A or B is on". The match "all" case joins with "and" and correctly stays plural. Nest a select on a new matchAny flag inside the multiple-entities plural branch so the verb agrees with the join. Other languages keep their count-based plural (the extra argument is ignored). Add a test that renders the actual en.json string to lock in the grammar.
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { IntlMessageFormat } from "intl-messageformat";
|
|
import { describe, expect, it } from "vitest";
|
|
import en from "../../src/translations/en.json";
|
|
|
|
// The state condition summary string. Its verb must agree with how the entity
|
|
// list is joined: "and" (match "all") takes a plural verb, "or" (match "any")
|
|
// takes a singular verb in English.
|
|
const message = (en as any).ui.panel.config.automation.editor.conditions.type
|
|
.state.description.full;
|
|
|
|
const format = (values: Record<string, unknown>) =>
|
|
new IntlMessageFormat(message, "en").format(values) as string;
|
|
|
|
describe("state condition summary grammar", () => {
|
|
it("uses a singular verb for a single entity", () => {
|
|
expect(
|
|
format({
|
|
hasAttribute: "false",
|
|
numberOfEntities: 1,
|
|
matchAny: "false",
|
|
entities: "Light",
|
|
numberOfStates: 1,
|
|
states: "on",
|
|
hasDuration: "false",
|
|
})
|
|
).toBe("If Light is on");
|
|
});
|
|
|
|
it("uses a plural verb for multiple entities matched with all (and)", () => {
|
|
expect(
|
|
format({
|
|
hasAttribute: "false",
|
|
numberOfEntities: 2,
|
|
matchAny: "false",
|
|
entities: "A and B",
|
|
numberOfStates: 1,
|
|
states: "on",
|
|
hasDuration: "false",
|
|
})
|
|
).toBe("If A and B are on");
|
|
});
|
|
|
|
it("uses a singular verb for multiple entities matched with any (or)", () => {
|
|
expect(
|
|
format({
|
|
hasAttribute: "false",
|
|
numberOfEntities: 2,
|
|
matchAny: "true",
|
|
entities: "A or B",
|
|
numberOfStates: 1,
|
|
states: "on",
|
|
hasDuration: "false",
|
|
})
|
|
).toBe("If A or B is on");
|
|
});
|
|
});
|