SOme test fixes

This commit is contained in:
shamoon
2026-07-08 08:18:21 -07:00
parent 825c91f584
commit c7b391f905
4 changed files with 39 additions and 27 deletions
@@ -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', () => {
@@ -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: '<span>bananas</span>',
component.document = {
...component.document,
__search_hit__: {
score: 0.9,
rank: 1,
note_highlights: '<span>bananas</span>',
},
}
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()
@@ -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()
@@ -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))