mirror of
https://github.com/zadam/trilium.git
synced 2025-12-05 06:54:23 +01:00
feat(unit): ocr tests almost pass...
This commit is contained in:
parent
d20b3d854f
commit
80a9182f05
@ -689,6 +689,13 @@ describe('OCRService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should process image notes and attachments in sequence', async () => {
|
it('should process image notes and attachments in sequence', async () => {
|
||||||
|
// Clear all mocks at the start of this test to ensure clean state
|
||||||
|
vi.clearAllMocks();
|
||||||
|
|
||||||
|
// Reinitialize OCR service after clearing mocks
|
||||||
|
await ocrService.initialize();
|
||||||
|
(ocrService as any).worker = mockWorker;
|
||||||
|
|
||||||
// Mock data for batch processing
|
// Mock data for batch processing
|
||||||
const imageNotes = [
|
const imageNotes = [
|
||||||
{ noteId: 'note1', mime: 'image/jpeg' },
|
{ noteId: 'note1', mime: 'image/jpeg' },
|
||||||
@ -712,12 +719,18 @@ describe('OCRService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Mock notes and attachments
|
// Mock notes and attachments
|
||||||
const mockNote = {
|
const mockNote1 = {
|
||||||
noteId: 'note1',
|
noteId: 'note1',
|
||||||
type: 'image',
|
type: 'image',
|
||||||
mime: 'image/jpeg',
|
mime: 'image/jpeg',
|
||||||
getContent: vi.fn().mockReturnValue(Buffer.from('fake-image-data'))
|
getContent: vi.fn().mockReturnValue(Buffer.from('fake-image-data'))
|
||||||
};
|
};
|
||||||
|
const mockNote2 = {
|
||||||
|
noteId: 'note2',
|
||||||
|
type: 'image',
|
||||||
|
mime: 'image/png',
|
||||||
|
getContent: vi.fn().mockReturnValue(Buffer.from('fake-image-data'))
|
||||||
|
};
|
||||||
const mockAttachment = {
|
const mockAttachment = {
|
||||||
attachmentId: 'attach1',
|
attachmentId: 'attach1',
|
||||||
role: 'image',
|
role: 'image',
|
||||||
@ -725,7 +738,11 @@ describe('OCRService', () => {
|
|||||||
getContent: vi.fn().mockReturnValue(Buffer.from('fake-image-data'))
|
getContent: vi.fn().mockReturnValue(Buffer.from('fake-image-data'))
|
||||||
};
|
};
|
||||||
|
|
||||||
mockBecca.getNote.mockReturnValue(mockNote);
|
mockBecca.getNote.mockImplementation((noteId) => {
|
||||||
|
if (noteId === 'note1') return mockNote1;
|
||||||
|
if (noteId === 'note2') return mockNote2;
|
||||||
|
return null;
|
||||||
|
});
|
||||||
mockBecca.getAttachment.mockReturnValue(mockAttachment);
|
mockBecca.getAttachment.mockReturnValue(mockAttachment);
|
||||||
mockSql.getRow.mockReturnValue(null); // No existing OCR results
|
mockSql.getRow.mockReturnValue(null); // No existing OCR results
|
||||||
|
|
||||||
@ -733,7 +750,8 @@ describe('OCRService', () => {
|
|||||||
await ocrService.startBatchProcessing();
|
await ocrService.startBatchProcessing();
|
||||||
|
|
||||||
// Wait for background processing to complete
|
// Wait for background processing to complete
|
||||||
await new Promise(resolve => setTimeout(resolve, 100));
|
// Need to wait longer since there's a 500ms delay between each item in batch processing
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||||
|
|
||||||
// Verify notes and attachments were processed
|
// Verify notes and attachments were processed
|
||||||
expect(mockBecca.getNote).toHaveBeenCalledWith('note1');
|
expect(mockBecca.getNote).toHaveBeenCalledWith('note1');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user