@@ -2966,6 +2966,62 @@ describe('FormViewer.vue', () => {
29662966 expect ( getDispositionSpy ) . toBeCalledTimes ( 1 ) ;
29672967 } ) ;
29682968
2969+ it ( 'getFile will download json file as blob' , async ( ) => {
2970+ const jsonBlob = new Blob ( [ JSON . stringify ( { testKey : 'testValue' } ) ] , {
2971+ type : 'application/json' ,
2972+ } ) ;
2973+
2974+ const createObjectURLSpy = vi
2975+ . spyOn ( window . URL , 'createObjectURL' )
2976+ . mockReturnValue ( 'blob:test-url' ) ;
2977+
2978+ const revokeObjectURLSpy = vi
2979+ . spyOn ( window . URL , 'revokeObjectURL' )
2980+ . mockImplementation ( ( ) => { } ) ;
2981+
2982+ downloadFileSpy . mockImplementationOnce ( ( ) => {
2983+ formStore . downloadedFile = {
2984+ headers : {
2985+ 'content-type' : 'application/json' ,
2986+ 'content-disposition' : 'attachment; filename="test.json"' ,
2987+ } ,
2988+ data : jsonBlob ,
2989+ } ;
2990+ } ) ;
2991+
2992+ const wrapper = shallowMount ( FormViewer , {
2993+ props : {
2994+ formId,
2995+ submissionId : '123' ,
2996+ } ,
2997+ global : {
2998+ provide : {
2999+ setWideLayout : vi . fn ( ) ,
3000+ } ,
3001+ plugins : [ pinia ] ,
3002+ stubs : STUBS ,
3003+ } ,
3004+ } ) ;
3005+
3006+ await flushPromises ( ) ;
3007+
3008+ await wrapper . vm . getFile ( 'asdf' ) ;
3009+
3010+ expect ( downloadFileSpy ) . toBeCalledTimes ( 1 ) ;
3011+ expect ( downloadFileSpy ) . toHaveBeenCalledWith ( 'asdf' , expect . anything ( ) ) ;
3012+
3013+ expect ( createObjectURLSpy ) . toHaveBeenCalledTimes ( 1 ) ;
3014+ expect ( createObjectURLSpy ) . toHaveBeenCalledWith ( jsonBlob ) ;
3015+
3016+ expect ( getDispositionSpy ) . toBeCalledTimes ( 1 ) ;
3017+ expect ( getDispositionSpy ) . toHaveBeenCalledWith (
3018+ 'attachment; filename="test.json"'
3019+ ) ;
3020+
3021+ createObjectURLSpy . mockRestore ( ) ;
3022+ revokeObjectURLSpy . mockRestore ( ) ;
3023+ } ) ;
3024+
29693025 it ( 'uploadFile will call fileServices uploadFile' , async ( ) => {
29703026 const uploadFileSpy = vi . spyOn ( fileService , 'uploadFile' ) ;
29713027 uploadFileSpy . mockImplementation ( ( ) => { } ) ;
0 commit comments