From d35676f528182f056fb8f6936cd911001a100a67 Mon Sep 17 00:00:00 2001 From: Perry Mitchell Date: Sun, 28 Jan 2024 19:23:28 +0200 Subject: [PATCH] Add entry tag tests --- test/unit/core/Entry.spec.js | 42 +++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/test/unit/core/Entry.spec.js b/test/unit/core/Entry.spec.js index 96090631..cbac4e36 100644 --- a/test/unit/core/Entry.spec.js +++ b/test/unit/core/Entry.spec.js @@ -1,5 +1,6 @@ import { expect } from "chai"; import { + Entry, EntryChangeType, EntryPropertyValueType, Group, @@ -22,6 +23,7 @@ describe("core/Entry", function () { this.group = this.vault.createGroup("test"); this.otherGroup = this.vault.createGroup("second"); this.entry = this.group.createEntry("entry"); + this.entry.setAttribute(Entry.Attributes.Tags, "one,two,three"); this.entry.setAttribute("attrib", "ok"); this.entry.setAttribute("attrib2", "also-ok"); this.entry.setProperty("metakey", "metaval"); @@ -51,6 +53,31 @@ describe("core/Entry", function () { }); }); + describe("addTags", function () { + it("adds tags", function () { + this.entry.addTags("four", "five"); + expect(this.entry.getTags()).to.deep.equal([ + "one", + "two", + "three", + "four", + "five" + ]); + }); + + it("throws adding tags with invalid characters", function () { + expect(() => { + this.entry.addTags("ok", "!"); + }).to.throw(/Invalid format/i); + }); + + it("throws adding empty", function () { + expect(() => { + this.entry.addTags("ok", ""); + }).to.throw(/Invalid format/i); + }); + }); + describe("delete", function () { it("moves itself to the Trash group", function () { const trash = this.vault.getTrashGroup(); @@ -94,7 +121,7 @@ describe("core/Entry", function () { }); it("returns an object if no parameter is provided", function () { - expect(this.entry.getAttribute()).to.deep.equal({ + expect(this.entry.getAttribute()).to.deep.include({ attrib: "ok", attrib2: "also-ok" }); @@ -218,6 +245,12 @@ describe("core/Entry", function () { }); }); + describe("getTags", function () { + it("returns an array of strings", function () { + expect(this.entry.getTags()).to.deep.equal(["one", "two", "three"]); + }); + }); + describe("getURLs", function () { it("returns an array of URLs", function () { const urls = this.entry.getURLs(); @@ -243,6 +276,13 @@ describe("core/Entry", function () { }); }); + describe("removeTags", function () { + it("removes tags", function () { + this.entry.removeTags("one", "two"); + expect(this.entry.getTags()).to.deep.equal(["three"]); + }); + }); + describe("setAttribute", function () { it("sets attributes", function () { this.entry.setAttribute("one", "two");