Skip to content

Commit eb74104

Browse files
committed
test coverage
1 parent 3be3b6a commit eb74104

2 files changed

Lines changed: 31 additions & 19 deletions

File tree

test/nuxt/components/compare/FacetSelector.spec.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ const categoryLabels: Record<string, string> = {
3434
security: 'Security & Compliance',
3535
}
3636

37+
// ComingSoon tests run only when FACET_INFO has at least one comingSoon facet
38+
const comingSoonFacets = (Object.keys(FACET_INFO) as ComparisonFacet[]).filter(
39+
f => FACET_INFO[f].comingSoon,
40+
)
41+
const hasComingSoonFacets = comingSoonFacets.length > 0
42+
const comingSoonFacetId = comingSoonFacets[0]
43+
const comingSoonFacetLabel = hasComingSoonFacets
44+
? (facetLabels[comingSoonFacetId!]?.label ?? comingSoonFacetId)
45+
: ''
46+
3747
// Helper to build facet info with labels
3848
function buildFacetInfo(facet: ComparisonFacet) {
3949
return {
@@ -174,13 +184,12 @@ describe('FacetSelector', () => {
174184
})
175185
})
176186

177-
describe('comingSoon facets', () => {
187+
describe.runIf(hasComingSoonFacets)('comingSoon facets', () => {
178188
it('disables comingSoon facets', async () => {
179189
const component = await mountSuspended(FacetSelector)
180190

181-
// totalDependencies is marked as comingSoon
182191
const buttons = component.findAll('button')
183-
const comingSoonButton = buttons.find(b => b.text().includes('Total Deps'))
192+
const comingSoonButton = buttons.find(b => b.text().includes(comingSoonFacetLabel))
184193

185194
expect(comingSoonButton?.attributes('disabled')).toBeDefined()
186195
})
@@ -194,11 +203,9 @@ describe('FacetSelector', () => {
194203
it('does not show checkmark/add icon for comingSoon facets', async () => {
195204
const component = await mountSuspended(FacetSelector)
196205

197-
// Find the comingSoon button
198206
const buttons = component.findAll('button')
199-
const comingSoonButton = buttons.find(b => b.text().includes('Total Deps'))
207+
const comingSoonButton = buttons.find(b => b.text().includes(comingSoonFacetLabel))
200208

201-
// Should not have checkmark or add icon
202209
expect(comingSoonButton?.find('.i-carbon\\:checkmark').exists()).toBe(false)
203210
expect(comingSoonButton?.find('.i-carbon\\:add').exists()).toBe(false)
204211
})
@@ -207,11 +214,10 @@ describe('FacetSelector', () => {
207214
const component = await mountSuspended(FacetSelector)
208215

209216
const buttons = component.findAll('button')
210-
const comingSoonButton = buttons.find(b => b.text().includes('Total Deps'))
217+
const comingSoonButton = buttons.find(b => b.text().includes(comingSoonFacetLabel))
211218
await comingSoonButton?.trigger('click')
212219

213-
// toggleFacet should not have been called with totalDependencies
214-
expect(mockToggleFacet).not.toHaveBeenCalledWith('totalDependencies')
220+
expect(mockToggleFacet).not.toHaveBeenCalledWith(comingSoonFacetId)
215221
})
216222
})
217223

@@ -281,7 +287,7 @@ describe('FacetSelector', () => {
281287
expect(component.find('.bg-bg-muted').exists()).toBe(true)
282288
})
283289

284-
it('applies cursor-not-allowed to comingSoon facets', async () => {
290+
it.runIf(hasComingSoonFacets)('applies cursor-not-allowed to comingSoon facets', async () => {
285291
const component = await mountSuspended(FacetSelector)
286292

287293
expect(component.find('.cursor-not-allowed').exists()).toBe(true)

test/nuxt/composables/use-facet-selection.spec.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
22
import { mountSuspended } from '@nuxt/test-utils/runtime'
33
import { ref } from 'vue'
44
import type { ComparisonFacet } from '#shared/types/comparison'
5-
import { DEFAULT_FACETS, FACETS_BY_CATEGORY } from '#shared/types/comparison'
5+
import { DEFAULT_FACETS, FACET_INFO, FACETS_BY_CATEGORY } from '#shared/types/comparison'
66
import type { FacetInfoWithLabels } from '~/composables/useFacetSelection'
77

88
// Mock useRouteQuery - needs to be outside of the helper to persist across calls
@@ -113,15 +113,21 @@ describe('useFacetSelection', () => {
113113
expect(isFacetSelected('types')).toBe(true)
114114
})
115115

116-
it('filters out comingSoon facets from query', async () => {
117-
mockRouteQuery.value = 'downloads,totalDependencies,types'
116+
it.runIf((Object.keys(FACET_INFO) as ComparisonFacet[]).some(f => FACET_INFO[f].comingSoon))(
117+
'filters out comingSoon facets from query',
118+
async () => {
119+
const comingSoonFacet = (Object.keys(FACET_INFO) as ComparisonFacet[]).find(
120+
f => FACET_INFO[f].comingSoon,
121+
)!
122+
mockRouteQuery.value = `downloads,${comingSoonFacet},types`
118123

119-
const { isFacetSelected } = await useFacetSelectionInComponent()
124+
const { isFacetSelected } = await useFacetSelectionInComponent()
120125

121-
expect(isFacetSelected('downloads')).toBe(true)
122-
expect(isFacetSelected('types')).toBe(true)
123-
expect(isFacetSelected('totalDependencies')).toBe(false)
124-
})
126+
expect(isFacetSelected('downloads')).toBe(true)
127+
expect(isFacetSelected('types')).toBe(true)
128+
expect(isFacetSelected(comingSoonFacet)).toBe(false)
129+
},
130+
)
125131

126132
it('falls back to DEFAULT_FACETS if all parsed facets are invalid', async () => {
127133
mockRouteQuery.value = 'invalidFacet1,invalidFacet2'
@@ -225,7 +231,7 @@ describe('useFacetSelection', () => {
225231
selectCategory('performance')
226232

227233
const performanceFacets = FACETS_BY_CATEGORY.performance.filter(
228-
f => f !== 'totalDependencies', // comingSoon facet
234+
f => !FACET_INFO[f].comingSoon,
229235
)
230236
for (const facet of performanceFacets) {
231237
expect(isFacetSelected(facet)).toBe(true)

0 commit comments

Comments
 (0)