@@ -180,6 +180,192 @@ describe("Match Columns automatic matching", () => {
180180 expect ( onContinue . mock . calls [ 0 ] [ 0 ] ) . toEqual ( result )
181181 } )
182182
183+ test ( "AutoMatches select values on mount" , async ( ) => {
184+ const header = [ "first name" , "count" , "Email" ]
185+ const OPTION_RESULT_ONE = "John"
186+ const OPTION_RESULT_ONE_VALUE = "1"
187+ const OPTION_RESULT_TWO = "Dane"
188+ const OPTION_RESULT_TWO_VALUE = "2"
189+ const OPTION_RESULT_THREE = "Kane"
190+ const data = [
191+ // match by option label
192+ [ OPTION_RESULT_ONE , "123" , "[email protected] " ] , 193+ // match by option value
194+ [ OPTION_RESULT_TWO_VALUE , "333" , "[email protected] " ] , 195+ // do not match
196+ [ OPTION_RESULT_THREE , "534" , "[email protected] " ] , 197+ ]
198+ const options = [
199+ { label : OPTION_RESULT_ONE , value : OPTION_RESULT_ONE_VALUE } ,
200+ { label : OPTION_RESULT_TWO , value : OPTION_RESULT_TWO_VALUE } ,
201+ ]
202+ // finds only names with automatic matching
203+ const result = [ { name : OPTION_RESULT_ONE_VALUE } , { name : OPTION_RESULT_TWO_VALUE } , { name : undefined } ]
204+
205+ const alternativeFields = [
206+ {
207+ label : "Name" ,
208+ key : "name" ,
209+ alternateMatches : [ "first name" ] ,
210+ fieldType : {
211+ type : "select" ,
212+ options,
213+ } ,
214+ example : "Stephanie" ,
215+ } ,
216+ ] as const
217+
218+ const onContinue = jest . fn ( )
219+ render (
220+ < Providers
221+ theme = { defaultTheme }
222+ rsiValues = { { ...mockRsiValues , fields : alternativeFields , autoMapSelectValues : true } }
223+ >
224+ < ModalWrapper isOpen = { true } onClose = { ( ) => { } } >
225+ < MatchColumnsStep headerValues = { header } data = { data } onContinue = { onContinue } />
226+ </ ModalWrapper >
227+ </ Providers > ,
228+ )
229+
230+ expect ( screen . getByText ( / 1 U n m a t c h e d / ) ) . toBeInTheDocument ( )
231+
232+ const nextButton = screen . getByRole ( "button" , {
233+ name : "Next" ,
234+ } )
235+
236+ await userEvent . click ( nextButton )
237+
238+ await waitFor ( ( ) => {
239+ expect ( onContinue ) . toBeCalled ( )
240+ } )
241+ expect ( onContinue . mock . calls [ 0 ] [ 0 ] ) . toEqual ( result )
242+ } )
243+
244+ test ( "Does not auto match select values when autoMapSelectValues:false" , async ( ) => {
245+ const header = [ "first name" , "count" , "Email" ]
246+ const OPTION_RESULT_ONE = "John"
247+ const OPTION_RESULT_ONE_VALUE = "1"
248+ const OPTION_RESULT_TWO = "Dane"
249+ const OPTION_RESULT_TWO_VALUE = "2"
250+ const OPTION_RESULT_THREE = "Kane"
251+ const data = [
252+ // match by option label
253+ [ OPTION_RESULT_ONE , "123" , "[email protected] " ] , 254+ // match by option value
255+ [ OPTION_RESULT_TWO_VALUE , "333" , "[email protected] " ] , 256+ // do not match
257+ [ OPTION_RESULT_THREE , "534" , "[email protected] " ] , 258+ ]
259+ const options = [
260+ { label : OPTION_RESULT_ONE , value : OPTION_RESULT_ONE_VALUE } ,
261+ { label : OPTION_RESULT_TWO , value : OPTION_RESULT_TWO_VALUE } ,
262+ ]
263+ const result = [ { name : undefined } , { name : undefined } , { name : undefined } ]
264+
265+ const alternativeFields = [
266+ {
267+ label : "Name" ,
268+ key : "name" ,
269+ alternateMatches : [ "first name" ] ,
270+ fieldType : {
271+ type : "select" ,
272+ options,
273+ } ,
274+ example : "Stephanie" ,
275+ } ,
276+ ] as const
277+
278+ const onContinue = jest . fn ( )
279+ render (
280+ < Providers
281+ theme = { defaultTheme }
282+ rsiValues = { { ...mockRsiValues , fields : alternativeFields , autoMapSelectValues : false } }
283+ >
284+ < ModalWrapper isOpen = { true } onClose = { ( ) => { } } >
285+ < MatchColumnsStep headerValues = { header } data = { data } onContinue = { onContinue } />
286+ </ ModalWrapper >
287+ </ Providers > ,
288+ )
289+
290+ expect ( screen . getByText ( / 3 U n m a t c h e d / ) ) . toBeInTheDocument ( )
291+
292+ const nextButton = screen . getByRole ( "button" , {
293+ name : "Next" ,
294+ } )
295+
296+ await userEvent . click ( nextButton )
297+
298+ await waitFor ( ( ) => {
299+ expect ( onContinue ) . toBeCalled ( )
300+ } )
301+ expect ( onContinue . mock . calls [ 0 ] [ 0 ] ) . toEqual ( result )
302+ } )
303+
304+ test ( "AutoMatches select values on select" , async ( ) => {
305+ const header = [ "first name" , "count" , "Email" ]
306+ const OPTION_RESULT_ONE = "John"
307+ const OPTION_RESULT_ONE_VALUE = "1"
308+ const OPTION_RESULT_TWO = "Dane"
309+ const OPTION_RESULT_TWO_VALUE = "2"
310+ const OPTION_RESULT_THREE = "Kane"
311+ const data = [
312+ // match by option label
313+ [ OPTION_RESULT_ONE , "123" , "[email protected] " ] , 314+ // match by option value
315+ [ OPTION_RESULT_TWO_VALUE , "333" , "[email protected] " ] , 316+ // do not match
317+ [ OPTION_RESULT_THREE , "534" , "[email protected] " ] , 318+ ]
319+ const options = [
320+ { label : OPTION_RESULT_ONE , value : OPTION_RESULT_ONE_VALUE } ,
321+ { label : OPTION_RESULT_TWO , value : OPTION_RESULT_TWO_VALUE } ,
322+ ]
323+ // finds only names with automatic matching
324+ const result = [ { name : OPTION_RESULT_ONE_VALUE } , { name : OPTION_RESULT_TWO_VALUE } , { name : undefined } ]
325+
326+ const alternativeFields = [
327+ {
328+ label : "Name" ,
329+ key : "name" ,
330+ fieldType : {
331+ type : "select" ,
332+ options,
333+ } ,
334+ example : "Stephanie" ,
335+ } ,
336+ ] as const
337+
338+ const onContinue = jest . fn ( )
339+ render (
340+ < Providers
341+ theme = { defaultTheme }
342+ rsiValues = { { ...mockRsiValues , fields : alternativeFields , autoMapSelectValues : true } }
343+ >
344+ < ModalWrapper isOpen = { true } onClose = { ( ) => { } } >
345+ < MatchColumnsStep headerValues = { header } data = { data } onContinue = { onContinue } />
346+ < div id = { SELECT_DROPDOWN_ID } />
347+ </ ModalWrapper >
348+ </ Providers > ,
349+ )
350+
351+ await selectEvent . select ( screen . getByLabelText ( header [ 0 ] ) , alternativeFields [ 0 ] . label , {
352+ container : document . getElementById ( SELECT_DROPDOWN_ID ) ! ,
353+ } )
354+
355+ expect ( screen . getByText ( / 1 U n m a t c h e d / ) ) . toBeInTheDocument ( )
356+
357+ const nextButton = screen . getByRole ( "button" , {
358+ name : "Next" ,
359+ } )
360+
361+ await userEvent . click ( nextButton )
362+
363+ await waitFor ( ( ) => {
364+ expect ( onContinue ) . toBeCalled ( )
365+ } )
366+ expect ( onContinue . mock . calls [ 0 ] [ 0 ] ) . toEqual ( result )
367+ } )
368+
183369 test ( "Boolean-like values are returned as Booleans" , async ( ) => {
184370 const header = [ "namezz" , "is_cool" , "Email" ]
185371 const data = [
0 commit comments