mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-12 00:19:48 +00:00
Feature: customizable fields display for documents, saved views & dashboard widgets (#6439)
This commit is contained in:
@@ -11,7 +11,13 @@ import { RouterTestingModule } from '@angular/router/testing'
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'
|
||||
import { of, Subject } from 'rxjs'
|
||||
import { routes } from 'src/app/app-routing.module'
|
||||
import { FILTER_HAS_TAGS_ALL } from 'src/app/data/filter-rule-type'
|
||||
import {
|
||||
FILTER_CORRESPONDENT,
|
||||
FILTER_DOCUMENT_TYPE,
|
||||
FILTER_FULLTEXT_MORELIKE,
|
||||
FILTER_HAS_TAGS_ALL,
|
||||
FILTER_STORAGE_PATH,
|
||||
} from 'src/app/data/filter-rule-type'
|
||||
import { SavedView } from 'src/app/data/saved-view'
|
||||
import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive'
|
||||
import { PermissionsGuard } from 'src/app/guards/permissions.guard'
|
||||
@@ -31,6 +37,10 @@ import { SafeUrlPipe } from 'src/app/pipes/safeurl.pipe'
|
||||
import { DragDropModule } from '@angular/cdk/drag-drop'
|
||||
import { PreviewPopupComponent } from 'src/app/components/common/preview-popup/preview-popup.component'
|
||||
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
|
||||
import { CustomFieldsService } from 'src/app/services/rest/custom-fields.service'
|
||||
import { CustomFieldDataType } from 'src/app/data/custom-field'
|
||||
import { CustomFieldDisplayComponent } from 'src/app/components/common/custom-field-display/custom-field-display.component'
|
||||
import { DisplayMode, DisplayField } from 'src/app/data/document'
|
||||
|
||||
const savedView: SavedView = {
|
||||
id: 1,
|
||||
@@ -45,17 +55,53 @@ const savedView: SavedView = {
|
||||
value: '1,2',
|
||||
},
|
||||
],
|
||||
page_size: 20,
|
||||
display_mode: DisplayMode.TABLE,
|
||||
display_fields: [
|
||||
DisplayField.CREATED,
|
||||
DisplayField.TITLE,
|
||||
DisplayField.TAGS,
|
||||
DisplayField.CORRESPONDENT,
|
||||
DisplayField.DOCUMENT_TYPE,
|
||||
DisplayField.STORAGE_PATH,
|
||||
`${DisplayField.CUSTOM_FIELD}11` as any,
|
||||
`${DisplayField.CUSTOM_FIELD}15` as any,
|
||||
],
|
||||
}
|
||||
|
||||
const documentResults = [
|
||||
{
|
||||
id: 2,
|
||||
title: 'doc2',
|
||||
custom_fields: [
|
||||
{ id: 1, field: 11, created: new Date(), value: 'custom', document: 2 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
title: 'doc3',
|
||||
correspondent: 0,
|
||||
custom_fields: [],
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
title: 'doc4',
|
||||
custom_fields: [
|
||||
{ id: 32, field: 3, created: new Date(), value: 'EUR123', document: 4 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
title: 'doc5',
|
||||
custom_fields: [
|
||||
{
|
||||
id: 22,
|
||||
field: 15,
|
||||
created: new Date(),
|
||||
value: [123, 456, 789],
|
||||
document: 5,
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
@@ -77,6 +123,7 @@ describe('SavedViewWidgetComponent', () => {
|
||||
DocumentTitlePipe,
|
||||
SafeUrlPipe,
|
||||
PreviewPopupComponent,
|
||||
CustomFieldDisplayComponent,
|
||||
],
|
||||
providers: [
|
||||
PermissionsGuard,
|
||||
@@ -89,6 +136,33 @@ describe('SavedViewWidgetComponent', () => {
|
||||
},
|
||||
CustomDatePipe,
|
||||
DatePipe,
|
||||
{
|
||||
provide: CustomFieldsService,
|
||||
useValue: {
|
||||
listAll: () =>
|
||||
of({
|
||||
all: [3, 11, 15],
|
||||
count: 3,
|
||||
results: [
|
||||
{
|
||||
id: 3,
|
||||
name: 'Custom field 3',
|
||||
data_type: CustomFieldDataType.Monetary,
|
||||
},
|
||||
{
|
||||
id: 11,
|
||||
name: 'Custom Field 11',
|
||||
data_type: CustomFieldDataType.String,
|
||||
},
|
||||
{
|
||||
id: 15,
|
||||
name: 'Custom Field 15',
|
||||
data_type: CustomFieldDataType.DocumentLink,
|
||||
},
|
||||
],
|
||||
}),
|
||||
},
|
||||
},
|
||||
],
|
||||
imports: [
|
||||
HttpClientTestingModule,
|
||||
@@ -170,7 +244,7 @@ describe('SavedViewWidgetComponent', () => {
|
||||
component.ngOnInit()
|
||||
expect(listAllSpy).toHaveBeenCalledWith(
|
||||
1,
|
||||
10,
|
||||
20,
|
||||
savedView.sort_field,
|
||||
savedView.sort_reverse,
|
||||
savedView.filter_rules,
|
||||
@@ -204,11 +278,78 @@ describe('SavedViewWidgetComponent', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should navigate to document', () => {
|
||||
const routerSpy = jest.spyOn(router, 'navigate')
|
||||
component.openDocumentDetail(documentResults[0])
|
||||
expect(routerSpy).toHaveBeenCalledWith(['documents', documentResults[0].id])
|
||||
})
|
||||
|
||||
it('should navigate via quickfilter on click tag', () => {
|
||||
const qfSpy = jest.spyOn(documentListViewService, 'quickFilter')
|
||||
component.clickTag({ id: 11, name: 'Tag11' }, new MouseEvent('click'))
|
||||
component.clickTag(11, new MouseEvent('click'))
|
||||
expect(qfSpy).toHaveBeenCalledWith([
|
||||
{ rule_type: FILTER_HAS_TAGS_ALL, value: '11' },
|
||||
])
|
||||
component.clickTag(11) // coverage
|
||||
})
|
||||
|
||||
it('should navigate via quickfilter on click correspondent', () => {
|
||||
const qfSpy = jest.spyOn(documentListViewService, 'quickFilter')
|
||||
component.clickCorrespondent(11, new MouseEvent('click'))
|
||||
expect(qfSpy).toHaveBeenCalledWith([
|
||||
{ rule_type: FILTER_CORRESPONDENT, value: '11' },
|
||||
])
|
||||
component.clickCorrespondent(11) // coverage
|
||||
})
|
||||
|
||||
it('should navigate via quickfilter on click doc type', () => {
|
||||
const qfSpy = jest.spyOn(documentListViewService, 'quickFilter')
|
||||
component.clickDocType(11, new MouseEvent('click'))
|
||||
expect(qfSpy).toHaveBeenCalledWith([
|
||||
{ rule_type: FILTER_DOCUMENT_TYPE, value: '11' },
|
||||
])
|
||||
component.clickDocType(11) // coverage
|
||||
})
|
||||
|
||||
it('should navigate via quickfilter on click storage path', () => {
|
||||
const qfSpy = jest.spyOn(documentListViewService, 'quickFilter')
|
||||
component.clickStoragePath(11, new MouseEvent('click'))
|
||||
expect(qfSpy).toHaveBeenCalledWith([
|
||||
{ rule_type: FILTER_STORAGE_PATH, value: '11' },
|
||||
])
|
||||
component.clickStoragePath(11) // coverage
|
||||
})
|
||||
|
||||
it('should navigate via quickfilter on click more like', () => {
|
||||
const qfSpy = jest.spyOn(documentListViewService, 'quickFilter')
|
||||
component.clickMoreLike(11)
|
||||
expect(qfSpy).toHaveBeenCalledWith([
|
||||
{ rule_type: FILTER_FULLTEXT_MORELIKE, value: '11' },
|
||||
])
|
||||
})
|
||||
|
||||
it('should get correct column title', () => {
|
||||
expect(component.getColumnTitle(DisplayField.TITLE)).toEqual('Title')
|
||||
expect(component.getColumnTitle(DisplayField.CREATED)).toEqual('Created')
|
||||
expect(component.getColumnTitle(DisplayField.ADDED)).toEqual('Added')
|
||||
expect(component.getColumnTitle(DisplayField.TAGS)).toEqual('Tags')
|
||||
expect(component.getColumnTitle(DisplayField.CORRESPONDENT)).toEqual(
|
||||
'Correspondent'
|
||||
)
|
||||
expect(component.getColumnTitle(DisplayField.DOCUMENT_TYPE)).toEqual(
|
||||
'Document type'
|
||||
)
|
||||
expect(component.getColumnTitle(DisplayField.STORAGE_PATH)).toEqual(
|
||||
'Storage path'
|
||||
)
|
||||
})
|
||||
|
||||
it('should get correct column title for custom field', () => {
|
||||
expect(
|
||||
component.getColumnTitle((DisplayField.CUSTOM_FIELD + 11) as any)
|
||||
).toEqual('Custom Field 11')
|
||||
expect(
|
||||
component.getColumnTitle((DisplayField.CUSTOM_FIELD + 15) as any)
|
||||
).toEqual('Custom Field 15')
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user