Move run_zone_ocr to the new bulk operations pathway

This commit is contained in:
shamoon committed 2026-11-17 13:43:13 -08:00
1 parent 3153b118bd
commit 855b161407
13 files changed
+193 -47

No files matched your search

@@ -1387,6 +1387,10 @@ describe('BulkEditorComponent', () => {
})
it('should support run zone ocr', () => {
const queued = jest
.spyOn(TestBed.inject(TaskNotificationService), 'showQueued')
.mockImplementation(() => {})
const reload = jest.spyOn(documentListViewService, 'reload')
let modal: NgbModalRef
modalService.activeInstances.subscribe((m) => (modal = m[0]))
jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true)
@@ -1406,10 +1410,17 @@ describe('BulkEditorComponent', () => {
let req = httpTestingController.expectOne(
`${environment.apiBaseUrl}documents/run_zone_ocr/`
)
req.flush(true)
req.flush({ result: 'OK', task_id: 'zone-ocr-1' })
expect(req.request.body).toEqual({
documents: [3, 4],
from_webui: true,
})
expect(queued).toHaveBeenLastCalledWith(
'zone-ocr-1',
"Bulk operation 'Run zone OCR' queued.",
{ content: "Bulk operation 'Run zone OCR' completed." }
)
expect(reload).not.toHaveBeenCalled()
component.runZoneOcrSelected()
modal.componentInstance.template = 3
@@ -1417,11 +1428,17 @@ describe('BulkEditorComponent', () => {
req = httpTestingController.expectOne(
`${environment.apiBaseUrl}documents/run_zone_ocr/`
)
req.flush(true)
req.flush({ result: 'OK', task_id: 'zone-ocr-2' })
expect(req.request.body).toEqual({
documents: [3, 4],
template: 3,
from_webui: true,
})
expect(queued).toHaveBeenLastCalledWith(
'zone-ocr-2',
"Bulk operation 'Run zone OCR' queued.",
{ content: "Bulk operation 'Run zone OCR' completed." }
)
httpTestingController.match(
`${environment.apiBaseUrl}ocr_templates/?page=1&page_size=100000`
) // template list
@@ -1042,6 +1042,7 @@ export class BulkEditorComponent
dialog.buttonsEnabled.set(false)
this.executeDocumentAction(
modal,
'run_zone_ocr',
this.documentService.runZoneOcrDocuments(
this.getSelectionQuery(),
dialog.template
@@ -323,6 +323,27 @@ describe(`DocumentService`, () => {
})
})
it.each([null, 3])('should queue zone OCR with template %s', (template) => {
const queued = jest.fn()
subscription = service
.runZoneOcrDocuments({ documents: [1, 2] }, template)
.subscribe(queued)
const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/run_zone_ocr/`
)
expect(req.request.method).toBe('POST')
expect(req.request.body).toEqual({
documents: [1, 2],
...(template ? { template } : {}),
from_webui: true,
})
req.flush({ result: 'OK', task_id: 'zone-ocr-task' })
expect(queued).toHaveBeenCalledWith({
result: 'OK',
task_id: 'zone-ocr-task',
})
})
it('should call appropriate api endpoint for rotate documents', () => {
const ids = [1, 2, 3]
subscription = service.rotateDocuments({ documents: ids }, 90).subscribe()
@@ -376,10 +376,14 @@ export class DocumentService extends AbstractPaperlessService<Document> {
selection: DocumentSelectionQuery,
templateId: number | null = null
) {
return this.http.post(this.getResourceUrl(null, 'run_zone_ocr'), {
...selection,
...(templateId ? { template: templateId } : {}),
})
return this.http.post<BulkOperationResponse>(
this.getResourceUrl(null, 'run_zone_ocr'),
{
...selection,
...(templateId ? { template: templateId } : {}),
from_webui: true,
}
)
}
runZoneOcr(
@@ -1,6 +1,13 @@
import { getDocumentOperationLabel } from './document-operation'
import {
documentOperationHasFollowUpTasks,
getDocumentOperationLabel,
} from './document-operation'
describe('Document Operation Utils', () => {
it('names zone OCR and treats task completion as finished extraction', () => {
expect(getDocumentOperationLabel('run_zone_ocr')).toBe('Run zone OCR')
expect(documentOperationHasFollowUpTasks('run_zone_ocr')).toBe(false)
})
it('should retrieve the document operation label correctly for an existing operation, null otherwise', () => {
const result = getDocumentOperationLabel('modify_custom_fields')
expect(result).toBe('Update custom fields')
@@ -10,6 +10,7 @@ const OPERATION_LABELS: Record<string, string> = {
delete: $localize`Move to trash`,
reprocess: $localize`Document reprocessing`,
run_workflow: $localize`Run workflow`,
run_zone_ocr: $localize`Run zone OCR`,
rotate: $localize`Rotate documents`,
merge: $localize`Merge documents`,
merge_as_versions: $localize`Merge as versions`,