@@ -105,7 +105,7 @@ describe('DropzoneController', () => {
105105 expect ( dispatched ) . toBe ( true ) ;
106106 } ) ;
107107
108- it ( 'file chosen' , async ( ) => {
108+ it ( 'single file chosen' , async ( ) => {
109109 startStimulus ( ) ;
110110 await waitFor ( ( ) => expect ( getByTestId ( container , 'input' ) ) . toHaveStyle ( { display : 'block' } ) ) ;
111111
@@ -126,6 +126,35 @@ describe('DropzoneController', () => {
126126
127127 // The event should have been dispatched
128128 expect ( dispatched ) . not . toBeNull ( ) ;
129- expect ( dispatched . detail ) . toStrictEqual ( file ) ;
129+ expect ( dispatched . detail [ 0 ] ) . toStrictEqual ( file ) ;
130+ } ) ;
131+
132+ it ( 'multiple files chosen' , async ( ) => {
133+ startStimulus ( ) ;
134+ await waitFor ( ( ) => expect ( getByTestId ( container , 'input' ) ) . toHaveStyle ( { display : 'block' } ) ) ;
135+
136+ // Attach a listener to ensure the event is dispatched
137+ let dispatched = null ;
138+ getByTestId ( container , 'container' ) . addEventListener ( 'dropzone:change' , ( event ) => ( dispatched = event ) ) ;
139+
140+ // Select the file
141+ const input = getByTestId ( container , 'input' ) ;
142+ const files = [
143+ new File ( [ 'hello' ] , 'hello.png' , { type : 'image/png' } ) ,
144+ new File ( [ 'again' ] , 'again.png' , { type : 'image/png' } ) ,
145+ ]
146+
147+ user . upload ( input , files ) ;
148+ expect ( input . files [ 0 ] ) . toStrictEqual ( files [ 0 ] ) ;
149+ expect ( input . files [ 1 ] ) . toStrictEqual ( files [ 1 ] ) ;
150+
151+ // The dropzone should be in preview mode
152+ await waitFor ( ( ) => expect ( getByTestId ( container , 'input' ) ) . toHaveStyle ( { display : 'none' } ) ) ;
153+ await waitFor ( ( ) => expect ( getByTestId ( container , 'placeholder' ) ) . toHaveStyle ( { display : 'none' } ) ) ;
154+
155+ // The event should have been dispatched
156+ expect ( dispatched ) . not . toBeNull ( ) ;
157+ expect ( dispatched . detail [ 0 ] ) . toStrictEqual ( files [ 0 ] ) ;
158+ expect ( dispatched . detail [ 1 ] ) . toStrictEqual ( files [ 1 ] ) ;
130159 } ) ;
131160} ) ;
0 commit comments