@@ -143,6 +143,51 @@ test('#handleSelect calls foundation.handleChipSelection with selectedChipId and
143
143
td . verify ( handleChipSelection ( '1' , false ) , { times : 1 } ) ;
144
144
} ) ;
145
145
146
+ test ( '#handleSelect calls updates parent component with selectedChipIds correctly for filter chips' , ( ) => {
147
+ type HandleSelectMethod = ( prevSelectedChipIds : string [ ] , selectedChipId : string [ ] ) => void ;
148
+ type Props = {
149
+ handleSelect : HandleSelectMethod
150
+ } ;
151
+ type State = { selectedChipIds : string [ ] } ;
152
+
153
+ class TestChipParentComponent extends React . Component < Props , State > {
154
+ state = { selectedChipIds : [ ] } ;
155
+ componentDidUpdate ( _ : Props , pState : State ) {
156
+ if ( pState . selectedChipIds !== this . state . selectedChipIds ) {
157
+ this . props . handleSelect ( pState . selectedChipIds , this . state . selectedChipIds ) ;
158
+ }
159
+ }
160
+ handleSelect = ( selectedChipIds : string [ ] ) => {
161
+ this . setState ( { selectedChipIds} ) ;
162
+ }
163
+ render ( ) {
164
+ const Chip1 = < Chip id = 'chip1' /> ;
165
+ const Chip2 = < Chip id = 'chip2' /> ;
166
+ return (
167
+ < ChipSet
168
+ filter
169
+ selectedChipIds = { this . state . selectedChipIds }
170
+ handleSelect = { this . handleSelect }
171
+ >
172
+ { Chip1 }
173
+ { Chip2 }
174
+ </ ChipSet >
175
+ ) ;
176
+ }
177
+ }
178
+
179
+ const handleChipSelection = coerceForTesting < HandleSelectMethod > ( td . func ( ) ) ;
180
+ const wrapper = mount < TestChipParentComponent > (
181
+ < TestChipParentComponent handleSelect = { handleChipSelection } />
182
+ ) ;
183
+ const chipSet = wrapper . childAt ( 0 ) ;
184
+ chipSet . children ( ) . children ( ) . first ( ) . children ( ) . simulate ( 'click' ) ;
185
+ td . verify ( handleChipSelection ( [ ] , [ 'chip1' ] ) , { times : 1 } ) ;
186
+ chipSet . children ( ) . children ( ) . last ( ) . children ( ) . simulate ( 'click' ) ;
187
+ td . verify ( handleChipSelection ( [ 'chip1' ] , [ 'chip1' , 'chip2' ] ) , { times : 1 } ) ;
188
+ } ) ;
189
+
190
+
146
191
test ( '#handleInteraction calls #foundation.handleChipInteraction' , ( ) => {
147
192
const handleChipInteraction = td . func ( ) ;
148
193
const foundation = { handleChipInteraction} ;
0 commit comments