-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Edit and EditV2 type guards
- Loading branch information
1 parent
898c4e3
commit 7d5f002
Showing
4 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { expect } from "@open-wc/testing"; | ||
|
||
import { isEdit, Update } from "./editv1.js"; | ||
import { Insert, Remove, SetAttributes, SetTextContent } from "./editv2.js"; | ||
|
||
const element = new DOMParser().parseFromString( | ||
"<SCL />", | ||
"application/xml", | ||
)!.documentElement; | ||
|
||
const update: Update = { element, attributes: {} }; | ||
const insert: Insert = { parent: element, node: element, reference: null }; | ||
const remove: Remove = { node: element }; | ||
const setAttributes: SetAttributes = { | ||
element, | ||
attributes: {}, | ||
attributesNS: {}, | ||
}; | ||
const setTextContent: SetTextContent = { element, textContent: "" }; | ||
|
||
describe("type guard functions for editv1", () => { | ||
it("returns false on invalid Edit type", () => | ||
expect("invalid edit").to.not.satisfy(isEdit)); | ||
|
||
it("returns false on Update", () => expect(update).to.satisfy(isEdit)); | ||
|
||
it("returns true for Insert", () => expect(insert).to.satisfy(isEdit)); | ||
|
||
it("returns true for Remove", () => expect(remove).to.satisfy(isEdit)); | ||
|
||
it("returns false for SetAttributes", () => | ||
expect(setAttributes).to.not.satisfy(isEdit)); | ||
|
||
it("returns true for SetTextContent", () => | ||
expect(setTextContent).to.not.satisfy(isEdit)); | ||
|
||
it("returns false on mixed edit and editV2 array", () => | ||
expect([update, setAttributes]).to.not.satisfy(isEdit)); | ||
|
||
it("returns true on edit array", () => | ||
expect([update, remove, insert]).to.satisfy(isEdit)); | ||
|
||
it("returns false on editV2 array", () => | ||
expect([setAttributes, remove, insert, setTextContent]).to.not.satisfy(isEdit)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { expect } from "@open-wc/testing"; | ||
|
||
import { Update } from "./editv1.js"; | ||
import { | ||
Insert, | ||
isEditV2, | ||
Remove, | ||
SetAttributes, | ||
SetTextContent, | ||
} from "./editv2.js"; | ||
|
||
const element = new DOMParser().parseFromString( | ||
"<SCL />", | ||
"application/xml", | ||
)!.documentElement; | ||
|
||
const update: Update = { element, attributes: {} }; | ||
const insert: Insert = { parent: element, node: element, reference: null }; | ||
const remove: Remove = { node: element }; | ||
const setAttributes: SetAttributes = { | ||
element, | ||
attributes: {}, | ||
attributesNS: {}, | ||
}; | ||
const setTextContent: SetTextContent = { element, textContent: "" }; | ||
|
||
describe("type guard functions for editv2", () => { | ||
it("returns false on invalid Edit type", () => | ||
expect("invalid edit").to.not.satisfy(isEditV2)); | ||
|
||
it("returns false on Update", () => expect(update).to.not.satisfy(isEditV2)); | ||
|
||
it("returns true for Insert", () => expect(insert).to.satisfy(isEditV2)); | ||
|
||
it("returns true for Remove", () => expect(remove).to.satisfy(isEditV2)); | ||
|
||
it("returns true for SetAttributes", () => | ||
expect(setAttributes).to.satisfy(isEditV2)); | ||
|
||
it("returns true for SetTextContent", () => | ||
expect(setTextContent).to.satisfy(isEditV2)); | ||
|
||
it("returns false on mixed edit and editV2 array", () => | ||
expect([update, setAttributes]).to.not.satisfy(isEditV2)); | ||
|
||
it("returns false on edit array", () => | ||
expect([update, update]).to.not.satisfy(isEditV2)); | ||
|
||
it("returns true on editV2 array", () => | ||
expect([setAttributes, remove, insert, setTextContent]).to.satisfy( | ||
isEditV2, | ||
)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters