Skip to content

Commit 878317e

Browse files
fix: add unit tests after classifications (#591)
1 parent 6255673 commit 878317e

File tree

12 files changed

+534
-45
lines changed

12 files changed

+534
-45
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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
<div v-else class="search-mode-ctn">
77
<SearchResults
8+
data-test="search-results"
89
key="search-results"
910
:tag-results="tagResults"
1011
:existing-tags="existingTags"
@@ -60,26 +61,32 @@ export default {
6061
6162
props: {
6263
search: {
64+
// search query
6365
type: String,
6466
default: '',
6567
},
6668
classificationId: {
69+
// classification id to limit search to (if not searchAll)
6770
type: Number,
6871
default: null,
6972
},
7073
type: {
71-
type: String, // "skills" or "projects"
74+
// "skills" or "projects"
75+
type: String,
7276
default: '',
7377
},
7478
searchAll: {
79+
// search all org classification
7580
type: Boolean,
7681
default: false,
7782
},
7883
existingTags: {
84+
// array of tag ids
7985
type: Array,
8086
default: () => [],
8187
},
8288
showPreSearchList: {
89+
// shwow all tags (aka empty search) before search
8390
type: Boolean,
8491
default: false,
8592
},

src/components/search/Filters/SkillsFilterEditor.vue

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div :class="{ inline }" class="skills-filter-editor">
2+
<div class="skills-filter-editor">
33
<div class="section">
44
<CurrentTags
55
:current-tags="skills"
@@ -12,20 +12,26 @@
1212
<div class="section" v-if="!allSearchMode">
1313
<p class="notice">{{ $t('search.pick-skill-classification') }}</p>
1414

15-
<LpiSelect v-model="selectedClassificationId" :options="orgClassificationOptions" />
15+
<LpiSelect
16+
data-test="classification-picker"
17+
v-model="selectedClassificationId"
18+
:options="orgClassificationOptions"
19+
/>
1620
</div>
1721

1822
<div v-show="allSearchMode || showTagSearch" class="section">
1923
<p class="notice">{{ $t('search.current-skill-description') }}</p>
2024

2125
<FilterSearchInput
26+
data-test="tag-search-input"
2227
ref="search-input-component"
2328
v-model.trim="search"
2429
:placeholder="$t('search.search-skill')"
2530
class="search-input-ctn"
2631
/>
2732

2833
<TagResults
34+
data-test="tag-results"
2935
v-if="search || showPreSearchList"
3036
:classification-id="selectedClassificationId"
3137
:existing-tags="alreadySelectedSkills"
@@ -40,6 +46,7 @@
4046
<p class="notice notice-suggested">{{ $t('search.pick-skill-preset') }}</p>
4147

4248
<SuggestedTags
49+
data-test="suggested-tags"
4350
:current-tags="alreadySelectedSkills"
4451
:suggested-tags="suggestedTags"
4552
@add-tag="onAddSkill"
@@ -77,25 +84,19 @@ export default {
7784
default: () => [],
7885
},
7986
blockedSkills: {
87+
// unselctable skills (already selected ones)
8088
type: Array,
8189
default: () => [],
8290
},
8391
84-
triggerUpdate: {
85-
type: Boolean,
86-
default: false,
87-
},
88-
8992
hideOrganizationTags: {
90-
type: Boolean,
91-
default: false,
92-
},
93-
94-
inline: {
93+
// dont show org suggested skills
9594
type: Boolean,
9695
default: false,
9796
},
9897
allSearchMode: {
98+
// search all org classification
99+
// or a picked one
99100
type: Boolean,
100101
default: true,
101102
},
@@ -184,10 +185,6 @@ export default {
184185
}
185186
},
186187
187-
triggerUpdate: function () {
188-
this.$emit('update:modelValue', this.skills)
189-
},
190-
191188
modelValue: {
192189
handler: function (neo) {
193190
this.skills = [...neo]

src/components/search/Filters/TagsFilterEditor.vue

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div :class="{ inline }" class="tags-filter-editor">
2+
<div class="tags-filter-editor">
33
<div class="section">
44
<CurrentTags
55
:current-tags="tags"
@@ -12,7 +12,11 @@
1212
<div class="section" v-if="!allSearchMode">
1313
<p class="notice">{{ $t('search.pick-tag-classification') }}</p>
1414

15-
<LpiSelect v-model="selectedClassificationId" :options="orgClassificationOptions" />
15+
<LpiSelect
16+
data-test="classification-picker"
17+
v-model="selectedClassificationId"
18+
:options="orgClassificationOptions"
19+
/>
1620

1721
<ClassificationDescription
1822
v-if="selectedClassification"
@@ -24,13 +28,15 @@
2428
<p class="notice">{{ $t('search.current-tag-description') }}</p>
2529

2630
<FilterSearchInput
31+
data-test="tag-search-input"
2732
ref="search-input-component"
2833
v-model.trim="search"
2934
:placeholder="$t('search.search-tag')"
3035
class="search-input-ctn"
3136
/>
3237

3338
<TagResults
39+
data-test="tag-results"
3440
v-if="search || showPreSearchList"
3541
:classification-id="selectedClassificationId"
3642
:existing-tags="alreadySelectedTags"
@@ -44,6 +50,7 @@
4450
<template v-else-if="suggestedTags.length">
4551
<p class="notice notice-suggested">{{ $t('search.pick-tag-preset') }}</p>
4652
<SuggestedTags
53+
data-test="suggested-tags"
4754
:current-tags="alreadySelectedTags"
4855
:suggested-tags="suggestedTags"
4956
@add-tag="addTag"
@@ -82,31 +89,30 @@ export default {
8289
default: () => [],
8390
},
8491
blockedTags: {
92+
// unselctable tags (already selected ones)
8593
type: Array,
8694
default: () => [],
8795
},
88-
triggerUpdate: {
89-
type: Boolean,
90-
default: false,
91-
},
9296
9397
hideOrganizationTags: {
94-
type: Boolean,
95-
default: false,
96-
},
97-
inline: {
98+
// dont show org suggested tags
9899
type: Boolean,
99100
default: false,
100101
},
101102
progressiveUpdate: {
103+
// if false emit specific event instead of model update
104+
// see ProjectForm
102105
type: Boolean,
103106
default: true,
104107
},
105108
allSearchMode: {
109+
// search all org classification
110+
// or a picked one
106111
type: Boolean,
107112
default: true,
108113
},
109114
hideCurrentTagsSeparator: {
115+
// hide "or" separator between selected tags
110116
type: Boolean,
111117
default: false,
112118
},
@@ -203,10 +209,6 @@ export default {
203209
}
204210
},
205211
206-
triggerUpdate: function () {
207-
this.$emit('update:modelValue', this.tags)
208-
},
209-
210212
modelValue: {
211213
handler: function (neo) {
212214
this.tags = [...neo]

src/composables/useTagSearch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export default function useTagSearch({
114114
const classificationReq = await getOrgClassificationTags(
115115
organizationsStore.current.code,
116116
selectedClassificationId.value,
117-
// temp hackish fix until we have count int he org data
117+
// temp hackish fix until we have count in the org data
118118
{ search: '' }
119119
)
120120
// if there's too many tags, show none

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

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

@@ -29,4 +29,40 @@ describe('SearchResults', () => {
2929

3030
expect(wrapper.exists()).toBeTruthy()
3131
})
32+
33+
it('should mark disabled tags', () => {
34+
wrapper = lpiMount(SearchResults, {
35+
...defaultParams,
36+
props: {
37+
tagResults: [{ id: 1 }, { id: 2 }, { id: 3 }],
38+
existingTags: [1, 3],
39+
},
40+
})
41+
const vm: any = wrapper.vm
42+
const filtered = vm.filteredTagResults
43+
expect(filtered.length).toBe(3)
44+
expect(filtered[0].id).toBe(1)
45+
expect(filtered[0].disabled).toBeTruthy()
46+
expect(filtered[1].id).toBe(2)
47+
expect(filtered[1].disabled).toBeFalsy()
48+
expect(filtered[2].id).toBe(3)
49+
expect(filtered[2].disabled).toBeTruthy()
50+
51+
const results = wrapper.findAll('.tag-result')
52+
expect(results.length).toBe(3)
53+
54+
// disabled item should not emit event
55+
results[0].trigger('click')
56+
expect(wrapper.emitted()['result-clicked']).toBeFalsy()
57+
58+
// non disabled item should emit event (with item as payload)
59+
results[1].trigger('click')
60+
expect(wrapper.emitted()['result-clicked'].length).toBe(1)
61+
// for some reason paylod is wrapped in an array by vitest
62+
expect(wrapper.emitted()['result-clicked'][0][0]).toEqual(filtered[1])
63+
64+
// disabled item should not emit event
65+
results[2].trigger('click')
66+
expect(wrapper.emitted()['result-clicked'].length).toBe(1)
67+
})
3268
})

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
})

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { lpiShallowMount } from '../../../../helpers/LpiMount'
1+
import { lpiShallowMount, lpiMount } from '../../../../helpers/LpiMount'
22
import english from '@/locales/en.json'
33
import TagResults from '@/components/search/FilterTags/TagResults.vue'
44
import { flushPromises } from '@vue/test-utils'
@@ -52,4 +52,17 @@ describe('TagResults', () => {
5252
expect(wrapper.exists()).toBeTruthy()
5353
expect(mockSearch).toHaveBeenCalled()
5454
})
55+
56+
it('should pass existingTags to searchResults', async () => {
57+
wrapper = lpiMount(TagResults, { ...defaultParams, props: { existingTags: [1, 2] } })
58+
59+
const vm: any = wrapper.vm
60+
vm.isLoading = false
61+
await flushPromises()
62+
// should display search results
63+
const resultsComp = wrapper.findComponent('[data-test="search-results"]')
64+
expect(resultsComp.vm.existingTags.length).toBe(2)
65+
expect(resultsComp.vm.existingTags[0]).toBe(1)
66+
expect(resultsComp.vm.existingTags[1]).toBe(2)
67+
})
5568
})

tests/unit/components/search/Filters/CategoriesFilterEditor.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('CategoriesFilterEditor.vue', () => {
3333
})
3434

3535
it('should emit event update is triggered', async () => {
36-
const wrapper = factory({ modelValue: [], triggerUpdate: true })
36+
const wrapper = factory({ modelValue: [] })
3737
const vm: any = wrapper.vm
3838

3939
const buttonContainer = wrapper.find('.category-picker-element input')

0 commit comments

Comments
 (0)