File tree Expand file tree Collapse file tree
src/components/inputs/upload-input-v3 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ describe('UploadInputV3', () => {
4444 type : {
4545 allowed_extensions : [ 'pdf' , 'jpg' , 'png' ]
4646 } ,
47- max_size : 1024000
47+ max_size : 10485760
4848 }
4949 } ;
5050
@@ -139,14 +139,14 @@ describe('UploadInputV3', () => {
139139 test ( 'shows default size when size is not provided' , ( ) => {
140140 const files = [ { filename : 'no-size.pdf' } ] ;
141141 const wrapper = mount ( < UploadInputV3 { ...defaultProps } value = { files } /> ) ;
142- expect ( wrapper . text ( ) ) . toContain ( '100kb ' ) ;
142+ expect ( wrapper . text ( ) ) . toContain ( '0 KB ' ) ;
143143 wrapper . unmount ( ) ;
144144 } ) ;
145145
146146 test ( 'formats file size correctly' , ( ) => {
147147 const files = [ { filename : 'large-file.pdf' , size : 2048000 } ] ;
148148 const wrapper = mount ( < UploadInputV3 { ...defaultProps } value = { files } /> ) ;
149- expect ( wrapper . text ( ) ) . toContain ( '2000kb ' ) ;
149+ expect ( wrapper . text ( ) ) . toContain ( '2 MB ' ) ;
150150 wrapper . unmount ( ) ;
151151 } ) ;
152152 } ) ;
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ export const DropzoneV3 = ({
4444 if ( eventHandlers . removedfile ) eventHandlers . removedfile ( file ) ;
4545 } ,
4646 uploadprogress : ( file , progress , bytesSent ) => {
47- if ( onUploadProgress ) onUploadProgress ( file , bytesSent / file . size * 100 ) ;
47+ if ( onUploadProgress ) onUploadProgress ( file , file . size > 0 ? bytesSent / file . size * 100 : 0 ) ;
4848 if ( eventHandlers . uploadprogress ) eventHandlers . uploadprogress ( file , progress , bytesSent ) ;
4949 } ,
5050 success : ( file ) => {
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ const UploadInputV3 = ({
6060 } , [ mediaType ] ) ;
6161
6262 const getDefaultMaxSize = useCallback ( ( ) => {
63- return mediaType ? mediaType ?. max_size / 1024 : 100 ;
63+ return mediaType ? mediaType ?. max_size / ( 1024 * 1024 ) : 100 ;
6464 } , [ mediaType ] ) ;
6565
6666 const allowedExt = useMemo ( ( ) =>
@@ -112,8 +112,9 @@ const UploadInputV3 = ({
112112 } ) , [ mediaType , value ] ) ;
113113
114114 const formatFileSize = useCallback ( ( bytes ) => {
115- if ( ! bytes ) return '100kb' ;
116- return `${ Math . round ( bytes / 1024 ) } kb` ;
115+ if ( ! bytes ) return '0 KB' ;
116+ if ( bytes >= 1024 * 1024 ) return `${ Math . round ( bytes / ( 1024 * 1024 ) ) } MB` ;
117+ return `${ Math . round ( bytes / 1024 ) } KB` ;
117118 } , [ ] ) ;
118119
119120 const formatExtensionsDisplay = useCallback ( ( ) => {
You can’t perform that action at this time.
0 commit comments