@@ -25,34 +25,34 @@ jest.mock('antd', () => {
2525 const React = require ( 'react' ) ;
2626 // eslint-disable-next-line @typescript-eslint/no-shadow
2727 const antd = jest . requireActual ( 'antd' ) ;
28- const OldUpload = antd . Upload ;
29- const Upload : React . FC < UploadProps > = ( { children, onChange, ...rest } ) => {
28+ const Upload : React . FC < UploadProps > = ( { children, onChange } ) => {
3029 return (
31- < OldUpload
32- { ...rest }
33- onChange = { ( data : UploadChangeParam ) => {
34- const file = data . file ;
35- const response = { } ;
36- onChange ?.( {
37- ...data ,
38- file : {
39- status : 'success' ,
40- response : file . name
41- ? {
42- success : true ,
43- err : { } ,
44- data : {
45- ...file ,
46- url : 'filePath' ,
47- } ,
48- }
49- : undefined ,
50- } ,
51- } ) ;
52- } }
53- >
30+ < label >
31+ < input
32+ type = "file"
33+ onChange = { ( e ) => {
34+ const file = e . target . files ?. [ 0 ] ;
35+ if ( ! file ) return ;
36+ onChange ?.( {
37+ file : {
38+ ...file ,
39+ status : 'success' ,
40+ response : {
41+ success : true ,
42+ err : { } ,
43+ data : {
44+ name : file . name ,
45+ size : file . size ,
46+ url : 'filePath' ,
47+ } ,
48+ } ,
49+ } ,
50+ } as UploadChangeParam ) ;
51+ } }
52+ style = { { display : 'none' } }
53+ />
5454 { children }
55- </ OldUpload >
55+ </ label >
5656 ) ;
5757 } ;
5858 return {
@@ -65,6 +65,15 @@ describe('UploadPlugin', () => {
6565 const images = new File ( [ 'this is an images' ] , 'logo.png' , {
6666 type : 'image/png' ,
6767 } ) ;
68+ const kbFile = new File ( [ new ArrayBuffer ( 1024 ) ] , 'small.bin' , {
69+ type : 'application/octet-stream' ,
70+ } ) ;
71+ const mbFile = new File ( [ new ArrayBuffer ( 2 * 1024 * 1024 ) ] , 'big.bin' , {
72+ type : 'application/octet-stream' ,
73+ } ) ;
74+ const decimalFile = new File ( [ new Uint8Array ( 1500 ) ] , 'decimal.bin' , {
75+ type : 'application/octet-stream' ,
76+ } ) ;
6877 beforeAll ( ( ) => {
6978 jest . mock ( 'agent' ) ;
7079 agent . post = ( ) => ( {
@@ -100,7 +109,25 @@ describe('UploadPlugin', () => {
100109 userEvent . upload ( imageUpload , images ) ;
101110 await flushPromises ( ) ;
102111 } ) ;
103- expect ( insertTextFn ) . toHaveBeenLastCalledWith ( '\n\n' ) ;
112+ expect ( insertTextFn ) . toHaveBeenLastCalledWith ( '\n\n' ) ;
113+
114+ await act ( async ( ) => {
115+ userEvent . upload ( imageUpload , kbFile ) ;
116+ await flushPromises ( ) ;
117+ } ) ;
118+ expect ( insertTextFn ) . toHaveBeenLastCalledWith ( '\n\n' ) ;
119+
120+ await act ( async ( ) => {
121+ userEvent . upload ( imageUpload , mbFile ) ;
122+ await flushPromises ( ) ;
123+ } ) ;
124+ expect ( insertTextFn ) . toHaveBeenLastCalledWith ( '\n\n' ) ;
125+
126+ await act ( async ( ) => {
127+ userEvent . upload ( imageUpload , decimalFile ) ;
128+ await flushPromises ( ) ;
129+ } ) ;
130+ expect ( insertTextFn ) . toHaveBeenLastCalledWith ( '\n\n' ) ;
104131 spyOnError . mockClear ( ) ;
105132 } ) ;
106133} ) ;
0 commit comments