11import InlineSpecListHeader from './InlineSpecListHeader.vue'
22import { ref } from 'vue'
3+ import { defaultMessages } from '@cy/i18n'
34
45describe ( 'InlineSpecListHeader' , ( ) => {
5- beforeEach ( ( ) => {
6+ const mountWithResultCount = ( resultCount = 0 ) => {
67 const search = ref ( '' )
78 const onAddSpec = cy . spy ( ) . as ( 'new-spec' )
89
@@ -18,21 +19,36 @@ describe('InlineSpecListHeader', () => {
1819
1920 cy . mount ( ( ) =>
2021 ( < div class = "bg-gray-1000" >
21- < InlineSpecListHeader { ...methods } />
22+ < InlineSpecListHeader { ...methods } resultCount = { resultCount } />
2223 </ div > ) )
23- } )
24+ }
2425
2526 it ( 'should allow search' , ( ) => {
27+ mountWithResultCount ( 0 )
2628 const searchString = 'my/component.cy.tsx'
2729
28- cy . get ( 'input' )
30+ cy . findByLabelText ( defaultMessages . specPage . searchPlaceholder )
2931 . type ( searchString , { delay : 0 } )
3032 . get ( '@search' ) . its ( 'value' ) . should ( 'eq' , searchString )
3133 } )
3234
3335 it ( 'should emit add spec' , ( ) => {
34- cy . get ( '[data-cy="runner-spec-list-add-spec"]' ) . click ( )
36+ mountWithResultCount ( 0 )
37+ cy . findAllByLabelText ( defaultMessages . specPage . newSpecButton )
38+ . click ( )
3539 . get ( '@new-spec' )
3640 . should ( 'have.been.called' )
3741 } )
42+
43+ it ( 'exposes the result count correctly to assistive tech' , ( ) => {
44+ mountWithResultCount ( 0 )
45+ cy . contains ( `0 ${ defaultMessages . specPage . matchPlural } ` )
46+ . should ( 'have.class' , 'sr-only' )
47+ . and ( 'have.attr' , 'aria-live' , 'polite' )
48+
49+ mountWithResultCount ( 1 )
50+ cy . contains ( `1 ${ defaultMessages . specPage . matchSingular } ` ) . should ( 'have.class' , 'sr-only' )
51+ mountWithResultCount ( 100 )
52+ cy . contains ( `100 ${ defaultMessages . specPage . matchPlural } ` ) . should ( 'have.class' , 'sr-only' )
53+ } )
3854} )
0 commit comments