X-Git-Url: https://git.ladys.computer/Etiquette/blobdiff_plain/e3a2a78fdfb9d913f311ff1948038dfbcb758a05..e20983aca1b36dd368d52e02ee018c2eaf0ca55f:/model.test.js diff --git a/model.test.js b/model.test.js index a648d4f..74f73da 100644 --- a/model.test.js +++ b/model.test.js @@ -105,13 +105,13 @@ describe("TagSystem", () => { }); it("[[Construct]] defaults the preferred label to the empty string", () => { - assertStrictEquals(new Tag().prefLabel, ""); + assertEquals({ ...new Tag().prefLabel }, { "@value": "" }); }); it("[[Construct]] correctly sets the preferred label to a simple string", () => { - assertStrictEquals( - new Tag("RelationshipTag", "Shadow, Me").prefLabel, - "Shadow, Me", + assertEquals( + { ...new Tag("RelationshipTag", "Shadow, Me").prefLabel }, + { "@value": "Shadow, Me" }, ); }); @@ -140,6 +140,12 @@ describe("TagSystem", () => { }); }); + describe(".For", () => { + it("[[Has]] is not present", () => { + assertFalse("For" in Tag); + }); + }); + describe(".all", () => { it("[[Call]] yields all the persisted tags", () => { const tags = new Set(function* () { @@ -186,8 +192,10 @@ describe("TagSystem", () => { ); }); - it("[[Call]] returns null if passed an invalid I·R·I", () => { - assertStrictEquals(Tag.fromIRI(`bad iri`), null); + it("[[Call]] throws if passed an invalid I·R·I", () => { + assertThrows(() => { + Tag.fromIRI(`bad iri`); + }); }); }); @@ -233,11 +241,11 @@ describe("TagSystem", () => { it("[[Call]] returns null if no tag with the given Tag U·R·I has been persisted", () => { assertStrictEquals( - Tag.fromIRI(`tag:${system.taggingEntity}:`), + Tag.fromTagURI(`tag:${system.taggingEntity}:`), null, ); assertStrictEquals( - Tag.fromIRI(`tag:${system.taggingEntity}:000-0000`), + Tag.fromTagURI(`tag:${system.taggingEntity}:000-0000`), null, ); }); @@ -295,17 +303,19 @@ describe("TagSystem", () => { { "@value": "three", "@language": "en" }, ); assertEquals( - Array.from( - tag.altLabels(), - ($) => typeof $ == "string" ? $ : { ...$ }, - ), + Array.from(tag.altLabels(), ($) => ({ ...$ })), [ - "one", - "two", + { "@value": "one" }, + { "@value": "two" }, { "@value": "three", "@language": "en" }, ], ); }); + + it("[[Call]] returns this", () => { + const tag = new Tag(); + assertStrictEquals(tag.addAltLabel(), tag); + }); }); describe("::addBroaderTag", () => { @@ -328,6 +338,11 @@ describe("TagSystem", () => { ); }); + it("[[Call]] returns this", () => { + const tag = new Tag(); + assertStrictEquals(tag.addBroaderTag(), tag); + }); + it("[[Call]] throws when adding a non‐persisted tag", () => { const tag = new Tag(); assertThrows(() => { @@ -361,17 +376,19 @@ describe("TagSystem", () => { { "@value": "three", "@language": "en" }, ); assertEquals( - Array.from( - tag.hiddenLabels(), - ($) => typeof $ == "string" ? $ : { ...$ }, - ), + Array.from(tag.hiddenLabels(), ($) => ({ ...$ })), [ - "one", - "two", + { "@value": "one" }, + { "@value": "two" }, { "@value": "three", "@language": "en" }, ], ); }); + + it("[[Call]] returns this", () => { + const tag = new Tag(); + assertStrictEquals(tag.addHiddenLabel(), tag); + }); }); describe("::addInCanonTag", () => { @@ -394,9 +411,16 @@ describe("TagSystem", () => { ); }); + it("[[Call]] returns this", () => { + const tag = new Tag("EntityTag"); + assertStrictEquals(tag.addInCanonTag(), tag); + }); + it("[[Call]] throws when this is not a tag which can be placed in canon", () => { + const canon = new Tag("CanonTag"); + canon.persist(); assertThrows(() => { - new Tag().addInCanonTag(); + new Tag().addInCanonTag(canon); }); }); @@ -447,9 +471,16 @@ describe("TagSystem", () => { ); }); + it("[[Call]] returns this", () => { + const tag = new Tag("ConceptualTag"); + assertStrictEquals(tag.addInvolvesTag(), tag); + }); + it("[[Call]] throws when this is not a conceptual tag", () => { + const involved = new Tag(); + involved.persist(); assertThrows(() => { - new Tag().addInvolvesTag(); + new Tag().addInvolvesTag(involved); }); }); @@ -528,7 +559,10 @@ describe("TagSystem", () => { const tag = new Tag(); tag.addAltLabel("etaoin"); tag.deleteAltLabel(); - assertEquals([...tag.altLabels()], ["etaoin"]); + assertEquals( + Array.from(tag.altLabels(), ($) => ({ ...$ })), + [{ "@value": "etaoin" }], + ); }); it("[[Call]] deletes only the provided hidden labels", () => { @@ -545,7 +579,15 @@ describe("TagSystem", () => { { "@value": "three", "@language": "en" }, { "@value": "four", "@language": "en" }, ); - assertEquals([...tag.altLabels()], ["four"]); + assertEquals( + Array.from(tag.altLabels(), ($) => ({ ...$ })), + [{ "@value": "four" }], + ); + }); + + it("[[Call]] returns this", () => { + const tag = new Tag(); + assertStrictEquals(tag.deleteAltLabel(), tag); }); }); @@ -579,6 +621,11 @@ describe("TagSystem", () => { [broader2.identifier], ); }); + + it("[[Call]] returns this", () => { + const tag = new Tag(); + assertStrictEquals(tag.deleteBroaderTag(), tag); + }); }); describe("::deleteHiddenLabel", () => { @@ -586,7 +633,10 @@ describe("TagSystem", () => { const tag = new Tag(); tag.addHiddenLabel("etaoin"); tag.deleteHiddenLabel(); - assertEquals([...tag.hiddenLabels()], ["etaoin"]); + assertEquals( + Array.from(tag.hiddenLabels(), ($) => ({ ...$ })), + [{ "@value": "etaoin" }], + ); }); it("[[Call]] deletes only the provided alternative labels", () => { @@ -603,7 +653,15 @@ describe("TagSystem", () => { { "@value": "three", "@language": "en" }, { "@value": "four", "@language": "en" }, ); - assertEquals([...tag.hiddenLabels()], ["four"]); + assertEquals( + Array.from(tag.hiddenLabels(), ($) => ({ ...$ })), + [{ "@value": "four" }], + ); + }); + + it("[[Call]] returns this", () => { + const tag = new Tag(); + assertStrictEquals(tag.deleteHiddenLabel(), tag); }); }); @@ -633,6 +691,11 @@ describe("TagSystem", () => { [canon2.identifier], ); }); + + it("[[Call]] returns this", () => { + const tag = new Tag("EntityTag"); + assertStrictEquals(tag.deleteInCanonTag(), tag); + }); }); describe("::deleteInvolvesTag", () => { @@ -665,6 +728,11 @@ describe("TagSystem", () => { [involved2.identifier], ); }); + + it("[[Call]] returns this", () => { + const tag = new Tag("ConceptualTag"); + assertStrictEquals(tag.deleteInvolvesTag(), tag); + }); }); describe("::hasInCanonTags", () => { @@ -713,6 +781,8 @@ describe("TagSystem", () => { // `::iri` is tested by a `.fromIRI`. + // `::iriSpace` is tested by a `.fromIRI`. + // `::kind` is tested by the constructor. describe("::narrowerTags", () => { @@ -864,9 +934,9 @@ describe("TagSystem", () => { it("[[Set]] sets the preferred label", () => { const tag = new Tag(); tag.prefLabel = "one"; - assertStrictEquals(tag.prefLabel, "one"); + assertEquals({ ...tag.prefLabel }, { "@value": "one" }); tag.prefLabel = { "@value": "two" }; - assertStrictEquals(tag.prefLabel, "two"); + assertEquals({ ...tag.prefLabel }, { "@value": "two" }); tag.prefLabel = { "@value": "three", "@language": "en" }; assertEquals( { ...tag.prefLabel }, @@ -978,6 +1048,25 @@ describe("TagSystem", () => { }); }); + describe("::iriSpace", () => { + it("[[Get]] returns the I·R·I space", () => { + const system = new TagSystem("etaoin.example", "1972-12-31"); + assertStrictEquals( + system.iriSpace, + "https://etaoin.example/tag:etaoin.example,1972-12-31:", + ); + const system2 = new TagSystem( + "etaoin.example", + "1972-12-31", + "etaoin", + ); + assertStrictEquals( + system2.iriSpace, + "https://etaoin.example/tag:etaoin.example,1972-12-31:", + ); + }); + }); + describe("::tagURI", () => { it("[[Get]] returns the Tag U·R·I", () => { const system = new TagSystem("etaoin.example", "1972-12-31");