You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/core/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.test.ts
+55-1Lines changed: 55 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,8 @@ it("does not move color attributes on newer documents", async () => {
53
53
props: {
54
54
backgroundColor: "red",
55
55
textColor: "blue",
56
+
// Set to non-default value to ensure it is not overridden by the migration rule.
57
+
textAlignment: "right",
56
58
},
57
59
},
58
60
],
@@ -66,11 +68,63 @@ it("does not move color attributes on newer documents", async () => {
66
68
67
69
expect(fragment.toJSON()).toMatchInlineSnapshot(
68
70
// The color attributes are on the paragraph, not the blockContainer.
69
-
`"<blockgroup><blockcontainer id="0"><paragraph backgroundColor="red" textAlignment="left" textColor="blue">Welcome to this demo!</paragraph></blockcontainer></blockgroup>"`,
71
+
`"<blockgroup><blockcontainer id="0"><paragraph backgroundColor="red" textAlignment="right" textColor="blue">Welcome to this demo!</paragraph></blockcontainer></blockgroup>"`,
70
72
);
71
73
72
74
consttr=editor.prosemirrorState.tr;
73
75
moveColorAttributes(fragment,tr);
74
76
// The document will be unchanged because the color attributes are already on the paragraph.
75
77
expect(tr.docChanged).toBe(false);
76
78
});
79
+
80
+
it("can move color attributes on older documents multiple times",async()=>{
81
+
constdoc=newY.Doc();
82
+
constfragment=doc.getXmlFragment("doc");
83
+
consteditor=BlockNoteEditor.create({
84
+
initialContent: [
85
+
{
86
+
type: "paragraph",
87
+
content: "Welcome to this demo!",
88
+
},
89
+
],
90
+
});
91
+
92
+
// Because this was a previous schema, we are creating the YFragment manually
93
+
constblockGroup=newY.XmlElement("blockGroup");
94
+
constel=newY.XmlElement("blockContainer");
95
+
el.setAttribute("id","0");
96
+
el.setAttribute("backgroundColor","red");
97
+
el.setAttribute("textColor","blue");
98
+
constpara=newY.XmlElement("paragraph");
99
+
para.setAttribute("textAlignment","left");
100
+
para.insert(0,[newY.XmlText("Welcome to this demo!")]);
101
+
el.insert(0,[para]);
102
+
blockGroup.insert(0,[el]);
103
+
fragment.insert(0,[blockGroup]);
104
+
105
+
// Note that the blockContainer has the color attributes, but the paragraph does not.
106
+
expect(fragment.toJSON()).toMatchInlineSnapshot(
107
+
`"<blockgroup><blockcontainer backgroundColor="red" id="0" textColor="blue"><paragraph textAlignment="left">Welcome to this demo!</paragraph></blockcontainer></blockgroup>"`,
108
+
);
109
+
110
+
consttr=editor.prosemirrorState.tr;
111
+
moveColorAttributes(fragment,tr);
112
+
// Note that the color attributes have been moved to the paragraph.
`"{"type":"doc","content":[{"type":"blockGroup","content":[{"type":"blockContainer","attrs":{"id":"0"},"content":[{"type":"paragraph","attrs":{"backgroundColor":"red","textColor":"blue","textAlignment":"left"},"content":[{"type":"text","text":"Welcome to this demo!"}]}]}]}]}"`,
115
+
);
116
+
117
+
el.setAttribute("backgroundColor","green");
118
+
el.setAttribute("textColor","yellow");
119
+
120
+
expect(fragment.toJSON()).toMatchInlineSnapshot(
121
+
`"<blockgroup><blockcontainer backgroundColor="green" id="0" textColor="yellow"><paragraph textAlignment="left">Welcome to this demo!</paragraph></blockcontainer></blockgroup>"`,
122
+
);
123
+
124
+
constnextTr=editor.prosemirrorState.tr;
125
+
moveColorAttributes(fragment,nextTr);
126
+
// Note that the color attributes have been moved to the paragraph.
`"{"type":"doc","content":[{"type":"blockGroup","content":[{"type":"blockContainer","attrs":{"id":"0"},"content":[{"type":"paragraph","attrs":{"backgroundColor":"green","textColor":"yellow","textAlignment":"left"},"content":[{"type":"text","text":"Welcome to this demo!"}]}]}]}]}"`,
0 commit comments