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:
33
tests/lib/booru/tag-utils.spec.ts
Normal file
33
tests/lib/booru/tag-utils.spec.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user