diff --git a/src-ui/src/app/components/manage/correspondent-list/correspondent-list.component.ts b/src-ui/src/app/components/manage/correspondent-list/correspondent-list.component.ts index 0131ac992..957371e08 100644 --- a/src-ui/src/app/components/manage/correspondent-list/correspondent-list.component.ts +++ b/src-ui/src/app/components/manage/correspondent-list/correspondent-list.component.ts @@ -1,6 +1,7 @@ import { NgClass, NgTemplateOutlet, TitleCasePipe } from '@angular/common' import { Component, inject } from '@angular/core' import { FormsModule, ReactiveFormsModule } from '@angular/forms' +import { RouterModule } from '@angular/router' import { NgbDropdownModule, NgbPaginationModule, @@ -29,6 +30,7 @@ import { ManagementListComponent } from '../management-list/management-list.comp TitleCasePipe, FormsModule, ReactiveFormsModule, + RouterModule, NgClass, NgTemplateOutlet, NgbDropdownModule, diff --git a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.html b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.html index 185e9da35..0a6d80658 100644 --- a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.html +++ b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.html @@ -42,7 +42,13 @@ @if (field.document_count > 0) { - + Filter Documents ({{ field.document_count }}) } @@ -57,9 +63,13 @@ @if (field.document_count > 0) {
} diff --git a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.spec.ts b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.spec.ts index e94470d64..b86d476f3 100644 --- a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.spec.ts +++ b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.spec.ts @@ -4,6 +4,7 @@ import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http' import { provideHttpClientTesting } from '@angular/common/http/testing' import { FormsModule, ReactiveFormsModule } from '@angular/forms' import { By } from '@angular/platform-browser' +import { RouterTestingModule } from '@angular/router/testing' import { NgbModal, NgbModalModule, @@ -61,6 +62,7 @@ describe('CustomFieldsComponent', () => { NgbModalModule, NgbPopoverModule, NgxBootstrapIconsModule.pick(allIcons), + RouterTestingModule, CustomFieldsComponent, IfPermissionsDirective, PageHeaderComponent, @@ -108,7 +110,9 @@ describe('CustomFieldsComponent', () => { const toastInfoSpy = jest.spyOn(toastService, 'showInfo') const reloadSpy = jest.spyOn(component, 'reload') - const createButton = fixture.debugElement.queryAll(By.css('button'))[1] + const createButton = fixture.debugElement + .queryAll(By.css('button')) + .find((btn) => btn.nativeElement.textContent.trim().includes('Add Field')) createButton.triggerEventHandler('click') expect(modal).not.toBeUndefined() @@ -133,7 +137,11 @@ describe('CustomFieldsComponent', () => { const toastInfoSpy = jest.spyOn(toastService, 'showInfo') const reloadSpy = jest.spyOn(component, 'reload') - const editButton = fixture.debugElement.queryAll(By.css('button'))[2] + const editButton = fixture.debugElement + .queryAll(By.css('button')) + .find((btn) => + btn.nativeElement.textContent.trim().includes(fields[0].name) + ) editButton.triggerEventHandler('click') expect(modal).not.toBeUndefined() @@ -158,7 +166,9 @@ describe('CustomFieldsComponent', () => { const deleteSpy = jest.spyOn(customFieldsService, 'delete') const reloadSpy = jest.spyOn(component, 'reload') - const deleteButton = fixture.debugElement.queryAll(By.css('button'))[5] + const deleteButton = fixture.debugElement + .queryAll(By.css('button')) + .find((btn) => btn.nativeElement.textContent.trim().includes('Delete')) deleteButton.triggerEventHandler('click') expect(modal).not.toBeUndefined() @@ -176,10 +186,10 @@ describe('CustomFieldsComponent', () => { expect(reloadSpy).toHaveBeenCalled() }) - it('should support filter documents', () => { - const filterSpy = jest.spyOn(listViewService, 'quickFilter') - component.filterDocuments(fields[0]) - expect(filterSpy).toHaveBeenCalledWith([ + it('should provide document filter url', () => { + const urlSpy = jest.spyOn(listViewService, 'getQuickFilterUrl') + component.getDocumentFilterUrl(fields[0]) + expect(urlSpy).toHaveBeenCalledWith([ { rule_type: FILTER_CUSTOM_FIELDS_QUERY, value: JSON.stringify([ diff --git a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.ts b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.ts index 9e7ecf78a..8ecd713ef 100644 --- a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.ts +++ b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit, inject } from '@angular/core' +import { RouterModule } from '@angular/router' import { NgbDropdownModule, NgbModal, @@ -36,6 +37,7 @@ import { LoadingComponentWithPermissions } from '../../loading-component/loading NgbDropdownModule, NgbPaginationModule, NgxBootstrapIconsModule, + RouterModule, ], }) export class CustomFieldsComponent @@ -130,8 +132,8 @@ export class CustomFieldsComponent return DATA_TYPE_LABELS.find((l) => l.id === field.data_type).name } - filterDocuments(field: CustomField) { - this.documentListViewService.quickFilter([ + getDocumentFilterUrl(field: CustomField) { + return this.documentListViewService.getQuickFilterUrl([ { rule_type: FILTER_CUSTOM_FIELDS_QUERY, value: JSON.stringify([ diff --git a/src-ui/src/app/components/manage/document-type-list/document-type-list.component.ts b/src-ui/src/app/components/manage/document-type-list/document-type-list.component.ts index 21a4779e9..b561af2d1 100644 --- a/src-ui/src/app/components/manage/document-type-list/document-type-list.component.ts +++ b/src-ui/src/app/components/manage/document-type-list/document-type-list.component.ts @@ -1,6 +1,7 @@ import { NgClass, NgTemplateOutlet, TitleCasePipe } from '@angular/common' import { Component, inject } from '@angular/core' import { FormsModule, ReactiveFormsModule } from '@angular/forms' +import { RouterModule } from '@angular/router' import { NgbDropdownModule, NgbPaginationModule, @@ -27,6 +28,7 @@ import { ManagementListComponent } from '../management-list/management-list.comp IfPermissionsDirective, FormsModule, ReactiveFormsModule, + RouterModule, NgClass, NgTemplateOutlet, NgbDropdownModule, diff --git a/src-ui/src/app/components/manage/management-list/management-list.component.html b/src-ui/src/app/components/manage/management-list/management-list.component.html index 8fac6f44f..1cfb3aa0d 100644 --- a/src-ui/src/app/components/manage/management-list/management-list.component.html +++ b/src-ui/src/app/components/manage/management-list/management-list.component.html @@ -120,7 +120,14 @@ @if (getDocumentCount(object) > 0) { - + Filter Documents ({{ getDocumentCount(object) }}) } @@ -135,9 +142,15 @@ @if (getDocumentCount(object) > 0) { } diff --git a/src-ui/src/app/components/manage/management-list/management-list.component.spec.ts b/src-ui/src/app/components/manage/management-list/management-list.component.spec.ts index 813c81148..a9f7a0626 100644 --- a/src-ui/src/app/components/manage/management-list/management-list.component.spec.ts +++ b/src-ui/src/app/components/manage/management-list/management-list.component.spec.ts @@ -13,6 +13,7 @@ import { } from '@angular/core/testing' import { FormsModule, ReactiveFormsModule } from '@angular/forms' import { By } from '@angular/platform-browser' +import { RouterLinkWithHref } from '@angular/router' import { RouterTestingModule } from '@angular/router/testing' import { NgbModal, @@ -230,12 +231,15 @@ describe('ManagementListComponent', () => { }) it('should support quick filter for objects', () => { - const qfSpy = jest.spyOn(documentListViewService, 'quickFilter') - const filterButton = fixture.debugElement.queryAll(By.css('button'))[9] - filterButton.triggerEventHandler('click') - expect(qfSpy).toHaveBeenCalledWith([ + const expectedUrl = documentListViewService.getQuickFilterUrl([ { rule_type: FILTER_HAS_TAGS_ALL, value: tags[0].id.toString() }, - ]) // subclasses set the filter rule type + ]) + const filterLink = fixture.debugElement.query( + By.css('a.btn-outline-secondary') + ) + expect(filterLink).toBeTruthy() + const routerLink = filterLink.injector.get(RouterLinkWithHref) + expect(routerLink.urlTree).toEqual(expectedUrl) }) it('should reload on sort', () => { diff --git a/src-ui/src/app/components/manage/management-list/management-list.component.ts b/src-ui/src/app/components/manage/management-list/management-list.component.ts index b1af1f1d1..e8e7a3bb3 100644 --- a/src-ui/src/app/components/manage/management-list/management-list.component.ts +++ b/src-ui/src/app/components/manage/management-list/management-list.component.ts @@ -230,8 +230,8 @@ export abstract class ManagementListComponent