From d01d4984cb8088dd4a5e1c83176149950df567b4 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 8 Jul 2026 18:09:43 -0700 Subject: [PATCH] Fix these test specs --- .../global-search.component.spec.ts | 2 +- .../page-header/page-header.component.spec.ts | 12 +++++------ .../share-links-dialog.component.spec.ts | 14 ++++++------- .../suggestions-dropdown.component.spec.ts | 16 +++++++-------- .../processed-mail-dialog.component.spec.ts | 20 +++++++++---------- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts b/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts index d605cde89..95ec55d24 100644 --- a/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts +++ b/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts @@ -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() }) diff --git a/src-ui/src/app/components/common/page-header/page-header.component.spec.ts b/src-ui/src/app/components/common/page-header/page-header.component.spec.ts index 8fa9ad369..86c3ec079 100644 --- a/src-ui/src/app/components/common/page-header/page-header.component.spec.ts +++ b/src-ui/src/app/components/common/page-header/page-header.component.spec.ts @@ -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) }) }) diff --git a/src-ui/src/app/components/common/share-links-dialog/share-links-dialog.component.spec.ts b/src-ui/src/app/components/common/share-links-dialog/share-links-dialog.component.spec.ts index 05915c09e..92bc06634 100644 --- a/src-ui/src/app/components/common/share-links-dialog/share-links-dialog.component.spec.ts +++ b/src-ui/src/app/components/common/share-links-dialog/share-links-dialog.component.spec.ts @@ -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() diff --git a/src-ui/src/app/components/common/suggestions-dropdown/suggestions-dropdown.component.spec.ts b/src-ui/src/app/components/common/suggestions-dropdown/suggestions-dropdown.component.spec.ts index 863393ace..ffb63b420 100644 --- a/src-ui/src/app/components/common/suggestions-dropdown/suggestions-dropdown.component.spec.ts +++ b/src-ui/src/app/components/common/suggestions-dropdown/suggestions-dropdown.component.spec.ts @@ -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() }) diff --git a/src-ui/src/app/components/manage/mail/processed-mail-dialog/processed-mail-dialog.component.spec.ts b/src-ui/src/app/components/manage/mail/processed-mail-dialog/processed-mail-dialog.component.spec.ts index c34c97ef2..1344c5ba1 100644 --- a/src-ui/src/app/components/manage/mail/processed-mail-dialog/processed-mail-dialog.component.spec.ts +++ b/src-ui/src/app/components/manage/mail/processed-mail-dialog/processed-mail-dialog.component.spec.ts @@ -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', () => {