Fix/Chore: replace file drop package (#9926)

This commit is contained in:
shamoon
2025-05-12 23:05:34 -07:00
committed by GitHub
parent 2c9e690dfb
commit 0ab85b5122
13 changed files with 319 additions and 576 deletions

View File

@@ -82,10 +82,20 @@ describe('UploadFileWidgetComponent', () => {
})
it('should upload files', () => {
const uploadSpy = jest.spyOn(uploadDocumentsService, 'uploadFiles')
fixture.debugElement
.query(By.css('input'))
.nativeElement.dispatchEvent(new Event('change'))
const uploadSpy = jest.spyOn(uploadDocumentsService, 'uploadFile')
const file = new File(
[new Blob(['testing'], { type: 'application/pdf' })],
'file.pdf'
)
const fileInput = fixture.debugElement.query(By.css('input'))
jest.spyOn(fileInput.nativeElement, 'files', 'get').mockReturnValue({
item: () => file,
length: 1,
[Symbol.iterator]: () => ({
next: () => ({ done: false, value: file }),
}),
} as any)
fileInput.nativeElement.dispatchEvent(new Event('change'))
expect(uploadSpy).toHaveBeenCalled()
})

View File

@@ -134,9 +134,11 @@ export class UploadFileWidgetComponent extends ComponentWithPermissions {
}
public onFileSelected(event: Event) {
this.uploadDocumentsService.uploadFiles(
(event.target as HTMLInputElement).files
)
const files = (event.target as HTMLInputElement).files
for (let i = 0; i < files?.length; i++) {
const file = files.item(i)
file && this.uploadDocumentsService.uploadFile(file)
}
}
get slimSidebarEnabled(): boolean {