recogito-client-core/test/WebAnnotationTest.js

68 lines
1.8 KiB
JavaScript

import assert from 'assert';
import WebAnnotation from "../src/WebAnnotation";
const fixtureAnnotation = {
"@context": "http://www.w3.org/ns/anno.jsonld",
type: "Annotation",
body: [
{
type: "TextualBody",
value: "This annotation was added via JS."
}
],
target: {
selector: [
{
type: "TextQuoteSelector",
exact: "that ingenious hero"
},
{
type: "TextPositionSelector",
start: 38,
end: 57
}
]
}
};
describe("WebAnnotation", function() {
describe("#isEqual()", function() {
it("should return true if the other is the same object", () => {
const a = new WebAnnotation(fixtureAnnotation);
const b = new WebAnnotation(fixtureAnnotation);
assert(a.isEqual(b));
});
it("should return false if either annotation has no ID set", () => {
const a = new WebAnnotation({
...fixtureAnnotation,
id: "https://www.example.com/anno1"
});
const b = new WebAnnotation({ ...fixtureAnnotation });
assert.strictEqual(a.isEqual(b), false);
assert.strictEqual(b.isEqual(a), false);
});
it("should return true iff annotation IDs do match", () => {
const a = new WebAnnotation({
...fixtureAnnotation,
id: "https://www.example.com/anno1"
});
const b = new WebAnnotation({
...fixtureAnnotation,
id: "https://www.example.com/anno2"
});
const c = new WebAnnotation({
...fixtureAnnotation,
id: "https://www.example.com/anno1",
body: [
{
type: "TextualBody",
value: "foobar"
}
]
});
assert.strictEqual(a.isEqual(b), false);
assert.strictEqual(a.isEqual(c), true);
});
});
});