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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
import { describe, expect, test } from "bun:test";
import { transformProjectV3ToV4 } from "../transformers/v3-to-v4";
import { v3Project } from "./fixtures";
import { asRecordArray } from "./helpers";
describe("V3 to V4 Migration", () => {
test("normalizes legacy text fontWeight values", () => {
const projectWithLegacyTextWeight = {
...v3Project,
scenes: [
{
...v3Project.scenes[0],
tracks: [
{
id: "track-text",
type: "text",
name: "Text Track",
hidden: false,
elements: [
{
id: "text-1",
type: "text",
name: "Title",
content: "Hello",
duration: 5,
startTime: 0,
trimStart: 0,
trimEnd: 0,
fontSize: 64,
fontFamily: "Inter",
color: "#ffffff",
backgroundColor: "transparent",
textAlign: "center",
fontWeight: "bold",
fontStyle: "normal",
textDecoration: "none",
transform: {
scale: 1,
position: { x: 0, y: 0 },
rotate: 0,
},
opacity: 1,
},
],
},
],
},
],
};
const result = transformProjectV3ToV4({
project: projectWithLegacyTextWeight,
});
expect(result.skipped).toBe(false);
expect(result.project.version).toBe(4);
const migratedScene = asRecordArray(result.project.scenes)[0];
const migratedTrack = asRecordArray(migratedScene.tracks)[0];
const migratedElement = asRecordArray(migratedTrack.elements)[0];
expect(migratedElement.fontWeight).toBe("700");
});
test("does not mutate non-text tracks", () => {
const projectWithoutTextTrack = {
...v3Project,
scenes: [
{
...v3Project.scenes[0],
tracks: [
{
id: "track-sticker",
type: "sticker",
name: "Sticker Track",
hidden: false,
elements: [
{
id: "sticker-1",
type: "sticker",
name: "Flag",
iconName: "mdi:home",
duration: 5,
startTime: 0,
trimStart: 0,
trimEnd: 0,
transform: {
scale: 1,
position: { x: 0, y: 0 },
rotate: 0,
},
opacity: 1,
},
],
},
],
},
],
};
const result = transformProjectV3ToV4({ project: projectWithoutTextTrack });
const migratedScene = asRecordArray(result.project.scenes)[0];
const migratedTrack = asRecordArray(migratedScene.tracks)[0];
const migratedElement = asRecordArray(migratedTrack.elements)[0];
expect(migratedElement.iconName).toBe("mdi:home");
});
test("skips projects that are already v4", () => {
const result = transformProjectV3ToV4({
project: { ...v3Project, version: 4 },
});
expect(result.skipped).toBe(true);
expect(result.reason).toBe("already v4");
});
test("skips projects with no id", () => {
const result = transformProjectV3ToV4({
project: {
version: 3,
scenes: [],
},
});
expect(result.skipped).toBe(true);
expect(result.reason).toBe("no project id");
});
});
|