@@ -109,6 +109,45 @@ describe('LiveController rendering Tests', () => {
109
109
expect ( ( test . queryByDataModel ( 'comment' ) as HTMLTextAreaElement ) . value ) . toEqual ( 'I HAD A GREAT TIME' ) ;
110
110
} ) ;
111
111
112
+ it ( 'keeps file input value after a render request' , async ( ) => {
113
+ const test = await createTest (
114
+ { } ,
115
+ ( ) => `
116
+ <div ${ initComponent ( { } , { debounce : 1 } ) } >
117
+ <input type="file" data-model="file">
118
+ <button data-action="live#$render">Reload</button>
119
+ </div>
120
+ `
121
+ ) ;
122
+
123
+ const fileInput = test . element . querySelector ( 'input[type="file"]' ) as HTMLInputElement ;
124
+ const file = new File ( [ 'content' ] , 'test.txt' , { type : 'text/plain' } ) ;
125
+
126
+ Object . defineProperty ( fileInput , 'files' , {
127
+ value : [ file ] ,
128
+ writable : false ,
129
+ } ) ;
130
+
131
+ // Checks that the file is correctly assigned before rendering
132
+ expect ( fileInput . files ) . not . toBeNull ( ) ;
133
+ expect ( fileInput . files ?. length ) . toBe ( 1 ) ;
134
+ expect ( fileInput . files ?. [ 0 ] . name ) . toBe ( 'test.txt' ) ;
135
+
136
+ // Simulates an AJAX request triggered by Live rendering
137
+ test . expectsAjaxCall ( )
138
+ . expectUpdatedData ( { } )
139
+ . delayResponse ( 100 ) ;
140
+
141
+ getByText ( test . element , 'Reload' ) . click ( ) ;
142
+
143
+ // Checks that the file is still present after rendering
144
+ await waitFor ( ( ) => {
145
+ expect ( fileInput . files ) . not . toBeNull ( ) ;
146
+ expect ( fileInput . files ?. length ) . toBe ( 1 ) ;
147
+ expect ( fileInput . files ?. [ 0 ] . name ) . toBe ( 'test.txt' ) ;
148
+ } ) ;
149
+ } ) ;
150
+
112
151
it ( 'conserves the value of an unmapped field that was modified after a render request' , async ( ) => {
113
152
const test = await createTest (
114
153
{ title : 'greetings' } ,
0 commit comments