diff --git a/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor.component.spec.ts b/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor.component.spec.ts index 10c21d0d2..4a9025204 100644 --- a/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor.component.spec.ts +++ b/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor.component.spec.ts @@ -397,7 +397,7 @@ describe('OcrTemplateEditorComponent', () => { expect(customZone.name).toBe('New name') }) - it('tracks unsaved changes against the last loaded or saved state', () => { + it('tracks unsaved changes against the initial state', () => { fixture.detectChanges() expect(component.isDirty).toBe(false) @@ -407,8 +407,7 @@ describe('OcrTemplateEditorComponent', () => { component.template.name = 'Invoices' expect(component.isDirty).toBe(true) - templates.create.mockReturnValue(of({ ...component.template, id: 3 })) - component.save() + component.template.name = '' expect(component.isDirty).toBe(false) component.previewDocId = 5 @@ -431,10 +430,12 @@ describe('OcrTemplateEditorComponent', () => { component.onOverlayPointerUp(pointer(700, 700)) expect(component.template.zones).toHaveLength(0) - pending.next({ ...component.template, id: 3 }) + const saved = { ...component.template, id: 3 } + const succeeded = jest.spyOn(component.succeeded, 'emit') + pending.next(saved) pending.complete() - expect(component.saving).toBe(false) - expect(activeModal.close).toHaveBeenCalledWith(component.template) + expect(succeeded).toHaveBeenCalledWith(saved) + expect(activeModal.close).toHaveBeenCalledWith(saved) }) it('stops an active move and unlocks editing without losing changes after a failed save', () => { diff --git a/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor.component.ts b/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor.component.ts index 95d24e18a..a1f62c0ca 100644 --- a/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor.component.ts +++ b/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor.component.ts @@ -272,11 +272,10 @@ export class OcrTemplateEditorComponent implements OnInit, OnDestroy { : null } - /** Snapshot of the editor state as last loaded or saved. */ - private savedState = '' + private initialState = '' get isDirty(): boolean { - return this.editorState() !== this.savedState + return this.editorState() !== this.initialState } private editorState(): string { @@ -290,10 +289,6 @@ export class OcrTemplateEditorComponent implements OnInit, OnDestroy { }) } - private markSaved() { - this.savedState = this.editorState() - } - get dialogTitle(): string { return this.isNew ? $localize`New OCR Template` @@ -337,7 +332,7 @@ export class OcrTemplateEditorComponent implements OnInit, OnDestroy { this.loadPreview() } } - this.markSaved() + this.initialState = this.editorState() } searchDocuments = (text$: Observable): Observable => @@ -883,14 +878,7 @@ export class OcrTemplateEditorComponent implements OnInit, OnDestroy { obs.pipe(takeUntil(this.destroy$)).subscribe({ next: (saved) => { - const idx = this.selectedZoneIndex - this.template = saved - this.isNew = false - this.selectedZoneIndex = idx - this.saving = false - this.markSaved() this.toastService.showInfo($localize`OCR template saved.`) - this.changeDetector.markForCheck() this.succeeded.emit(saved) this.activeModal.close(saved) },