@@ -12,6 +12,8 @@ import { StepType } from "../../UploadFlow"
1212const MUTATED_HEADER = "mutated header"
1313const CONTINUE_BUTTON = "Next"
1414const ERROR_MESSAGE = "Something happened"
15+ const RAW_DATE = "2020-03-03"
16+ const FORMATTED_DATE = "2020/03/03"
1517
1618test ( "Select header row and click next" , async ( ) => {
1719 const data = [
@@ -69,11 +71,11 @@ test("selectHeaderStepHook should be called after header is selected", async ()
6971 fireEvent . click ( continueButton )
7072 await waitFor ( ( ) => {
7173 expect ( selectHeaderStepHook ) . toBeCalledWith (
72- [ "name" , "age" ] ,
74+ [ "name" , "age" , "date" ] ,
7375 [
74- [ "Josh" , "2" ] ,
75- [ "Charlie" , "3" ] ,
76- [ "Lena" , "50" ] ,
76+ [ "Josh" , "2" , "2020-03-03" ] ,
77+ [ "Charlie" , "3" , "2010-04-04" ] ,
78+ [ "Lena" , "50" , "1994-02-27" ] ,
7779 ] ,
7880 )
7981 } )
@@ -134,3 +136,35 @@ test("Should show error toast if error is thrown in selectHeaderStepHook", async
134136 expect ( errorToast ) . toBeInTheDocument ( )
135137 } )
136138} )
139+
140+ test ( "dateFormat property should be applied to dates read from csv files" , async ( ) => {
141+ const file = new File ( [ RAW_DATE ] , "test.csv" , {
142+ type : "text/csv" ,
143+ } )
144+ render ( < ReactSpreadsheetImport { ...mockRsiValues } dateFormat = "yyyy/mm/dd" /> )
145+
146+ const uploader = screen . getByTestId ( "rsi-dropzone" )
147+ fireEvent . drop ( uploader , {
148+ target : { files : [ file ] } ,
149+ } )
150+
151+ const el = await screen . findByText ( FORMATTED_DATE , undefined , { timeout : 5000 } )
152+ expect ( el ) . toBeInTheDocument ( )
153+ } )
154+
155+ test ( "dateFormat property should be applied to dates read from xlsx files" , async ( ) => {
156+ render ( < ReactSpreadsheetImport { ...mockRsiValues } dateFormat = "yyyy/mm/dd" /> )
157+ const uploader = screen . getByTestId ( "rsi-dropzone" )
158+ const data = readFileSync ( __dirname + "/../../../../static/Workbook2.xlsx" )
159+ fireEvent . drop ( uploader , {
160+ target : {
161+ files : [
162+ new File ( [ data ] , "testFile.xlsx" , {
163+ type : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ,
164+ } ) ,
165+ ] ,
166+ } ,
167+ } )
168+ const el = await screen . findByText ( FORMATTED_DATE , undefined , { timeout : 10000 } )
169+ expect ( el ) . toBeInTheDocument ( )
170+ } )
0 commit comments