Added frontend tests

This commit is contained in:
Łukasz Czyż 2023-12-16 22:34:29 +01:00
parent e1abf6f7f0
commit abbd0f7118
2 changed files with 17 additions and 8 deletions

View File

@ -802,30 +802,37 @@ describe('BulkEditorComponent', () => {
.spyOn(documentListViewService, 'documents', 'get') .spyOn(documentListViewService, 'documents', 'get')
.mockReturnValue([{ id: 3 }, { id: 4 }]) .mockReturnValue([{ id: 3 }, { id: 4 }])
jest jest
.spyOn(documentListViewService, 'selected', 'get') .spyOn(documentListViewService, 'getSelectedInOrder')
.mockReturnValue(new Set([3, 4])) .mockReturnValue(new Array(3, 4))
jest jest
.spyOn(permissionsService, 'currentUserHasObjectPermissions') .spyOn(permissionsService, 'currentUserHasObjectPermissions')
.mockReturnValue(true) .mockReturnValue(true)
component.downloadForm.get('downloadAsSingleFile').patchValue(false)
component.downloadForm.get('downloadFileTypeArchive').patchValue(true) component.downloadForm.get('downloadFileTypeArchive').patchValue(true)
fixture.detectChanges() fixture.detectChanges()
let downloadSpy = jest.spyOn(documentService, 'bulkDownload') let downloadSpy = jest.spyOn(documentService, 'bulkDownload')
//archive //archive
component.downloadSelected() component.downloadSelected()
expect(downloadSpy).toHaveBeenCalledWith([3, 4], 'archive', false) expect(downloadSpy).toHaveBeenCalledWith([3, 4], 'archive', false, false)
//originals //originals
component.downloadForm.get('downloadFileTypeArchive').patchValue(false) component.downloadForm.get('downloadFileTypeArchive').patchValue(false)
component.downloadForm.get('downloadFileTypeOriginals').patchValue(true) component.downloadForm.get('downloadFileTypeOriginals').patchValue(true)
component.downloadSelected() component.downloadSelected()
expect(downloadSpy).toHaveBeenCalledWith([3, 4], 'originals', false) expect(downloadSpy).toHaveBeenCalledWith([3, 4], 'originals', false, false)
//both //both
component.downloadForm.get('downloadFileTypeArchive').patchValue(true) component.downloadForm.get('downloadFileTypeArchive').patchValue(true)
component.downloadSelected() component.downloadSelected()
expect(downloadSpy).toHaveBeenCalledWith([3, 4], 'both', false) expect(downloadSpy).toHaveBeenCalledWith([3, 4], 'both', false, false)
//formatting //formatting
component.downloadForm.get('downloadUseFormatting').patchValue(true) component.downloadForm.get('downloadUseFormatting').patchValue(true)
component.downloadSelected() component.downloadSelected()
expect(downloadSpy).toHaveBeenCalledWith([3, 4], 'both', true) expect(downloadSpy).toHaveBeenCalledWith([3, 4], 'both', false, true)
//merging
component.downloadForm.get('downloadFileTypeOriginals').patchValue(true)
component.downloadForm.get('downloadFileTypeArchive').patchValue(false)
component.downloadForm.get('downloadAsSingleFile').patchValue(true)
component.downloadSelected()
expect(downloadSpy).toHaveBeenCalledWith([3, 4], 'originals', true, false)
httpTestingController.match( httpTestingController.match(
`${environment.apiBaseUrl}documents/bulk_download/` `${environment.apiBaseUrl}documents/bulk_download/`

View File

@ -137,10 +137,11 @@ describe(`DocumentService`, () => {
it('should call appropriate api endpoint for bulk download', () => { it('should call appropriate api endpoint for bulk download', () => {
const ids = [1, 2, 3] const ids = [1, 2, 3]
const content = 'both' const content = 'originals'
const mergeIntoSingleFile = false
const useFilenameFormatting = false const useFilenameFormatting = false
subscription = service subscription = service
.bulkDownload(ids, content, useFilenameFormatting) .bulkDownload(ids, content, mergeIntoSingleFile, useFilenameFormatting)
.subscribe() .subscribe()
const req = httpTestingController.expectOne( const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/bulk_download/` `${environment.apiBaseUrl}${endpoint}/bulk_download/`
@ -149,6 +150,7 @@ describe(`DocumentService`, () => {
expect(req.request.body).toEqual({ expect(req.request.body).toEqual({
documents: ids, documents: ids,
content, content,
single_file: mergeIntoSingleFile,
follow_formatting: useFilenameFormatting, follow_formatting: useFilenameFormatting,
}) })
}) })