mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-08-13 22:33:19 +00:00
Frontend can always just do versions[0]
This commit is contained in:
@@ -467,13 +467,6 @@ describe('DocumentDetailComponent', () => {
|
||||
const docWithVersions = {
|
||||
...doc,
|
||||
versions: [
|
||||
{
|
||||
id: doc.id,
|
||||
added: new Date('2024-01-01T00:00:00Z'),
|
||||
version_label: 'Original',
|
||||
checksum: 'aaaa',
|
||||
is_root: true,
|
||||
},
|
||||
{
|
||||
id: 10,
|
||||
added: new Date('2024-01-02T00:00:00Z'),
|
||||
@@ -481,6 +474,13 @@ describe('DocumentDetailComponent', () => {
|
||||
checksum: 'bbbb',
|
||||
is_root: false,
|
||||
},
|
||||
{
|
||||
id: doc.id,
|
||||
added: new Date('2024-01-01T00:00:00Z'),
|
||||
version_label: 'Original',
|
||||
checksum: 'aaaa',
|
||||
is_root: true,
|
||||
},
|
||||
],
|
||||
} as Document
|
||||
|
||||
@@ -1232,8 +1232,8 @@ describe('DocumentDetailComponent', () => {
|
||||
|
||||
metadataSpy.mockClear()
|
||||
component.document().versions = [
|
||||
{ id: doc.id, is_root: true },
|
||||
{ id: 10, is_root: false },
|
||||
{ id: doc.id, is_root: true },
|
||||
] as any
|
||||
jest.spyOn(documentService, 'getPreviewUrl').mockReturnValue('preview-root')
|
||||
jest.spyOn(documentService, 'getThumbUrl').mockReturnValue('thumb-root')
|
||||
@@ -1929,8 +1929,8 @@ describe('DocumentDetailComponent', () => {
|
||||
component.documentId.set(doc.id)
|
||||
component.document.set({ ...doc, versions: [] } as Document)
|
||||
const updatedVersions = [
|
||||
{ id: doc.id, is_root: true },
|
||||
{ id: 10, is_root: false },
|
||||
{ id: doc.id, is_root: true },
|
||||
] as any
|
||||
const openDoc = { ...doc, versions: [] } as Document
|
||||
jest.spyOn(openDocumentsService, 'getOpenDocument').mockReturnValue(openDoc)
|
||||
@@ -2046,8 +2046,8 @@ describe('DocumentDetailComponent', () => {
|
||||
it('should include version in download and print only for non-latest selected version', () => {
|
||||
initNormally()
|
||||
component.document().versions = [
|
||||
{ id: doc.id, is_root: true },
|
||||
{ id: 10, is_root: false },
|
||||
{ id: doc.id, is_root: true },
|
||||
] as any
|
||||
|
||||
const getDownloadUrlSpy = jest
|
||||
|
||||
@@ -889,13 +889,9 @@ export class DocumentDetailComponent
|
||||
|
||||
updateComponent(doc: Document) {
|
||||
this.document.set(doc)
|
||||
// Default selected version is the newest version
|
||||
// Default selected version is the newest version, which the API returns first
|
||||
const versions = doc.versions ?? []
|
||||
this.selectedVersionId.set(
|
||||
versions.length
|
||||
? Math.max(...versions.map((version) => version.id))
|
||||
: doc.id
|
||||
)
|
||||
this.selectedVersionId.set(versions.length ? versions[0].id : doc.id)
|
||||
this.previewLoaded.set(false)
|
||||
this.requiresPassword = false
|
||||
this.updateFormForCustomFields()
|
||||
@@ -1441,7 +1437,8 @@ export class DocumentDetailComponent
|
||||
if (!versions.length || !this.selectedVersionId()) {
|
||||
return null
|
||||
}
|
||||
const latestVersionId = Math.max(...versions.map((version) => version.id))
|
||||
// The API returns versions newest first
|
||||
const latestVersionId = versions[0].id
|
||||
return this.selectedVersionId() === latestVersionId
|
||||
? null
|
||||
: this.selectedVersionId()
|
||||
|
||||
+8
-5
@@ -234,9 +234,10 @@ describe('DocumentVersionDropdownComponent', () => {
|
||||
})
|
||||
|
||||
it('onVersionFileSelected should upload and update versions after websocket success', () => {
|
||||
// Newest first, as the API returns them
|
||||
const versions: DocumentVersionInfo[] = [
|
||||
{ id: 3, is_root: true, checksum: 'aaaa' },
|
||||
{ id: 20, is_root: false, checksum: 'cccc' },
|
||||
{ id: 3, is_root: true, checksum: 'aaaa' },
|
||||
]
|
||||
const file = new File(['test'], 'new-version.pdf', {
|
||||
type: 'application/pdf',
|
||||
@@ -348,9 +349,11 @@ describe('DocumentVersionDropdownComponent', () => {
|
||||
}
|
||||
modalService.open.mockReturnValue(modal as any)
|
||||
documentService.mergeDocumentsAsVersions.mockReturnValue(of({} as any))
|
||||
// Newest first, as the API returns them. The merged document has a lower id
|
||||
// than the root, which is the whole point of merging an existing document.
|
||||
const versions: DocumentVersionInfo[] = [
|
||||
{ id: 2, is_root: false, checksum: 'cccc' },
|
||||
{ id: 3, is_root: true, checksum: 'aaaa' },
|
||||
{ id: 20, is_root: false, checksum: 'cccc' },
|
||||
]
|
||||
documentService.getVersions.mockReturnValue(of({ id: 3, versions } as any))
|
||||
component.newVersionLabel = ' Imported '
|
||||
@@ -359,17 +362,17 @@ describe('DocumentVersionDropdownComponent', () => {
|
||||
|
||||
component.addExistingDocumentAsVersion()
|
||||
expect(modal.componentInstance.rootDocumentID).toEqual(3)
|
||||
confirmClicked.next(20)
|
||||
confirmClicked.next(2)
|
||||
|
||||
expect(documentService.mergeDocumentsAsVersions).toHaveBeenCalledWith(
|
||||
[3, 20],
|
||||
[3, 2],
|
||||
3,
|
||||
'Imported'
|
||||
)
|
||||
expect(documentService.updateVersionLabel).not.toHaveBeenCalled()
|
||||
expect(documentService.getVersions).toHaveBeenCalledWith(3)
|
||||
expect(versionsEmitSpy).toHaveBeenCalledWith(versions)
|
||||
expect(selectedEmitSpy).toHaveBeenCalledWith(20)
|
||||
expect(selectedEmitSpy).toHaveBeenCalledWith(2)
|
||||
expect(component.newVersionLabel).toEqual('')
|
||||
expect(modal.close).toHaveBeenCalled()
|
||||
expect(toastService.showInfo).toHaveBeenCalled()
|
||||
|
||||
+6
-8
@@ -258,11 +258,10 @@ export class DocumentVersionDropdownComponent implements OnChanges, OnDestroy {
|
||||
.subscribe({
|
||||
next: (doc) => {
|
||||
if (uploadDocumentId !== this.documentId) return
|
||||
if (doc?.versions) {
|
||||
if (doc?.versions?.length) {
|
||||
this.versionsUpdated.emit(doc.versions)
|
||||
this.versionSelected.emit(
|
||||
Math.max(...doc.versions.map((version) => version.id))
|
||||
)
|
||||
// The API returns versions newest first
|
||||
this.versionSelected.emit(doc.versions[0].id)
|
||||
this.clearVersionUploadStatus()
|
||||
}
|
||||
},
|
||||
@@ -308,11 +307,10 @@ export class DocumentVersionDropdownComponent implements OnChanges, OnDestroy {
|
||||
)
|
||||
.subscribe({
|
||||
next: (document) => {
|
||||
if (document?.versions) {
|
||||
if (document?.versions?.length) {
|
||||
this.versionsUpdated.emit(document.versions)
|
||||
this.versionSelected.emit(
|
||||
Math.max(...document.versions.map((version) => version.id))
|
||||
)
|
||||
// The API returns versions newest first
|
||||
this.versionSelected.emit(document.versions[0].id)
|
||||
}
|
||||
this.newVersionLabel = ''
|
||||
modal.close()
|
||||
|
||||
Reference in New Issue
Block a user