Skip to content

Commit 88db86f

Browse files
committed
test: fix attributesNS test
1 parent 2b1b02f commit 88db86f

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

handleEdit.spec.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,23 @@ describe("handleEdit", () => {
180180
),
181181
));
182182

183+
it("applies the last attribute of the same unprefixed name, per namespace", () => {
184+
const element = sclDoc.createElement("test");
185+
const xmlTextBefore = new XMLSerializer().serializeToString(element);
186+
const testEdit = {
187+
element,
188+
attributes: {},
189+
attributesNS: { "http://a.aa": { "A:Y": null, "B:Y": "abc", Y: "" } },
190+
};
191+
const undo = handleEdit(testEdit);
192+
expect(element.getAttributeNS("http://a.aa", "Y")).to.equal("");
193+
194+
handleEdit(undo);
195+
expect(new XMLSerializer().serializeToString(element)).to.equal(
196+
xmlTextBefore,
197+
);
198+
});
199+
183200
it("updates attributes given SetAttributes", () =>
184201
assert(
185202
property(
@@ -196,24 +213,22 @@ describe("handleEdit", () => {
196213
edit.attributesNS,
197214
)
198215
.map((entry) => entry as [string, Record<string, string | null>])
199-
.every(([ns, attributes]) =>
200-
Object.entries(attributes)
201-
.filter(([name]) => xmlAttributeName.test(name))
202-
.map((entry) => entry as [string, string | null])
203-
.every(
204-
([name, value]) =>
205-
edit.element.getAttributeNS(
206-
ns,
207-
name.includes(":")
208-
? <string>name.split(":", 2)[1]
209-
: name,
210-
) === value,
211-
),
212-
);
216+
.every(([ns, attributes]) => {
217+
const unprefixedAttributes = Object.fromEntries(
218+
Object.entries(attributes)
219+
.filter(([name]) => xmlAttributeName.test(name))
220+
.map((entry) => entry as [string, string | null])
221+
.map(([name, value]) => [name.split(":", 2).pop(), value])
222+
.filter(([name]) => name),
223+
);
224+
return Object.entries(unprefixedAttributes).every(
225+
([name, value]) =>
226+
edit.element.getAttributeNS(ns, name!) === value,
227+
);
228+
});
213229
return attributesHandledCorrectly && attributesNSHandledCorrectly;
214230
},
215231
),
216-
{ seed: 847773831 },
217232
)).timeout(20000);
218233

219234
it("removes elements given Removes", () =>

0 commit comments

Comments
 (0)