Skip to content

Commit 00bb21c

Browse files
committed
refactor(a11y): extract facet chip classes and harden comingSoon test id
1 parent 4b2657f commit 00bb21c

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

app/components/Compare/FacetSelector.vue

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ function onFacetChange(facet: FacetInfoWithLabels) {
2323
toggleFacet(facet.id)
2424
}
2525
26+
/** Visual variant for each facet chip (border/background/cursor). */
27+
function facetChipVariantClass(facet: FacetInfoWithLabels): string {
28+
if (facet.comingSoon) {
29+
return 'text-fg-subtle/50 bg-bg-subtle border-border-subtle cursor-not-allowed'
30+
}
31+
if (isFacetCheckboxDisabled(facet)) {
32+
return 'text-fg-muted bg-bg-muted border-border opacity-90 cursor-not-allowed'
33+
}
34+
if (isFacetSelected(facet.id)) {
35+
return 'text-fg-muted bg-bg-muted border-border cursor-pointer'
36+
}
37+
return 'text-fg-subtle bg-bg-subtle border-border-subtle hover:text-fg-muted hover:border-border cursor-pointer'
38+
}
39+
2640
// Check if all non-comingSoon facets in a category are selected
2741
function isCategoryAllSelected(category: string): boolean {
2842
const facets = facetsByCategory.value[category] ?? []
@@ -84,15 +98,7 @@ function isCategoryNoneSelected(category: string): boolean {
8498
v-for="facet in facetsByCategory[category]"
8599
:key="facet.id"
86100
class="flex items-center gap-1.5 px-1.5 py-0.5 rounded border text-xs transition-colors focus-within:outline focus-within:outline-2 focus-within:outline-offset-1 focus-within:outline-accent/70"
87-
:class="
88-
facet.comingSoon
89-
? 'text-fg-subtle/50 bg-bg-subtle border-border-subtle cursor-not-allowed'
90-
: isFacetCheckboxDisabled(facet)
91-
? 'text-fg-muted bg-bg-muted border-border opacity-90 cursor-not-allowed'
92-
: isFacetSelected(facet.id)
93-
? 'text-fg-muted bg-bg-muted border-border cursor-pointer'
94-
: 'text-fg-subtle bg-bg-subtle border-border-subtle hover:text-fg-muted hover:border-border cursor-pointer'
95-
"
101+
:class="facetChipVariantClass(facet)"
96102
>
97103
<input
98104
type="checkbox"

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const categoryLabels: Record<string, string> = {
4141
security: 'Security & Compliance',
4242
}
4343

44-
const comingSoonFacetId = comingSoonFacets[0]
44+
const comingSoonFacetId: ComparisonFacet | undefined = comingSoonFacets.at(0)
4545

4646
// Helper to build facet info with labels
4747
function buildFacetInfo(facet: ComparisonFacet) {
@@ -190,33 +190,35 @@ describe('FacetSelector', () => {
190190
})
191191
})
192192

193-
describe.runIf(hasComingSoonFacets)('comingSoon facets', () => {
194-
it('disables comingSoon facets', async () => {
195-
const component = await mountSuspended(FacetSelector)
193+
describe.runIf(hasComingSoonFacets && comingSoonFacetId !== undefined)(
194+
'comingSoon facets',
195+
() => {
196+
// runIf guarantees comingSoonFacetId is defined here
197+
const facetId: ComparisonFacet = comingSoonFacetId!
196198

197-
const comingSoonInput = component.find(
198-
`input[type="checkbox"][data-facet-id="${comingSoonFacetId}"]`,
199-
)
200-
expect(comingSoonInput.attributes('disabled')).toBeDefined()
201-
})
199+
it('disables comingSoon facets', async () => {
200+
const component = await mountSuspended(FacetSelector)
202201

203-
it('shows coming soon text for comingSoon facets', async () => {
204-
const component = await mountSuspended(FacetSelector)
202+
const comingSoonInput = component.find(`input[type="checkbox"][data-facet-id="${facetId}"]`)
203+
expect(comingSoonInput.attributes('disabled')).toBeDefined()
204+
})
205205

206-
expect(component.text().toLowerCase()).toContain('coming soon')
207-
})
206+
it('shows coming soon text for comingSoon facets', async () => {
207+
const component = await mountSuspended(FacetSelector)
208208

209-
it('does not call toggleFacet when comingSoon checkbox change is triggered', async () => {
210-
const component = await mountSuspended(FacetSelector)
209+
expect(component.text().toLowerCase()).toContain('coming soon')
210+
})
211211

212-
const comingSoonInput = component.find(
213-
`input[type="checkbox"][data-facet-id="${comingSoonFacetId}"]`,
214-
)
215-
await comingSoonInput.trigger('change')
212+
it('does not call toggleFacet when comingSoon checkbox change is triggered', async () => {
213+
const component = await mountSuspended(FacetSelector)
216214

217-
expect(mockToggleFacet).not.toHaveBeenCalledWith(comingSoonFacetId)
218-
})
219-
})
215+
const comingSoonInput = component.find(`input[type="checkbox"][data-facet-id="${facetId}"]`)
216+
await comingSoonInput.trigger('change')
217+
218+
expect(mockToggleFacet).not.toHaveBeenCalledWith(facetId)
219+
})
220+
},
221+
)
220222

221223
describe('category all/none buttons', () => {
222224
it('calls selectCategory when all button is clicked', async () => {

0 commit comments

Comments
 (0)