Fix these test specs

This commit is contained in:
shamoon
2026-07-08 18:09:43 -07:00
parent 1c2457a3a7
commit d01d4984cb
5 changed files with 32 additions and 32 deletions
@@ -465,7 +465,7 @@ describe('GlobalSearchComponent', () => {
const closeSpy = jest.spyOn(component.resultsDropdown, 'close')
component['reset'](true)
expect(debounce).toHaveBeenCalledWith(null)
expect(component.searchResults).toBeNull()
expect(component.searchResults()).toBeNull()
expect(component['currentItemIndex']).toBe(-1)
expect(closeSpy).toHaveBeenCalled()
})
@@ -24,8 +24,8 @@ describe('PageHeaderComponent', () => {
})
it('should display title + subtitle', () => {
component.title = 'Foo'
component.subTitle = 'Bar'
fixture.componentRef.setInput('title', 'Foo')
fixture.componentRef.setInput('subTitle', 'Bar')
fixture.detectChanges()
expect(fixture.nativeElement.textContent).toContain('Foo')
expect(fixture.nativeElement.textContent).toContain('Bar')
@@ -33,19 +33,19 @@ describe('PageHeaderComponent', () => {
it('should set html title', () => {
const titleSpy = jest.spyOn(titleService, 'setTitle')
component.title = 'Foo Bar'
fixture.componentRef.setInput('title', 'Foo Bar')
expect(titleSpy).toHaveBeenCalledWith(`Foo Bar - ${environment.appTitle}`)
})
it('should copy id to clipboard, reset after 3 seconds', () => {
jest.useFakeTimers()
component.id = 42 as any
fixture.componentRef.setInput('id', 42)
jest.spyOn(clipboard, 'copy').mockReturnValue(true)
component.copyID()
expect(clipboard.copy).toHaveBeenCalledWith('42')
expect(component.copied).toBe(true)
expect(component.copied()).toBe(true)
jest.advanceTimersByTime(3000)
expect(component.copied).toBe(false)
expect(component.copied()).toBe(false)
})
})
@@ -56,7 +56,7 @@ describe('ShareLinksDialogComponent', () => {
it('should support refresh to retrieve links', () => {
const getSpy = jest.spyOn(shareLinkService, 'getLinksForDocument')
component.documentId = 99
fixture.componentRef.setInput('documentId', 99)
const now = new Date()
const expiration7days = new Date()
@@ -88,7 +88,7 @@ describe('ShareLinksDialogComponent', () => {
fixture.detectChanges()
expect(component.shareLinks).toHaveLength(2)
expect(component.shareLinks()).toHaveLength(2)
})
it('should show error on refresh if needed', () => {
@@ -96,7 +96,7 @@ describe('ShareLinksDialogComponent', () => {
jest
.spyOn(shareLinkService, 'getLinksForDocument')
.mockReturnValueOnce(throwError(() => new Error('Unable to get links')))
component.documentId = 99
fixture.componentRef.setInput('documentId', 99)
component.ngOnInit()
fixture.detectChanges()
@@ -105,7 +105,7 @@ describe('ShareLinksDialogComponent', () => {
it('should support link creation then refresh & copy url', fakeAsync(() => {
const createSpy = jest.spyOn(shareLinkService, 'createLinkForDocument')
component.documentId = 99
fixture.componentRef.setInput('documentId', 99)
component.expirationDays = 7
component.useArchiveVersion = false
@@ -130,12 +130,12 @@ describe('ShareLinksDialogComponent', () => {
expect(refreshSpy).toHaveBeenCalled()
expect(copySpy).toHaveBeenCalled()
expect(component.copied).toEqual(1)
expect(component.copied()).toEqual(1)
tick(100) // copy timeout
}))
it('should show error on link creation if needed', () => {
component.documentId = 99
fixture.componentRef.setInput('documentId', 99)
component.expirationDays = 7
const expiration = new Date()
@@ -227,7 +227,7 @@ describe('ShareLinksDialogComponent', () => {
})
it('should disable archive switch & option if no archive available', (done) => {
component.hasArchiveVersion = false
fixture.componentRef.setInput('hasArchiveVersion', false)
component.ngOnInit()
fixture.detectChanges()
expect(component.useArchiveVersion).toBeFalsy()
@@ -22,25 +22,25 @@ describe('SuggestionsDropdownComponent', () => {
})
it('should calculate totalSuggestions', () => {
component.suggestions = {
fixture.componentRef.setInput('suggestions', {
suggested_correspondents: ['John Doe'],
suggested_tags: ['Tag1', 'Tag2'],
suggested_document_types: ['Type1'],
}
})
expect(component.totalSuggestions).toBe(4)
})
it('should emit getSuggestions when clickSuggest is called and suggestions are null', () => {
jest.spyOn(component.getSuggestions, 'emit')
component.suggestions = null
fixture.componentRef.setInput('suggestions', null)
component.clickSuggest()
expect(component.getSuggestions.emit).toHaveBeenCalled()
})
it('should not emit getSuggestions when disabled', () => {
jest.spyOn(component.getSuggestions, 'emit')
component.disabled = true
component.suggestions = null
fixture.componentRef.setInput('disabled', true)
fixture.componentRef.setInput('suggestions', null)
fixture.detectChanges()
component.clickSuggest()
@@ -50,13 +50,13 @@ describe('SuggestionsDropdownComponent', () => {
})
it('should toggle dropdown when clickSuggest is called and suggestions are not null', () => {
component.aiEnabled = true
fixture.componentRef.setInput('aiEnabled', true)
fixture.detectChanges()
component.suggestions = {
fixture.componentRef.setInput('suggestions', {
suggested_correspondents: [],
suggested_tags: [],
suggested_document_types: [],
}
})
component.clickSuggest()
expect(component.dropdown.open).toBeTruthy()
})
@@ -64,7 +64,7 @@ describe('ProcessedMailDialogComponent', () => {
toastService = TestBed.inject(ToastService)
fixture = TestBed.createComponent(ProcessedMailDialogComponent)
component = fixture.componentInstance
component.rule = rule
fixture.componentRef.setInput('rule', rule)
})
afterEach(() => {
@@ -83,8 +83,8 @@ describe('ProcessedMailDialogComponent', () => {
fixture.detectChanges()
const req = expectListRequest(rule.id)
req.flush({ count: 2, results: mails })
expect(component.loading).toBeFalsy()
expect(component.processedMails).toEqual(mails)
expect(component.loading()).toBeFalsy()
expect(component.processedMails()).toEqual(mails)
})
it('should delete selected mails and reload', () => {
@@ -94,8 +94,8 @@ describe('ProcessedMailDialogComponent', () => {
initialReq.flush({ count: 0, results: [] })
// select a couple of mails and delete
component.selectedMailIds.add(5)
component.selectedMailIds.add(6)
component.selectedMailIds().add(5)
component.selectedMailIds().add(6)
const toastInfoSpy = jest.spyOn(toastService, 'showInfo')
component.deleteSelected()
@@ -127,18 +127,18 @@ describe('ProcessedMailDialogComponent', () => {
header.dispatchEvent(new Event('click'))
header.checked = true
header.dispatchEvent(new Event('click'))
expect(component.selectedMailIds.size).toEqual(mails.length)
expect(component.selectedMailIds().size).toEqual(mails.length)
// toggle a single mail
component.toggleSelected(mails[0] as any)
expect(component.selectedMailIds.has(mails[0].id)).toBeFalsy()
expect(component.selectedMailIds().has(mails[0].id)).toBeFalsy()
component.toggleSelected(mails[0] as any)
expect(component.selectedMailIds.has(mails[0].id)).toBeTruthy()
expect(component.selectedMailIds().has(mails[0].id)).toBeTruthy()
// clear selection
component.clearSelection()
expect(component.selectedMailIds.size).toEqual(0)
expect(component.toggleAllEnabled).toBeFalsy()
expect(component.selectedMailIds().size).toEqual(0)
expect(component.toggleAllEnabled()).toBeFalsy()
})
it('should close the dialog', () => {