-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #344 from PermanentOrg/PER-8276-inform-user-about-…
…upload-destination PEr-8276 inform user about upload destination
- Loading branch information
Showing
5 changed files
with
196 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/app/core/components/upload-progress/upload-progress.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* @format */ | ||
import { UploadService } from '@core/services/upload/upload.service'; | ||
import { CoreModule } from '@core/core.module'; | ||
import { EventEmitter } from '@angular/core'; | ||
import { Shallow } from 'shallow-render'; | ||
import { | ||
UploadProgressEvent, | ||
UploadSessionStatus, | ||
} from '@core/services/upload/upload.session'; | ||
import { UploadItem } from '@core/services/upload/uploadItem'; | ||
import { FolderVO } from '@models/index'; | ||
import { UploadProgressComponent } from './upload-progress.component'; | ||
|
||
class MockUploadSession { | ||
public progress = new EventEmitter<UploadProgressEvent>(); | ||
} | ||
|
||
const mockUploadService = { | ||
registerComponent: () => {}, | ||
uploadSession: new MockUploadSession(), | ||
getTargetFolderId: () => { | ||
return 10; | ||
}, | ||
getTargetFolderName: () => { | ||
return 'testfolder'; | ||
}, | ||
}; | ||
|
||
describe('UploadProgressComponent', () => { | ||
let shallow: Shallow<UploadProgressComponent>; | ||
|
||
beforeEach(() => { | ||
shallow = new Shallow(UploadProgressComponent, CoreModule).mock( | ||
UploadService, | ||
mockUploadService | ||
); | ||
}); | ||
|
||
it('should create', async () => { | ||
const { instance } = await shallow.render(); | ||
|
||
expect(instance).toBeTruthy(); | ||
}); | ||
|
||
it('should become visible when show() is called', async () => { | ||
const { instance } = await shallow.render(); | ||
instance.show(); | ||
|
||
expect(instance.visible).toBe(true); | ||
}); | ||
|
||
it('should display the correct file name and the folder when dragging the file into a folder', async () => { | ||
const { find, instance, fixture } = await shallow.render(); | ||
|
||
const mockContent = new Uint8Array(10000); | ||
const progressEvent = { | ||
item: new UploadItem( | ||
new File([mockContent], 'testfile.txt'), | ||
new FolderVO({ | ||
displayName: 'testfolder', | ||
pathAsArchiveNbr: [], | ||
folderId: 10, | ||
}) | ||
), | ||
statistics: { current: 1, total: 5, completed: 0, error: 0 }, | ||
sessionStatus: UploadSessionStatus.InProgress, | ||
}; | ||
|
||
mockUploadService.uploadSession.progress.emit(progressEvent); | ||
|
||
fixture.detectChanges(); | ||
|
||
expect(find('.current-file').nativeElement.textContent.trim()).toBe( | ||
`Uploading ${progressEvent.item.file.name} to ${progressEvent.item.parentFolder.displayName}` | ||
); | ||
|
||
const fileCountElements = find('.file-count strong'); | ||
|
||
expect(fileCountElements[0].nativeElement.textContent).toEqual('1'); | ||
|
||
expect(fileCountElements[1].nativeElement.textContent).toEqual('5'); | ||
}); | ||
|
||
it('should display the correct file name, the target folder and the current folder when dragging a file nested into a folder over a folder', async () => { | ||
const { find, instance, fixture } = await shallow.render(); | ||
|
||
const mockContent = new Uint8Array(10000); | ||
const progressEvent = { | ||
item: new UploadItem( | ||
new File([mockContent], 'testfile.txt'), | ||
new FolderVO({ | ||
displayName: 'testfolder1', | ||
pathAsArchiveNbr: [], | ||
folderId: 9, | ||
}) | ||
), | ||
statistics: { current: 1, total: 5, completed: 0, error: 0 }, | ||
sessionStatus: UploadSessionStatus.InProgress, | ||
}; | ||
|
||
mockUploadService.uploadSession.progress.emit(progressEvent); | ||
|
||
fixture.detectChanges(); | ||
|
||
expect(find('.current-file').nativeElement.textContent.trim()).toBe( | ||
`Uploading ${progressEvent.item.file.name} to testfolder/${progressEvent.item.parentFolder.displayName}` | ||
); | ||
|
||
const fileCountElements = find('.file-count strong'); | ||
|
||
expect(fileCountElements[0].nativeElement.textContent).toEqual('1'); | ||
|
||
expect(fileCountElements[1].nativeElement.textContent).toEqual('5'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters