From 85bf4053bb4b708624e29349878513c4511191ad Mon Sep 17 00:00:00 2001 From: provira Date: Thu, 2 Jan 2025 12:03:56 +0100 Subject: [PATCH 1/3] feat: refs #7088 created test for FetchedTags --- .../ui/__tests__/FetchedTags.spec.js | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/components/ui/__tests__/FetchedTags.spec.js diff --git a/src/components/ui/__tests__/FetchedTags.spec.js b/src/components/ui/__tests__/FetchedTags.spec.js new file mode 100644 index 000000000..f1c14232c --- /dev/null +++ b/src/components/ui/__tests__/FetchedTags.spec.js @@ -0,0 +1,84 @@ +import { describe, expect, it } from 'vitest'; +import { mount } from '@vue/test-utils'; +import FetchedTags from 'src/components/ui/FetchedTags.vue'; + +describe('tags computed property', () => { + it('returns an object with the correct keys and values', () => { + const wrapper = mount(FetchedTags, { + props: { + item: { + tag1: 'JavaScript', + value1: 'Programming Language', + tag2: 'Vue', + value2: 'Framework', + tag3: 'EmptyTag', + }, + tag: 'tag', + value: 'value', + columns: 2, + }, + }); + expect(wrapper.vm.tags).toEqual({ + JavaScript: 'Programming Language', + Vue: 'Framework', + EmptyTag: '', + }); + }); + + it('returns an empty object if the item prop is an empty object', () => { + const wrapper = mount(FetchedTags, { + props: { + item: {}, + tag: 'tag', + value: 'value', + }, + }); + expect(wrapper.vm.tags).toEqual({}); + }); + + // Test the computed columnStyle with a defined 'columns' prop + it('should calculate the correct columnStyle when columns prop is defined', () => { + const wrapper = mount(FetchedTags, { + props: { + item: { + tag1: 'JavaScript', + value1: 'Programming Language', + tag2: 'Vue', + value2: 'Framework', + tag3: 'EmptyTag', + }, + tag: 'tag', + value: 'value', + columns: 2, + }, + }); + + const expectedStyle = { + 'grid-template-columns': 'repeat(2, 1fr)', // Should be 3 equal columns + 'max-width': '8rem', // Should be 3 * 4rem = 12rem + }; + + expect(wrapper.vm.columnStyle).toEqual(expectedStyle); + }); + + // Test the computed columnStyle with a falsy 'columns' prop (e.g., null or undefined) + it('should return an empty object for columnStyle when columns prop is not defined', () => { + const wrapper = mount(FetchedTags, { + props: { + item: { + tag1: 'JavaScript', + value1: 'Programming Language', + tag2: 'Vue', + value2: 'Framework', + tag3: 'EmptyTag', + }, + tag: 'tag', + value: 'value', + columns: null, + }, + }); + + // Should return an empty object as no grid layout is applied + expect(wrapper.vm.columnStyle).toEqual({}); + }); +}); -- 2.40.1 From 29614ce3352cd8963ae219232b2f22f826689148 Mon Sep 17 00:00:00 2001 From: provira Date: Tue, 7 Jan 2025 07:06:23 +0100 Subject: [PATCH 2/3] fix: refs #7088 changed wrapper to vm --- .../ui/__tests__/FetchedTags.spec.js | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/components/ui/__tests__/FetchedTags.spec.js b/src/components/ui/__tests__/FetchedTags.spec.js index f1c14232c..5d23505b7 100644 --- a/src/components/ui/__tests__/FetchedTags.spec.js +++ b/src/components/ui/__tests__/FetchedTags.spec.js @@ -1,10 +1,10 @@ import { describe, expect, it } from 'vitest'; -import { mount } from '@vue/test-utils'; +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 wrapper = mount(FetchedTags, { + const vm = createWrapper(FetchedTags, { props: { item: { tag1: 'JavaScript', @@ -18,7 +18,7 @@ describe('tags computed property', () => { columns: 2, }, }); - expect(wrapper.vm.tags).toEqual({ + expect(vm.vm.tags).toEqual({ JavaScript: 'Programming Language', Vue: 'Framework', EmptyTag: '', @@ -26,19 +26,18 @@ describe('tags computed property', () => { }); it('returns an empty object if the item prop is an empty object', () => { - const wrapper = mount(FetchedTags, { + const vm = createWrapper(FetchedTags, { props: { item: {}, tag: 'tag', value: 'value', }, }); - expect(wrapper.vm.tags).toEqual({}); + expect(vm.vm.tags).toEqual({}); }); - // Test the computed columnStyle with a defined 'columns' prop it('should calculate the correct columnStyle when columns prop is defined', () => { - const wrapper = mount(FetchedTags, { + const vm = createWrapper(FetchedTags, { props: { item: { tag1: 'JavaScript', @@ -54,16 +53,15 @@ describe('tags computed property', () => { }); const expectedStyle = { - 'grid-template-columns': 'repeat(2, 1fr)', // Should be 3 equal columns - 'max-width': '8rem', // Should be 3 * 4rem = 12rem + 'grid-template-columns': 'repeat(2, 1fr)', + 'max-width': '8rem', }; - expect(wrapper.vm.columnStyle).toEqual(expectedStyle); + expect(vm.vm.columnStyle).toEqual(expectedStyle); }); - // Test the computed columnStyle with a falsy 'columns' prop (e.g., null or undefined) it('should return an empty object for columnStyle when columns prop is not defined', () => { - const wrapper = mount(FetchedTags, { + const vm = createWrapper(FetchedTags, { props: { item: { tag1: 'JavaScript', @@ -78,7 +76,6 @@ describe('tags computed property', () => { }, }); - // Should return an empty object as no grid layout is applied - expect(wrapper.vm.columnStyle).toEqual({}); + expect(vm.vm.columnStyle).toEqual({}); }); }); -- 2.40.1 From 0d3b1130f9cacb9014b6254f580e2cbb890db9bf Mon Sep 17 00:00:00 2001 From: provira Date: Wed, 8 Jan 2025 07:39:50 +0100 Subject: [PATCH 3/3] fix: refs #7088 changed "vm.vm" to "vm" --- src/components/ui/__tests__/FetchedTags.spec.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/ui/__tests__/FetchedTags.spec.js b/src/components/ui/__tests__/FetchedTags.spec.js index 5d23505b7..3c658a80e 100644 --- a/src/components/ui/__tests__/FetchedTags.spec.js +++ b/src/components/ui/__tests__/FetchedTags.spec.js @@ -17,8 +17,8 @@ describe('tags computed property', () => { value: 'value', columns: 2, }, - }); - expect(vm.vm.tags).toEqual({ + }).vm; + expect(vm.tags).toEqual({ JavaScript: 'Programming Language', Vue: 'Framework', EmptyTag: '', @@ -32,8 +32,8 @@ describe('tags computed property', () => { tag: 'tag', value: 'value', }, - }); - expect(vm.vm.tags).toEqual({}); + }).vm; + expect(vm.tags).toEqual({}); }); it('should calculate the correct columnStyle when columns prop is defined', () => { @@ -50,14 +50,14 @@ describe('tags computed property', () => { value: 'value', columns: 2, }, - }); + }).vm; const expectedStyle = { 'grid-template-columns': 'repeat(2, 1fr)', 'max-width': '8rem', }; - expect(vm.vm.columnStyle).toEqual(expectedStyle); + expect(vm.columnStyle).toEqual(expectedStyle); }); it('should return an empty object for columnStyle when columns prop is not defined', () => { @@ -74,8 +74,8 @@ describe('tags computed property', () => { value: 'value', columns: null, }, - }); + }).vm; - expect(vm.vm.columnStyle).toEqual({}); + expect(vm.columnStyle).toEqual({}); }); }); -- 2.40.1