Skip to content

Commit 3a4f470

Browse files
committed
fix: use approach from #868
1 parent 01c90eb commit 3a4f470

File tree

3 files changed

+77
-5
lines changed

3 files changed

+77
-5
lines changed

shared/types/comparison.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,9 @@ export interface ComparisonPackage {
110110
version: string
111111
description?: string
112112
}
113+
114+
// ComingSoon tests run only when FACET_INFO has at least one comingSoon facet
115+
export const comingSoonFacets = (Object.keys(FACET_INFO) as ComparisonFacet[]).filter(
116+
f => FACET_INFO[f].comingSoon,
117+
)
118+
export const hasComingSoonFacets = comingSoonFacets.length > 0

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

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import type { ComparisonFacet } from '#shared/types/comparison'
2-
import { CATEGORY_ORDER, FACET_INFO, FACETS_BY_CATEGORY } from '#shared/types/comparison'
2+
import {
3+
CATEGORY_ORDER,
4+
FACET_INFO,
5+
FACETS_BY_CATEGORY,
6+
comingSoonFacets,
7+
hasComingSoonFacets,
8+
} from '#shared/types/comparison'
39
import FacetSelector from '~/components/Compare/FacetSelector.vue'
410
import { beforeEach, describe, expect, it, vi } from 'vitest'
511
import { computed, ref } from 'vue'
@@ -21,7 +27,7 @@ const facetLabels: Record<ComparisonFacet, { label: string; description: string
2127
license: { label: 'License', description: 'Package license' },
2228
dependencies: { label: 'Direct Deps', description: 'Number of direct dependencies' },
2329
totalDependencies: {
24-
label: 'Total Deps',
30+
label: 'Total deps',
2531
description: 'Total number of dependencies including transitive',
2632
},
2733
deprecated: { label: 'Deprecated?', description: 'Whether the package is deprecated' },
@@ -34,6 +40,11 @@ const categoryLabels: Record<string, string> = {
3440
security: 'Security & Compliance',
3541
}
3642

43+
const comingSoonFacetId = comingSoonFacets[0]
44+
const comingSoonFacetLabel = hasComingSoonFacets
45+
? (facetLabels[comingSoonFacetId!]?.label ?? comingSoonFacetId)
46+
: ''
47+
3748
// Helper to build facet info with labels
3849
function buildFacetInfo(facet: ComparisonFacet) {
3950
return {
@@ -174,6 +185,47 @@ describe('FacetSelector', () => {
174185
})
175186
})
176187

188+
describe.runIf(hasComingSoonFacets)('comingSoon facets', () => {
189+
it('disables comingSoon facets', async () => {
190+
const component = await mountSuspended(FacetSelector)
191+
192+
// totalDependencies is marked as comingSoon
193+
const buttons = component.findAll('button')
194+
const comingSoonButton = buttons.find(b => b.text().includes(comingSoonFacetLabel))
195+
196+
expect(comingSoonButton?.attributes('disabled')).toBeDefined()
197+
})
198+
199+
it('shows coming soon text for comingSoon facets', async () => {
200+
const component = await mountSuspended(FacetSelector)
201+
202+
expect(component.text().toLowerCase()).toContain('coming soon')
203+
})
204+
205+
it('does not show checkmark/add icon for comingSoon facets', async () => {
206+
const component = await mountSuspended(FacetSelector)
207+
208+
// Find the comingSoon button
209+
const buttons = component.findAll('button')
210+
const comingSoonButton = buttons.find(b => b.text().includes(comingSoonFacetLabel))
211+
212+
// Should not have checkmark or add icon
213+
expect(comingSoonButton?.find('.i-carbon\\:checkmark').exists()).toBe(false)
214+
expect(comingSoonButton?.find('.i-carbon\\:add').exists()).toBe(false)
215+
})
216+
217+
it('does not call toggleFacet when comingSoon facet is clicked', async () => {
218+
const component = await mountSuspended(FacetSelector)
219+
220+
const buttons = component.findAll('button')
221+
const comingSoonButton = buttons.find(b => b.text().includes(comingSoonFacetLabel))
222+
await comingSoonButton?.trigger('click')
223+
224+
// toggleFacet should not have been called with totalDependencies
225+
expect(mockToggleFacet).not.toHaveBeenCalledWith(comingSoonFacetId)
226+
})
227+
})
228+
177229
describe('category all/none buttons', () => {
178230
it('calls selectCategory when all button is clicked', async () => {
179231
const component = await mountSuspended(FacetSelector)
@@ -237,5 +289,11 @@ describe('FacetSelector', () => {
237289
// Selected facets have bg-bg-muted class
238290
expect(component.find('.bg-bg-muted').exists()).toBe(true)
239291
})
292+
293+
it.runIf(hasComingSoonFacets)('applies cursor-not-allowed to comingSoon facets', async () => {
294+
const component = await mountSuspended(FacetSelector)
295+
296+
expect(component.find('.cursor-not-allowed').exists()).toBe(true)
297+
})
240298
})
241299
})

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ 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 {
6+
DEFAULT_FACETS,
7+
FACET_INFO,
8+
FACETS_BY_CATEGORY,
9+
hasComingSoonFacets,
10+
} from '#shared/types/comparison'
611
import type { FacetInfoWithLabels } from '~/composables/useFacetSelection'
712

813
// Mock useRouteQuery - needs to be outside of the helper to persist across calls
@@ -113,7 +118,7 @@ describe('useFacetSelection', () => {
113118
expect(isFacetSelected('types')).toBe(true)
114119
})
115120

116-
it('filters out comingSoon facets from query', async () => {
121+
it.runIf(hasComingSoonFacets)('filters out comingSoon facets from query', async () => {
117122
mockRouteQuery.value = 'downloads,totalDependencies,types'
118123

119124
const { isFacetSelected } = await useFacetSelectionInComponent()
@@ -224,6 +229,9 @@ describe('useFacetSelection', () => {
224229

225230
selectCategory('performance')
226231

232+
const performanceFacets = FACETS_BY_CATEGORY.performance.filter(
233+
f => !FACET_INFO[f].comingSoon, // comingSoon facet
234+
)
227235
for (const facet of performanceFacets) {
228236
expect(isFacetSelected(facet)).toBe(true)
229237
}
@@ -249,7 +257,7 @@ describe('useFacetSelection', () => {
249257
deselectCategory('performance')
250258

251259
const nonComingSoonPerformanceFacets = FACETS_BY_CATEGORY.performance.filter(
252-
f => f !== 'totalDependencies',
260+
f => !FACET_INFO[f].comingSoon,
253261
)
254262
for (const facet of nonComingSoonPerformanceFacets) {
255263
expect(isFacetSelected(facet)).toBe(false)

0 commit comments

Comments
 (0)