Skip to content

Commit cb10522

Browse files
committed
feat: unit test filtered out suggested tags
1 parent 1dbdd42 commit cb10522

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

src/components/search/FilterTags/SearchResults.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default {
4343
},
4444
props: {
4545
tagResults: {
46+
// array of tag objects
4647
type: Array,
4748
default: () => [],
4849
},
@@ -55,6 +56,7 @@ export default {
5556
default: false,
5657
},
5758
existingTags: {
59+
// array of tag ids
5860
type: Array,
5961
default: () => [],
6062
},

src/components/search/FilterTags/SuggestedTags.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ export default {
3636
},
3737
props: {
3838
currentTags: {
39+
// array of tag ids
3940
type: Array,
4041
default: () => [],
4142
},
4243
4344
suggestedTags: {
45+
// array of tag objects
4446
type: Array,
4547
default: () => [],
4648
},

src/components/search/FilterTags/TagResults.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,32 @@ export default {
6161
6262
props: {
6363
search: {
64+
// search query
6465
type: String,
6566
default: '',
6667
},
6768
classificationId: {
69+
// classification id to limit search to (if not searchAll)
6870
type: Number,
6971
default: null,
7072
},
7173
type: {
72-
type: String, // "skills" or "projects"
74+
// "skills" or "projects"
75+
type: String,
7376
default: '',
7477
},
7578
searchAll: {
79+
// search all org classification
7680
type: Boolean,
7781
default: false,
7882
},
7983
existingTags: {
84+
// array of tag ids
8085
type: Array,
8186
default: () => [],
8287
},
8388
showPreSearchList: {
89+
// shwow all tags (aka empty search) before search
8490
type: Boolean,
8591
default: false,
8692
},

tests/unit/components/search/FilterTags/SuggestedTags.spec.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { lpiShallowMount } from '../../../../helpers/LpiMount'
1+
import { lpiShallowMount, lpiMount } from '../../../../helpers/LpiMount'
22
import english from '@/locales/en.json'
33
import SuggestedTags from '@/components/search/FilterTags/SuggestedTags.vue'
44

55
import { afterEach, beforeEach, describe, expect, it, vi, Mock } from 'vitest'
6+
import { id } from 'date-fns/locale'
67
const i18n = {
78
locale: 'en',
89
fallbackLocale: 'en',
@@ -26,4 +27,46 @@ describe('SuggestedTags', () => {
2627

2728
expect(wrapper.exists()).toBeTruthy()
2829
})
30+
31+
it('should render all Suggested Tags items', () => {
32+
wrapper = lpiMount(SuggestedTags, {
33+
...defaultParams,
34+
props: {
35+
suggestedTags: [
36+
{ id: 1, title: 'tag1' },
37+
{ id: 2, title: 'tag2' },
38+
{ id: 3, title: 'tag3' },
39+
],
40+
},
41+
})
42+
43+
const vm: any = wrapper.vm
44+
45+
expect(vm.displayableTags.length).toBe(3)
46+
47+
const tags = wrapper.findAll('.filter-value')
48+
expect(tags.length).toBe(3)
49+
})
50+
51+
it('should not render alredy selected Tags items', () => {
52+
wrapper = lpiMount(SuggestedTags, {
53+
...defaultParams,
54+
props: {
55+
suggestedTags: [
56+
{ id: 1, title: 'tag1' },
57+
{ id: 2, title: 'tag2' },
58+
{ id: 3, title: 'tag3' },
59+
],
60+
currentTags: [1, 3],
61+
},
62+
})
63+
64+
const vm: any = wrapper.vm
65+
66+
expect(vm.displayableTags.length).toBe(1)
67+
expect(vm.displayableTags[0].id).toBe(2)
68+
69+
const tags = wrapper.findAll('.filter-value')
70+
expect(tags.length).toBe(1)
71+
})
2972
})

0 commit comments

Comments
 (0)