@@ -85,7 +85,9 @@ vi.mock('~/composables/useFacetSelection', () => ({
8585 facetsByCategory : computed ( ( ) => {
8686 const result : Record < string , ReturnType < typeof buildFacetInfo > [ ] > = { }
8787 for ( const category of CATEGORY_ORDER ) {
88- result [ category ] = FACETS_BY_CATEGORY [ category ] . map ( facet => buildFacetInfo ( facet ) )
88+ result [ category ] = FACETS_BY_CATEGORY [ category ] . map ( ( facet : ComparisonFacet ) =>
89+ buildFacetInfo ( facet ) ,
90+ )
8991 }
9092 return result
9193 } ) ,
@@ -230,12 +232,21 @@ describe('FacetSelector', () => {
230232 } )
231233
232234 describe ( 'category all/none buttons' , ( ) => {
235+ function findCategoryActionButton (
236+ component : Awaited < ReturnType < typeof mountSuspended > > ,
237+ category : string ,
238+ action : 'all' | 'none' ,
239+ ) {
240+ return component . find (
241+ `button[data-facet-category="${ category } "][data-facet-category-action="${ action } "]` ,
242+ )
243+ }
244+
233245 it ( 'calls selectCategory when all button is clicked' , async ( ) => {
234246 const component = await mountSuspended ( FacetSelector )
235247
236- // Find the first 'all' radio (for performance category)
237- const allButton = component . findAll ( 'button[role="radio"]' ) . find ( b => b . text ( ) === 'all' )
238- await allButton ! . trigger ( 'click' )
248+ const allButton = findCategoryActionButton ( component , 'performance' , 'all' )
249+ await allButton . trigger ( 'click' )
239250
240251 expect ( mockSelectCategory ) . toHaveBeenCalledWith ( 'performance' )
241252 } )
@@ -247,38 +258,64 @@ describe('FacetSelector', () => {
247258
248259 const component = await mountSuspended ( FacetSelector )
249260
250- // Find the first 'none' radio (for performance category)
251- const noneButton = component . findAll ( 'button[role="radio"]' ) . find ( b => b . text ( ) === 'none' )
252- await noneButton ! . trigger ( 'click' )
261+ const noneButton = findCategoryActionButton ( component , 'performance' , 'none' )
262+ await noneButton . trigger ( 'click' )
253263
254264 expect ( mockDeselectCategory ) . toHaveBeenCalledWith ( 'performance' )
255265 } )
256266
257- it ( 'marks all button as checked when all facets in category are selected' , async ( ) => {
267+ it ( 'marks all button as aria-disabled when all facets in category are selected' , async ( ) => {
258268 // Select all performance facets
259269 const performanceFacets : ( string | ComparisonFacet ) [ ] = FACETS_BY_CATEGORY . performance . filter (
260- f => ! FACET_INFO [ f ] . comingSoon ,
270+ ( f : ComparisonFacet ) => ! FACET_INFO [ f ] . comingSoon ,
261271 )
262272 mockSelectedFacets . value = performanceFacets
263273 mockIsFacetSelected . mockImplementation ( ( f : string ) => performanceFacets . includes ( f ) )
264274
265275 const component = await mountSuspended ( FacetSelector )
266276
267- const allButton = component . findAll ( 'button[role="radio"]' ) . find ( b => b . text ( ) === 'all' )
268- // First all button (performance) should be checked
269- expect ( allButton ! . attributes ( 'aria-checked ' ) ) . toBe ( 'true' )
277+ const allButton = findCategoryActionButton ( component , 'performance' , 'all' )
278+
279+ expect ( allButton . attributes ( 'aria-disabled ' ) ) . toBe ( 'true' )
270280 } )
271281
272- it ( 'marks none button as checked when no facets in category are selected' , async ( ) => {
282+ it ( 'marks none button as aria-disabled when no facets in category are selected' , async ( ) => {
273283 // Deselect all performance facets
274284 mockSelectedFacets . value = [ 'downloads' ] // only health facet selected
275285 mockIsFacetSelected . mockImplementation ( ( f : string ) => f === 'downloads' )
276286
277287 const component = await mountSuspended ( FacetSelector )
278288
279- const noneButton = component . findAll ( 'button[role="radio"]' ) . find ( b => b . text ( ) === 'none' )
280- // First none button (performance) should be checked
281- expect ( noneButton ! . attributes ( 'aria-checked' ) ) . toBe ( 'true' )
289+ const noneButton = findCategoryActionButton ( component , 'performance' , 'none' )
290+
291+ expect ( noneButton . attributes ( 'aria-disabled' ) ) . toBe ( 'true' )
292+ } )
293+
294+ it ( 'does not call selectCategory when all button action is already fulfilled' , async ( ) => {
295+ const performanceFacets : ( string | ComparisonFacet ) [ ] = FACETS_BY_CATEGORY . performance . filter (
296+ ( f : ComparisonFacet ) => ! FACET_INFO [ f ] . comingSoon ,
297+ )
298+ mockSelectedFacets . value = performanceFacets
299+ mockIsFacetSelected . mockImplementation ( ( f : string ) => performanceFacets . includes ( f ) )
300+
301+ const component = await mountSuspended ( FacetSelector )
302+
303+ const allButton = findCategoryActionButton ( component , 'performance' , 'all' )
304+ await allButton . trigger ( 'click' )
305+
306+ expect ( mockSelectCategory ) . not . toHaveBeenCalled ( )
307+ } )
308+
309+ it ( 'does not call deselectCategory when none button action is already fulfilled' , async ( ) => {
310+ mockSelectedFacets . value = [ 'downloads' ]
311+ mockIsFacetSelected . mockImplementation ( ( f : string ) => f === 'downloads' )
312+
313+ const component = await mountSuspended ( FacetSelector )
314+
315+ const noneButton = findCategoryActionButton ( component , 'performance' , 'none' )
316+ await noneButton . trigger ( 'click' )
317+
318+ expect ( mockDeselectCategory ) . not . toHaveBeenCalled ( )
282319 } )
283320 } )
284321
0 commit comments