-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #648 from maxwroc/FixMinMaxGroup
Fixed min/max setting on groups
- Loading branch information
Showing
5 changed files
with
148 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { BatteryStateCard } from "../../src/custom-elements/battery-state-card"; | ||
import { CardElements, HomeAssistantMock } from "../helpers"; | ||
|
||
describe("Grouping", () => { | ||
test.each([ | ||
[["10", "24", "25", "26", "50"], 25, "10 %|24 %", "25 %|26 %|50 %"], | ||
[["10.1", "24.2", "25.3", "26.4", "50.5"], 25, "10,1 %|24,2 %", "25,3 %|26,4 %|50,5 %", ","], | ||
[["10.1", "24.2", "25.3", "26.4", "50.5"], 25, "10.1 %|24.2 %", "25.3 %|26.4 %|50.5 %", "."], | ||
])("works with 'min' setting", async (entityStates: string[], min: number, ungrouped: string, inGroup: string, decimalPoint = ".") => { | ||
|
||
const hass = new HomeAssistantMock<BatteryStateCard>(); | ||
const entities = entityStates.map((state, i) => { | ||
const batt = hass.addEntity(`Batt ${i + 1}`, state); | ||
return batt.entity_id; | ||
}); | ||
const groupEntity = hass.addEntity("My group", "30", { entity_id: entities }, "group"); | ||
|
||
hass.mockFunc("formatEntityState", (entityData: any) => `${entityData.state.replace(".", decimalPoint)} %`); | ||
|
||
const cardElem = hass.addCard("battery-state-card", { | ||
title: "Header", | ||
entities: [], | ||
//sort: "state", | ||
collapse: [ | ||
{ | ||
group_id: groupEntity.entity_id, | ||
min | ||
} | ||
] | ||
}); | ||
|
||
// waiting for card to be updated/rendered | ||
await cardElem.cardUpdated; | ||
|
||
const card = new CardElements(cardElem); | ||
|
||
const ungroupedStates = card.items.map(e => e.stateText).join("|"); | ||
expect(ungroupedStates).toBe(ungrouped); | ||
|
||
expect(card.groupsCount).toBe(1); | ||
|
||
const groupStates = card.group(0).items.map(e => e.stateText).join("|"); | ||
expect(groupStates).toBe(inGroup); | ||
}); | ||
|
||
test.each([ | ||
[["10", "24", "25", "26", "50"], "Min {min}, Max {max}, Range {range}, Count {count}", "Min 25, Max 50, Range 25-50, Count 3"], | ||
])("secondary info keywords", async (entityStates: string[], secondaryInfo: string, expectedSecondaryInfo: string) => { | ||
|
||
const hass = new HomeAssistantMock<BatteryStateCard>(); | ||
const entities = entityStates.map((state, i) => { | ||
const batt = hass.addEntity(`Batt ${i + 1}`, state); | ||
return batt.entity_id; | ||
}); | ||
const groupEntity = hass.addEntity("My group", "30", { entity_id: entities }, "group"); | ||
|
||
const cardElem = hass.addCard("battery-state-card", { | ||
title: "Header", | ||
entities: [], | ||
//sort: "state", | ||
collapse: [ | ||
{ | ||
group_id: groupEntity.entity_id, | ||
min: 25, | ||
secondary_info: secondaryInfo | ||
} | ||
] | ||
}); | ||
|
||
// waiting for card to be updated/rendered | ||
await cardElem.cardUpdated; | ||
|
||
const card = new CardElements(cardElem); | ||
|
||
expect(card.groupsCount).toBe(1); | ||
expect(card.group(0).secondaryInfoText).toBe(expectedSecondaryInfo); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters