From a51e6a71f4c8c8eb70ad222ca7a51d73335603a3 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 20 Oct 2026 08:20:44 -0700 Subject: [PATCH] Fix reload after running zone ocr --- .../document-detail.component.spec.ts | 40 +++++++++++++++++++ .../document-detail.component.ts | 5 +-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts b/src-ui/src/app/components/document-detail/document-detail.component.spec.ts index c89c9b89f..fbc7bc73b 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.spec.ts @@ -1900,6 +1900,46 @@ describe('DocumentDetailComponent', () => { expect(toastSpy).toHaveBeenCalledWith('Document reloaded.') }) + it('should run zone OCR, report results and force-reload the document', () => { + component.documentId.set(doc.id) + component.document.set(doc) + jest.spyOn(documentService, 'runZoneOcr').mockReturnValue( + of({ + results: [ + { zone: 'Total', value: '102.10' }, + { zone: 'Due', value: '' }, + ], + } as any) + ) + const loadSpy = jest + .spyOn(component as any, 'loadDocument') + .mockImplementation(() => {}) + const notifySpy = jest.spyOn(component.docChangeNotifier, 'next') + const toastSpy = jest.spyOn(toastService, 'showInfo') + + component.runZoneOcr() + + expect(toastSpy).toHaveBeenCalledWith( + 'Filled 1 of 2 fields. Failed to match zones: Due' + ) + expect(notifySpy).toHaveBeenCalledWith(doc.id) + expect(loadSpy).toHaveBeenCalledWith(doc.id, true) + }) + + it('should show an error when zone OCR fails', () => { + component.document.set(doc) + jest + .spyOn(documentService, 'runZoneOcr') + .mockReturnValue(throwError(() => new Error('nope'))) + const loadSpy = jest.spyOn(component as any, 'loadDocument') + const errorSpy = jest.spyOn(toastService, 'showError') + + component.runZoneOcr() + + expect(errorSpy).toHaveBeenCalledWith('Zone OCR failed', expect.any(Error)) + expect(loadSpy).not.toHaveBeenCalled() + }) + it('should change preview element by render type', () => { initNormally() component.document.update((document) => ({ diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts index 468469c18..94984c304 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.ts @@ -1577,9 +1577,8 @@ export class DocumentDetailComponent $localize`Zone OCR ran but no results extracted.` ) } - this.documentsService - .get(this.documentId()) - .subscribe((doc) => this.updateComponent(doc)) + this.docChangeNotifier.next(this.documentId()) + this.loadDocument(this.documentId(), true) }, error: (error) => { this.toastService.showError($localize`Zone OCR failed`, error)