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