})
Object.defineProperty(navigator, 'canShare', { value: () => true })
Object.defineProperty(window, 'ResizeObserver', { value: mock() })
+Object.defineProperty(window, 'location', {
+ configurable: true,
+ value: { reload: jest.fn() },
+})
HTMLCanvasElement.prototype.getContext = <
typeof HTMLCanvasElement.prototype.getContext
component.store.getValue()['displayLanguage'] = 'en-US'
component.store.getValue()['updateCheckingEnabled'] = false
component.settingsForm.value.displayLanguage = 'en-GB'
+ jest.spyOn(settingsService, 'storeSettings').mockReturnValue(of(true))
+ component.saveSettings()
+ expect(toast.actionName).toEqual('Reload now')
+
component.settingsForm.value.updateCheckingEnabled = true
- jest.spyOn(settingsService, 'storeSettings').mockReturnValueOnce(of(true))
component.saveSettings()
+
expect(toast.actionName).toEqual('Reload now')
+ toast.action()
})
it('should allow setting theme color, visually apply change immediately but not save', () => {
expect(changedResult.getExcludedItems()).toEqual(items)
}))
- it('FilterableDropdownSelectionModel should sort items by state', () => {
- component.items = items
+ it('selection model should sort items by state', () => {
+ component.items = items.concat([{ id: null, name: 'Null B' }])
component.selectionModel = selectionModel
selectionModel.toggle(items[1].id)
selectionModel.apply()
- expect(selectionModel.itemsSorted).toEqual([nullItem, items[1], items[0]])
+ expect(selectionModel.itemsSorted).toEqual([
+ nullItem,
+ { id: null, name: 'Null B' },
+ items[1],
+ items[0],
+ ])
})
it('should set support create, keep open model and call createRef method', fakeAsync(() => {
tick(300)
expect(createSpy).toHaveBeenCalled()
}))
+
+ it('should exclude item and trigger change event', () => {
+ const id = 1
+ const state = ToggleableItemState.Selected
+ component.selectionModel = selectionModel
+ component.manyToOne = true
+ component.selectionModel.singleSelect = true
+ component.selectionModel.intersection = Intersection.Include
+ component.selectionModel['temporarySelectionStates'].set(id, state)
+ const changedSpy = jest.spyOn(component.selectionModel.changed, 'next')
+ component.selectionModel.exclude(id)
+ expect(component.selectionModel.temporaryLogicalOperator).toBe(
+ LogicalOperator.And
+ )
+ expect(component.selectionModel['temporarySelectionStates'].get(id)).toBe(
+ ToggleableItemState.Excluded
+ )
+ expect(component.selectionModel['temporarySelectionStates'].size).toBe(1)
+ expect(changedSpy).toHaveBeenCalled()
+ })
+
+ it('should initialize selection states and apply changes', () => {
+ selectionModel.items = items
+ const map = new Map<number, ToggleableItemState>()
+ map.set(1, ToggleableItemState.Selected)
+ map.set(2, ToggleableItemState.Excluded)
+ selectionModel.init(map)
+ expect(selectionModel.getSelectedItems()).toEqual([items[0]])
+ expect(selectionModel.getExcludedItems()).toEqual([items[1]])
+ })
})
)
}
- init(map) {
+ init(map: Map<number, ToggleableItemState>) {
this.temporarySelectionStates = map
this.apply()
}
tick(3000)
expect(clearSpy).toHaveBeenCalled()
}))
+
+ it('should emit filtered documents', () => {
+ component.value = 10
+ component.items = items
+ const emitSpy = jest.spyOn(component.filterDocuments, 'emit')
+ component.onFilterDocuments()
+ expect(emitSpy).toHaveBeenCalledWith([items[2]])
+ })
+
+ it('should return the correct filter button title', () => {
+ component.title = 'Tag'
+ const expectedTitle = `Filter documents with this ${component.title}`
+ expect(component.filterButtonTitle).toEqual(expectedTitle)
+ })
})
expect(component.getTag(2)).toEqual(tags[1])
expect(component.getTag(4)).toBeUndefined()
})
+
+ it('should emit filtered documents', () => {
+ component.value = [10]
+ component.tags = tags
+ const emitSpy = jest.spyOn(component.filterDocuments, 'emit')
+ component.onFilterDocuments()
+ expect(emitSpy).toHaveBeenCalledWith([tags[2]])
+ })
})
const processingStatus = new FileStatus()
processingStatus.phase = FileStatusPhase.WORKING
expect(component.getStatusColor(processingStatus)).toEqual('primary')
+ processingStatus.phase = FileStatusPhase.UPLOADING
+ expect(component.getStatusColor(processingStatus)).toEqual('primary')
const failedStatus = new FileStatus()
failedStatus.phase = FileStatusPhase.FAILED
expect(component.getStatusColor(failedStatus)).toEqual('danger')
let guard: DirtyFormGuard
let component: DirtyComponent
let route: ActivatedRoute
+ let modalService: NgbModal
beforeEach(() => {
TestBed.configureTestingModule({
guard = TestBed.inject(DirtyFormGuard)
route = TestBed.inject(ActivatedRoute)
+ modalService = TestBed.inject(NgbModal)
const fixture = TestBed.createComponent(GenericDirtyComponent)
component = fixture.componentInstance
component.isDirty$ = true
const confirmSpy = jest.spyOn(guard, 'confirmChanges')
const canDeactivate = guard.canDeactivate(component, route.snapshot)
+ let modal
+ modalService.activeInstances.subscribe((instances) => {
+ modal = instances[0]
+ })
canDeactivate.subscribe()
expect(canDeactivate).toHaveProperty('source') // Observable
expect(confirmSpy).toHaveBeenCalled()
+ modal.componentInstance.confirmClicked.next()
})
})
})
it('should close documents', () => {
+ openDocumentsService.closeDocument({ id: 999 } as any)
subscriptions.push(
openDocumentsService.openDocument(documents[0]).subscribe()
)
subscriptions.push(
openDocumentsService.openDocument(documents[0]).subscribe()
)
+ openDocumentsService.setDirty({ id: 999 }, true) // coverage
openDocumentsService.setDirty(documents[0], false)
expect(openDocumentsService.hasDirty()).toBeFalsy()
openDocumentsService.setDirty(documents[0], true)
expect(openDocumentsService.hasDirty()).toBeTruthy()
+ let openModal
+ modalService.activeInstances.subscribe((instances) => {
+ openModal = instances[0]
+ })
const modalSpy = jest.spyOn(modalService, 'open')
subscriptions.push(
openDocumentsService.closeDocument(documents[0]).subscribe()
)
expect(modalSpy).toHaveBeenCalled()
+ openModal.componentInstance.confirmClicked.next()
})
it('should allow set dirty status, warn on closeAll', () => {
)
openDocumentsService.setDirty(documents[0], true)
expect(openDocumentsService.hasDirty()).toBeTruthy()
+ let openModal
+ modalService.activeInstances.subscribe((instances) => {
+ openModal = instances[0]
+ })
const modalSpy = jest.spyOn(modalService, 'open')
subscriptions.push(openDocumentsService.closeAll().subscribe())
expect(modalSpy).toHaveBeenCalled()
+ openModal.componentInstance.confirmClicked.next()
})
it('should load open documents from localStorage', () => {
it('should support patchMany', () => {
subscription = service.patchMany(mail_accounts).subscribe()
mail_accounts.forEach((mail_account) => {
- const reqs = httpTestingController.match(
+ const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/${mail_account.id}/`
)
- expect(reqs).toHaveLength(1)
- expect(reqs[0].request.method).toEqual('PATCH')
+ expect(req.request.method).toEqual('PATCH')
+ req.flush(mail_account)
})
+ httpTestingController.expectOne(
+ `${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000`
+ )
+ })
+
+ it('should support reload', () => {
+ service['reload']()
+ const req = httpTestingController.expectOne(
+ `${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000`
+ )
+ expect(req.request.method).toEqual('GET')
+ req.flush({ results: mail_accounts })
+ expect(service.allAccounts).toEqual(mail_accounts)
})
beforeEach(() => {
it('should support patchMany', () => {
subscription = service.patchMany(mail_rules).subscribe()
mail_rules.forEach((mail_rule) => {
- const reqs = httpTestingController.match(
+ const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/${mail_rule.id}/`
)
- expect(reqs).toHaveLength(1)
- expect(reqs[0].request.method).toEqual('PATCH')
+ expect(req.request.method).toEqual('PATCH')
+ req.flush(mail_rule)
})
+ const reloadReq = httpTestingController.expectOne(
+ `${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000`
+ )
+ reloadReq.flush({ results: mail_rules })
+ })
+
+ it('should support reload', () => {
+ service['reload']()
+ const req = httpTestingController.expectOne(
+ `${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000`
+ )
+ expect(req.request.method).toEqual('GET')
+ req.flush({ results: mail_rules })
+ expect(service.allRules).toEqual(mail_rules)
})
beforeEach(() => {