mirror of
https://github.com/home-assistant/frontend.git
synced 2026-05-08 17:28:46 +01:00
Add experimental sections view (#19846)
This commit is contained in:
@@ -1,63 +1,12 @@
|
||||
import { assert } from "chai";
|
||||
|
||||
import { LovelaceConfig } from "../../../../src/data/lovelace/config/types";
|
||||
import {
|
||||
swapCard,
|
||||
moveCard,
|
||||
moveCardToContainer,
|
||||
swapView,
|
||||
} from "../../../../src/panels/lovelace/editor/config-util";
|
||||
import { LovelaceConfig } from "../../../../src/data/lovelace/config/types";
|
||||
|
||||
describe("swapCard", () => {
|
||||
it("swaps 2 cards in same view", () => {
|
||||
const config: LovelaceConfig = {
|
||||
views: [
|
||||
{},
|
||||
{
|
||||
cards: [{ type: "card1" }, { type: "card2" }],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = swapCard(config, [1, 0], [1, 1]);
|
||||
const expected = {
|
||||
views: [
|
||||
{},
|
||||
{
|
||||
cards: [{ type: "card2" }, { type: "card1" }],
|
||||
},
|
||||
],
|
||||
};
|
||||
assert.deepEqual(expected, result);
|
||||
});
|
||||
|
||||
it("swaps 2 cards in different views", () => {
|
||||
const config: LovelaceConfig = {
|
||||
views: [
|
||||
{
|
||||
cards: [{ type: "v1-c1" }, { type: "v1-c2" }],
|
||||
},
|
||||
{
|
||||
cards: [{ type: "v2-c1" }, { type: "v2-c2" }],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = swapCard(config, [0, 0], [1, 1]);
|
||||
const expected: LovelaceConfig = {
|
||||
views: [
|
||||
{
|
||||
cards: [{ type: "v2-c2" }, { type: "v1-c2" }],
|
||||
},
|
||||
{
|
||||
cards: [{ type: "v2-c1" }, { type: "v1-c1" }],
|
||||
},
|
||||
],
|
||||
};
|
||||
assert.deepEqual(expected, result);
|
||||
});
|
||||
});
|
||||
|
||||
describe("moveCard", () => {
|
||||
describe("moveCardToContainer", () => {
|
||||
it("move a card to an empty view", () => {
|
||||
const config: LovelaceConfig = {
|
||||
views: [
|
||||
@@ -68,7 +17,7 @@ describe("moveCard", () => {
|
||||
],
|
||||
};
|
||||
|
||||
const result = moveCard(config, [1, 0], [0]);
|
||||
const result = moveCardToContainer(config, [1, 0], [0]);
|
||||
const expected: LovelaceConfig = {
|
||||
views: [
|
||||
{
|
||||
@@ -94,7 +43,7 @@ describe("moveCard", () => {
|
||||
],
|
||||
};
|
||||
|
||||
const result = moveCard(config, [1, 0], [0]);
|
||||
const result = moveCardToContainer(config, [1, 0], [0]);
|
||||
const expected: LovelaceConfig = {
|
||||
views: [
|
||||
{
|
||||
@@ -121,12 +70,12 @@ describe("moveCard", () => {
|
||||
};
|
||||
|
||||
const result = () => {
|
||||
moveCard(config, [1, 0], [1]);
|
||||
moveCardToContainer(config, [1, 0], [1]);
|
||||
};
|
||||
assert.throws(
|
||||
result,
|
||||
Error,
|
||||
"You cannot move a card to the view it is in."
|
||||
"You cannot move a card to the view or section it is in."
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user