fix(import): autofix missing shapes for sidebars and some sections as well (#2723)

This commit is contained in:
Meier Lukas
2025-03-28 17:44:11 +01:00
committed by GitHub
parent 217818573e
commit 62c7955e48
4 changed files with 113 additions and 44 deletions

View File

@@ -0,0 +1,53 @@
import { describe, expect, test } from "vitest";
import type { BoardSize } from "@homarr/old-schema";
import { hasEnoughItemShapes } from "../collections/board-collection";
const defaultShape = {
location: {
x: 0,
y: 0,
},
size: {
width: 1,
height: 1,
},
};
describe("hasEnoughItemShapes should check if there are more than one shape available for automatic reconstruction", () => {
test.each([
[true, [], []], // no items, so nothing to check
[true, [{ lg: true }], []], // lg always exists
[true, [], [{ md: true }]], // md always exists
[true, [{ md: true, sm: true }], [{ md: true, lg: true }]], // md always exists
[true, [{ md: true }], [{ md: true }]], // md always exists
[false, [{ md: true }, { md: true }], [{ lg: true }]], // md is missing for widgets
[false, [{ md: true }], [{ lg: true }]], // md is missing for widgets
[false, [{ md: true }], [{ md: true, lg: true }, { lg: true }]], // md is missing for 2. widget
] as [boolean, Shape[], Shape[]][])(
"should return %s if there are more than one shape available",
(returnValue, appShapes, widgetShapes) => {
const result = hasEnoughItemShapes({
apps: appShapes.map((shapes) => ({
shape: {
sm: shapes.sm ? defaultShape : undefined,
md: shapes.md ? defaultShape : undefined,
lg: shapes.lg ? defaultShape : undefined,
},
})),
widgets: widgetShapes.map((shapes) => ({
shape: {
sm: shapes.sm ? defaultShape : undefined,
md: shapes.md ? defaultShape : undefined,
lg: shapes.lg ? defaultShape : undefined,
},
})),
});
expect(result).toBe(returnValue);
},
);
});
type Shape = Partial<Record<BoardSize, true>>;