-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathplugins.test.ts
More file actions
90 lines (79 loc) · 2.64 KB
/
Copy pathplugins.test.ts
File metadata and controls
90 lines (79 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* Copyright 2026 Marimo. All rights reserved. */
import { describe, expect, it } from "vitest";
import type { CellId } from "@/core/cells/ids";
import type { CellData } from "@/core/cells/types";
import { deserializeLayout, getCellRendererPlugin } from "../plugins";
function makeCell(id: string): CellData {
return {
id: id as CellId,
name: id,
code: "",
edited: false,
lastCodeRun: null,
lastExecutionTime: null,
config: { hide_code: false, disabled: false, column: null },
serializedEditorState: null,
};
}
describe("getCellRendererPlugin", () => {
it("returns the matching plugin keyed by layout type", () => {
expect(getCellRendererPlugin("vertical").type).toBe("vertical");
expect(getCellRendererPlugin("grid").type).toBe("grid");
expect(getCellRendererPlugin("slides").type).toBe("slides");
});
});
describe("deserializeLayout", () => {
it("deserializes valid grid layout data", () => {
const layout = deserializeLayout({
type: "grid",
data: {
columns: 12,
rowHeight: 20,
cells: [{ position: [1, 2, 3, 4] }],
},
cells: [makeCell("a")],
});
expect(layout.columns).toBe(12);
expect(layout.cells).toEqual([{ i: "a", x: 1, y: 2, w: 3, h: 4 }]);
});
it("deserializes valid slides layout data", () => {
const layout = deserializeLayout({
type: "slides",
data: {
cells: [{ type: "fragment" }],
deck: { transition: "fade" },
},
cells: [makeCell("a")],
});
expect(layout.deck).toEqual({ transition: "fade" });
expect(layout.cells.get("a" as CellId)).toEqual({ type: "fragment" });
});
it("vertical layout is always null regardless of stored data", () => {
// Older save files may have arbitrary `data` for vertical; we must
// ignore it because `VerticalLayout = null`.
const layout = deserializeLayout({
type: "vertical",
data: { something: "unexpected" },
cells: [makeCell("a")],
});
expect(layout).toBeNull();
});
it("tolerates legacy `null` for optional grid fields", () => {
// Older marimo versions wrote unset optional fields as `null`
// (e.g. `"maxWidth": null` in `layout_grid_with_sidebar.grid.json`).
// Those files must keep loading.
const layout = deserializeLayout({
type: "grid",
data: {
columns: 24,
rowHeight: 20,
maxWidth: null,
bordered: true,
cells: [{ position: [0, 0, 5, 2] }, { position: null }],
},
cells: [makeCell("a"), makeCell("b")],
});
expect(layout.columns).toBe(24);
expect(layout.cells).toEqual([{ i: "a", x: 0, y: 0, w: 5, h: 2 }]);
});
});