1
0
mirror of https://github.com/koloml/furbooru-tagging-assistant.git synced 2025-12-23 23:02:58 +00:00

Covering tag-related util function with tests

This commit is contained in:
2025-06-25 19:29:07 +04:00
parent 4060e6c44b
commit fb626a3928

View File

@@ -0,0 +1,33 @@
import { buildTagsAndAliasesMap } from "$lib/booru/tag-utils";
describe('buildTagsAndAliasesMap', () => {
const exampleTag = 'safe';
const exampleTagAlias = 'rating:safe';
const tagsAndAliases = [exampleTag, exampleTagAlias, 'anthro', 'cat', 'feline', 'mammal', 'male', 'boy'];
const tagsOnly = [exampleTag, 'anthro', 'cat', 'feline', 'mammal', 'male'];
const mapping = buildTagsAndAliasesMap(tagsAndAliases, tagsOnly);
it('should return a map of tags', () => {
expect(mapping).toBeInstanceOf(Map);
});
it('should point aliases to their original tags', () => {
expect(mapping.get(exampleTagAlias)).toBe(exampleTag);
});
it('should point tags to themselves', () => {
expect(mapping.get(exampleTag)).toBe(exampleTag);
});
it('should ignore broken tag aliases and show a warning', () => {
vi.spyOn(console, 'warn');
const brokenMapping = buildTagsAndAliasesMap(
['broken alias', 'tag1', 'tag2'],
['tag1', 'tag2'],
);
expect(console.warn).toBeCalledTimes(1);
expect(brokenMapping.has('broken alias')).toBe(false);
});
});