Merge branch 'dev' into fix/issue-3945

This commit is contained in:
shamoon 2023-08-08 22:37:13 -07:00 committed by GitHub
commit f6dadd8c82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 8 deletions

View File

@ -668,7 +668,7 @@ describe('DocumentDetailComponent', () => {
const object = {
id: 22,
name: 'Correspondent22',
last_correspondence: new Date(),
last_correspondence: new Date().toISOString(),
} as PaperlessCorrespondent
const qfSpy = jest.spyOn(documentListViewService, 'quickFilter')
component.filterDocuments([object])

View File

@ -31,8 +31,12 @@ describe('CorrespondentListComponent', () => {
ReactiveFormsModule,
],
}).compileComponents()
correspondentsService = TestBed.inject(CorrespondentService)
})
// Tests are included in management-list.compontent.spec.ts
it('should use correct delete message', () => {
jest.spyOn(correspondentsService, 'listFiltered').mockReturnValue(
of({
count: 3,
@ -56,15 +60,30 @@ describe('CorrespondentListComponent', () => {
fixture = TestBed.createComponent(CorrespondentListComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
// Tests are included in management-list.compontent.spec.ts
it('should use correct delete message', () => {
expect(
component.getDeleteMessage({ id: 1, name: 'Correspondent1' })
).toEqual(
'Do you really want to delete the correspondent "Correspondent1"?'
)
})
it('should support very old date strings', () => {
jest.spyOn(correspondentsService, 'listFiltered').mockReturnValue(
of({
count: 1,
all: [1],
results: [
{
id: 1,
name: 'Correspondent1',
last_correspondence: '1832-12-31T15:32:54-07:52:58',
},
],
})
)
fixture = TestBed.createComponent(CorrespondentListComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
})

View File

@ -44,7 +44,19 @@ export class CorrespondentListComponent extends ManagementListComponent<Paperles
key: 'last_correspondence',
name: $localize`Last used`,
valueFn: (c: PaperlessCorrespondent) => {
return this.datePipe.transform(c.last_correspondence)
if (c.last_correspondence) {
let date = new Date(c.last_correspondence)
if (date.toString() == 'Invalid Date') {
// very old date strings are unable to be parsed
date = new Date(
c.last_correspondence
?.toString()
.replace(/-(\d\d):\d\d:\d\d/gm, `-$1:00`)
)
}
return this.datePipe.transform(date)
}
return ''
},
},
]

View File

@ -1,5 +1,5 @@
import { MatchingModel } from './matching-model'
export interface PaperlessCorrespondent extends MatchingModel {
last_correspondence?: Date
last_correspondence?: string // Date
}