diff --git a/src/components/ui/__tests__/FetchedTags.spec.js b/src/components/ui/__tests__/FetchedTags.spec.js new file mode 100644 index 000000000..3c658a80e --- /dev/null +++ b/src/components/ui/__tests__/FetchedTags.spec.js @@ -0,0 +1,81 @@ +import { describe, expect, it } from 'vitest'; +import { createWrapper } from 'app/test/vitest/helper'; +import FetchedTags from 'src/components/ui/FetchedTags.vue'; + +describe('tags computed property', () => { + it('returns an object with the correct keys and values', () => { + const vm = createWrapper(FetchedTags, { + props: { + item: { + tag1: 'JavaScript', + value1: 'Programming Language', + tag2: 'Vue', + value2: 'Framework', + tag3: 'EmptyTag', + }, + tag: 'tag', + value: 'value', + columns: 2, + }, + }).vm; + expect(vm.tags).toEqual({ + JavaScript: 'Programming Language', + Vue: 'Framework', + EmptyTag: '', + }); + }); + + it('returns an empty object if the item prop is an empty object', () => { + const vm = createWrapper(FetchedTags, { + props: { + item: {}, + tag: 'tag', + value: 'value', + }, + }).vm; + expect(vm.tags).toEqual({}); + }); + + it('should calculate the correct columnStyle when columns prop is defined', () => { + const vm = createWrapper(FetchedTags, { + props: { + item: { + tag1: 'JavaScript', + value1: 'Programming Language', + tag2: 'Vue', + value2: 'Framework', + tag3: 'EmptyTag', + }, + tag: 'tag', + value: 'value', + columns: 2, + }, + }).vm; + + const expectedStyle = { + 'grid-template-columns': 'repeat(2, 1fr)', + 'max-width': '8rem', + }; + + expect(vm.columnStyle).toEqual(expectedStyle); + }); + + it('should return an empty object for columnStyle when columns prop is not defined', () => { + const vm = createWrapper(FetchedTags, { + props: { + item: { + tag1: 'JavaScript', + value1: 'Programming Language', + tag2: 'Vue', + value2: 'Framework', + tag3: 'EmptyTag', + }, + tag: 'tag', + value: 'value', + columns: null, + }, + }).vm; + + expect(vm.columnStyle).toEqual({}); + }); +});