Skip to content

Commit

Permalink
Add entry tag tests
Browse files Browse the repository at this point in the history
  • Loading branch information
perry-mitchell committed Jan 28, 2024
1 parent 9a309ae commit d35676f
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion test/unit/core/Entry.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from "chai";
import {
Entry,
EntryChangeType,
EntryPropertyValueType,
Group,
Expand All @@ -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");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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"
});
Expand Down Expand Up @@ -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();
Expand All @@ -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");
Expand Down

0 comments on commit d35676f

Please sign in to comment.