@@ -83,7 +83,8 @@ describe('MDCSelectFoundation', () => {
83
83
] ) ;
84
84
} ) ;
85
85
86
- function setupTest ( hasLeadingIcon = true , hasHelperText = false ) {
86
+ function setupTest (
87
+ hasLeadingIcon = true , hasHelperText = false , describedbyElements = '' ) {
87
88
const mockAdapter = createMockAdapter ( MDCSelectFoundation ) ;
88
89
const leadingIcon = jasmine . createSpyObj ( 'leadingIcon' , [
89
90
'setDisabled' , 'setAriaLabel' , 'setContent' , 'registerInteractionHandler' ,
@@ -107,6 +108,8 @@ describe('MDCSelectFoundation', () => {
107
108
mockAdapter . getMenuItemTextAtIndex . withArgs ( 0 ) . and . returnValue ( 'foo' ) ;
108
109
mockAdapter . getMenuItemTextAtIndex . withArgs ( 1 ) . and . returnValue ( 'bar' ) ;
109
110
mockAdapter . getMenuItemCount . and . returnValue ( 2 ) ;
111
+ mockAdapter . getSelectAnchorAttr . withArgs ( 'aria-describedby' )
112
+ . and . returnValue ( describedbyElements ) ;
110
113
111
114
const foundation = new MDCSelectFoundation ( mockAdapter , foundationMap ) ;
112
115
return { foundation, mockAdapter, leadingIcon, helperText} ;
@@ -768,10 +771,10 @@ describe('MDCSelectFoundation', () => {
768
771
( ) => {
769
772
const hasIcon = false ;
770
773
const hasHelperText = true ;
774
+ const mockId = 'foobarbazcool' ;
771
775
const { foundation, mockAdapter, helperText} =
772
- setupTest ( hasIcon , hasHelperText ) ;
776
+ setupTest ( hasIcon , hasHelperText , mockId ) ;
773
777
774
- const mockId = 'foobarbazcool' ;
775
778
helperText . getId . and . returnValue ( mockId ) ;
776
779
helperText . isVisible . and . returnValue ( true ) ;
777
780
@@ -780,6 +783,59 @@ describe('MDCSelectFoundation', () => {
780
783
. toHaveBeenCalledWith ( strings . ARIA_DESCRIBEDBY , mockId ) ;
781
784
} ) ;
782
785
786
+ it ( '#setValid, with client ids, sets aria-describedby' , ( ) => {
787
+ const hasIcon = false ;
788
+ const hasHelperText = true ;
789
+ const mockId = 'foobarbazcool' ;
790
+ const clientDescribedbyIds = 'id1 id2 id3' ;
791
+
792
+ const { foundation, mockAdapter, helperText} =
793
+ setupTest ( hasIcon , hasHelperText , clientDescribedbyIds + ' ' + mockId ) ;
794
+
795
+ helperText . getId . and . returnValue ( mockId ) ;
796
+ helperText . isVisible . and . returnValue ( true ) ;
797
+
798
+ foundation . setValid ( false ) ;
799
+ expect ( mockAdapter . setSelectAnchorAttr )
800
+ . toHaveBeenCalledWith (
801
+ strings . ARIA_DESCRIBEDBY , clientDescribedbyIds + ' ' + mockId ) ;
802
+ } ) ;
803
+
804
+ it ( '#setValid, w/ client ids, remove helpertextId from aria-describedby' ,
805
+ ( ) => {
806
+ const hasIcon = false ;
807
+ const hasHelperText = true ;
808
+ const mockId = 'foobarbazcool' ;
809
+ const clientDescribedbyIds = `id1 id2 id3` ;
810
+
811
+ const { foundation, mockAdapter, helperText} = setupTest (
812
+ hasIcon , hasHelperText , clientDescribedbyIds + ' ' + mockId ) ;
813
+
814
+ helperText . getId . and . returnValue ( mockId ) ;
815
+ helperText . isVisible . and . returnValue ( false ) ;
816
+
817
+ foundation . setValid ( false ) ;
818
+ expect ( mockAdapter . setSelectAnchorAttr )
819
+ . toHaveBeenCalledWith (
820
+ strings . ARIA_DESCRIBEDBY , clientDescribedbyIds ) ;
821
+ } ) ;
822
+
823
+ it ( '#setValid, no client describedby ids, remove aria-describedby' , ( ) => {
824
+ const hasIcon = false ;
825
+ const hasHelperText = true ;
826
+ const mockId = 'foobarbazcool' ;
827
+
828
+ const { foundation, mockAdapter, helperText} =
829
+ setupTest ( hasIcon , hasHelperText , mockId ) ;
830
+
831
+ helperText . getId . and . returnValue ( mockId ) ;
832
+ helperText . isVisible . and . returnValue ( false ) ;
833
+
834
+ foundation . setValid ( false ) ;
835
+ expect ( mockAdapter . removeSelectAnchorAttr )
836
+ . toHaveBeenCalledWith ( strings . ARIA_DESCRIBEDBY ) ;
837
+ } ) ;
838
+
783
839
it ( '#setValid true sets aria-invalid to false and removes invalid classes' ,
784
840
( ) => {
785
841
const { foundation, mockAdapter} = setupTest ( ) ;
0 commit comments