zotero-ts-api
Version:
A TypeScript API wrapper for Zotero
74 lines • 3.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const ZTag_1 = require("./ZTag");
(0, vitest_1.describe)('ZTag', () => {
(0, vitest_1.describe)('Constructor', () => {
(0, vitest_1.it)('should create tag with name only', () => {
const data = { tag: 'science' };
const tag = new ZTag_1.ZTag(data);
(0, vitest_1.expect)(tag.name).toBe('science');
(0, vitest_1.expect)(tag.type).toBeUndefined();
});
(0, vitest_1.it)('should create tag with type', () => {
const data = { tag: 'important', type: 1 };
const tag = new ZTag_1.ZTag(data);
(0, vitest_1.expect)(tag.name).toBe('important');
(0, vitest_1.expect)(tag.type).toBe(1);
});
});
(0, vitest_1.describe)('Getters', () => {
(0, vitest_1.it)('should return correct name', () => {
const tag = new ZTag_1.ZTag({ tag: 'research' });
(0, vitest_1.expect)(tag.name).toBe('research');
});
(0, vitest_1.it)('should return correct type', () => {
const tag = new ZTag_1.ZTag({ tag: 'colored', type: 1 });
(0, vitest_1.expect)(tag.type).toBe(1);
});
});
(0, vitest_1.describe)('Setters', () => {
let tag;
(0, vitest_1.beforeEach)(() => {
tag = new ZTag_1.ZTag({ tag: 'science' });
});
(0, vitest_1.it)('should set name', () => {
tag.name = 'technology';
(0, vitest_1.expect)(tag.name).toBe('technology');
});
(0, vitest_1.it)('should set type', () => {
tag.type = 1;
(0, vitest_1.expect)(tag.type).toBe(1);
});
(0, vitest_1.it)('should allow undefined type', () => {
tag.type = undefined;
(0, vitest_1.expect)(tag.type).toBeUndefined();
});
(0, vitest_1.it)('should throw error for empty name', () => {
(0, vitest_1.expect)(() => { tag.name = ''; })
.toThrow('Tag name cannot be empty');
});
(0, vitest_1.it)('should throw error for whitespace name', () => {
(0, vitest_1.expect)(() => { tag.name = ' '; })
.toThrow('Tag name cannot be empty');
});
});
(0, vitest_1.describe)('toJSON()', () => {
(0, vitest_1.it)('should return tag data', () => {
const data = { tag: 'science', type: 1 };
const tag = new ZTag_1.ZTag(data);
const json = tag.toJSON();
(0, vitest_1.expect)(json).toEqual(data);
(0, vitest_1.expect)(json).not.toBe(data);
});
(0, vitest_1.it)('should reflect modifications', () => {
const tag = new ZTag_1.ZTag({ tag: 'science' });
tag.name = 'physics';
tag.type = 1;
const json = tag.toJSON();
(0, vitest_1.expect)(json.tag).toBe('physics');
(0, vitest_1.expect)(json.type).toBe(1);
});
});
});
//# sourceMappingURL=ZTag.test.js.map