diff --git a/src-ui/src/app/components/common/custom-fields-query-dropdown/custom-fields-query-dropdown.component.spec.ts b/src-ui/src/app/components/common/custom-fields-query-dropdown/custom-fields-query-dropdown.component.spec.ts index 69f89f74e..37f56aa54 100644 --- a/src-ui/src/app/components/common/custom-fields-query-dropdown/custom-fields-query-dropdown.component.spec.ts +++ b/src-ui/src/app/components/common/custom-fields-query-dropdown/custom-fields-query-dropdown.component.spec.ts @@ -210,13 +210,12 @@ describe('CustomFieldsQueryDropdownComponent', () => { expect(component.name).toBe('test_title') }) - it('should add a default atom on open and focus the select field', fakeAsync(() => { + it('should add a default atom on open', fakeAsync(() => { expect(component.selectionModel.queries.length).toBe(0) component.onOpenChange(true) fixture.detectChanges() tick() expect(component.selectionModel.queries.length).toBe(1) - expect(window.document.activeElement.tagName).toBe('INPUT') })) describe('CustomFieldQueriesModel', () => { diff --git a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.spec.ts b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.spec.ts index e4e2bca74..38858b092 100644 --- a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.spec.ts +++ b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.spec.ts @@ -67,15 +67,14 @@ describe('DocumentCardLargeComponent', () => { fixture = TestBed.createComponent(DocumentCardLargeComponent) component = fixture.componentInstance - component.document = doc + component.document = { ...doc, tags: [...doc.tags], notes: [...doc.notes] } fixture.detectChanges() jest.useFakeTimers() }) it('should show the card', () => { - expect(component.show).toBeFalsy() + expect(component.show).toBeTruthy() component.ngAfterViewInit() - jest.advanceTimersByTime(100) expect(component.show).toBeTruthy() }) @@ -91,10 +90,13 @@ describe('DocumentCardLargeComponent', () => { it('should display search hits with colored score', () => { // high - component.document.__search_hit__ = { - score: 0.9, - rank: 1, - highlights: 'cheesecake', + component.document = { + ...component.document, + __search_hit__: { + score: 0.9, + rank: 1, + highlights: 'cheesecake', + }, } fixture.detectChanges() let search_hit = fixture.debugElement.query(By.css('.search-score')) @@ -102,14 +104,20 @@ describe('DocumentCardLargeComponent', () => { expect(component.searchScoreClass).toEqual('success') // medium - component.document.__search_hit__.score = 0.6 + component.document = { + ...component.document, + __search_hit__: { ...component.document.__search_hit__, score: 0.6 }, + } fixture.detectChanges() search_hit = fixture.debugElement.query(By.css('.search-score')) expect(search_hit).not.toBeUndefined() expect(component.searchScoreClass).toEqual('warning') // low - component.document.__search_hit__.score = 0.1 + component.document = { + ...component.document, + __search_hit__: { ...component.document.__search_hit__, score: 0.1 }, + } fixture.detectChanges() search_hit = fixture.debugElement.query(By.css('.search-score')) expect(search_hit).not.toBeUndefined() @@ -117,10 +125,13 @@ describe('DocumentCardLargeComponent', () => { }) it('should display note highlights', () => { - component.document.__search_hit__ = { - score: 0.9, - rank: 1, - note_highlights: 'bananas', + component.document = { + ...component.document, + __search_hit__: { + score: 0.9, + rank: 1, + note_highlights: 'bananas', + }, } fixture.detectChanges() expect(fixture.nativeElement.textContent).toContain('bananas') @@ -128,11 +139,14 @@ describe('DocumentCardLargeComponent', () => { }) it('should fall back to document content when a search hit has no highlights', () => { - component.document.__search_hit__ = { - score: 0.9, - rank: 1, - highlights: '', - note_highlights: null, + component.document = { + ...component.document, + __search_hit__: { + score: 0.9, + rank: 1, + highlights: '', + note_highlights: null, + }, } fixture.detectChanges() diff --git a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.spec.ts b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.spec.ts index 982b3980b..30ce1a2a1 100644 --- a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.spec.ts +++ b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.spec.ts @@ -52,9 +52,8 @@ describe('DocumentCardSmallComponent', () => { }) it('should show the card', () => { - expect(component.show).toBeFalsy() + expect(component.show).toBeTruthy() component.ngAfterViewInit() - jest.advanceTimersByTime(100) expect(component.show).toBeTruthy() }) @@ -67,7 +66,7 @@ describe('DocumentCardSmallComponent', () => { expect( fixture.debugElement.queryAll(By.directive(TagComponent)) ).toHaveLength(5) - component.document.tags = [1, 2] + component.document = { ...component.document, tags: [1, 2] } fixture.detectChanges() expect( fixture.debugElement.queryAll(By.directive(TagComponent)) @@ -75,7 +74,7 @@ describe('DocumentCardSmallComponent', () => { }) it('should increase limit tags to 6 if no notes', () => { - component.document.notes = [] + component.document = { ...component.document, notes: [] } fixture.detectChanges() expect( fixture.debugElement.queryAll(By.directive(TagComponent)) @@ -85,7 +84,7 @@ describe('DocumentCardSmallComponent', () => { it('should clear hidden tag counter when tag count falls below the limit', () => { expect(component.moreTags).toEqual(3) - component.document.tags = [1, 2, 3, 4, 5, 6] + component.document = { ...component.document, tags: [1, 2, 3, 4, 5, 6] } fixture.detectChanges() expect(component.moreTags).toBeNull() diff --git a/src-ui/src/app/components/document-list/document-list.component.spec.ts b/src-ui/src/app/components/document-list/document-list.component.spec.ts index 9ea7f27de..0921ea38b 100644 --- a/src-ui/src/app/components/document-list/document-list.component.spec.ts +++ b/src-ui/src/app/components/document-list/document-list.component.spec.ts @@ -777,7 +777,7 @@ describe('DocumentListComponent', () => { }) it('should hide columns if no perms or notes disabled', () => { - jest.spyOn(permissionService, 'currentUserCan').mockReturnValue(true) + permissionService.initialize([], { is_superuser: true } as any) jest.spyOn(documentListService, 'documents', 'get').mockReturnValue(docs) expect(documentListService.sortField).toEqual('created') @@ -798,7 +798,7 @@ describe('DocumentListComponent', () => { ).toHaveLength(9) // insufficient perms - jest.spyOn(permissionService, 'currentUserCan').mockReturnValue(false) + permissionService.initialize([], { is_superuser: false } as any) fixture.detectChanges() expect( fixture.debugElement.queryAll(By.directive(SortableDirective))