|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 Certinia Inc. All rights reserved. |
| 3 | + */ |
| 4 | + |
| 5 | +import { createMockTextDocument } from '../../__tests__/mocks/vscode.js'; |
| 6 | +import { isApexLogContent } from '../ApexLogLanguageDetector.js'; |
| 7 | + |
| 8 | +describe('isApexLogContent', () => { |
| 9 | + it('should detect standard log with settings header on line 1', () => { |
| 10 | + const doc = createMockTextDocument({ |
| 11 | + lines: [ |
| 12 | + '64.0 APEX_CODE,FINE;APEX_PROFILING,NONE;CALLOUT,NONE;DB,INFO;NBA,NONE;SYSTEM,NONE;VALIDATION,NONE;VISUALFORCE,NONE;WAVE,NONE;WORKFLOW,NONE', |
| 13 | + '09:45:31.888 (1000)|EXECUTION_STARTED', |
| 14 | + ], |
| 15 | + }); |
| 16 | + |
| 17 | + expect(isApexLogContent(doc)).toBe(true); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should detect log with preamble text before settings header', () => { |
| 21 | + const doc = createMockTextDocument({ |
| 22 | + lines: [ |
| 23 | + 'Some preamble text from browser UI', |
| 24 | + 'Another line of preamble', |
| 25 | + '64.0 APEX_CODE,FINE;APEX_PROFILING,NONE;CALLOUT,NONE;DB,INFO', |
| 26 | + '09:45:31.888 (1000)|EXECUTION_STARTED', |
| 27 | + ], |
| 28 | + }); |
| 29 | + |
| 30 | + expect(isApexLogContent(doc)).toBe(true); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should detect log without settings header but with EXECUTION_STARTED', () => { |
| 34 | + const doc = createMockTextDocument({ |
| 35 | + lines: [ |
| 36 | + 'Some preamble text', |
| 37 | + '09:45:31.888 (1000)|EXECUTION_STARTED', |
| 38 | + '09:45:31.889 (2000)|USER_INFO|[EXTERNAL]|user@example.com', |
| 39 | + ], |
| 40 | + }); |
| 41 | + |
| 42 | + expect(isApexLogContent(doc)).toBe(true); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should detect log without settings header but with USER_INFO', () => { |
| 46 | + const doc = createMockTextDocument({ |
| 47 | + lines: ['Some preamble text', '09:45:31.889 (2000)|USER_INFO|[EXTERNAL]|user@example.com'], |
| 48 | + }); |
| 49 | + |
| 50 | + expect(isApexLogContent(doc)).toBe(true); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should detect real-world log starting with USER_INFO and no settings header', () => { |
| 54 | + const doc = createMockTextDocument({ |
| 55 | + lines: [ |
| 56 | + '17:23:32.3 (3925848)|USER_INFO|[EXTERNAL]|0054R00000B6Q3p|luke.cotter@example.com|(GMT+00:00) Greenwich Mean Time (Europe/London)|GMT+00:00', |
| 57 | + '17:23:32.3 (4conversionId)|EXECUTION_STARTED', |
| 58 | + ], |
| 59 | + }); |
| 60 | + |
| 61 | + expect(isApexLogContent(doc)).toBe(true); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should detect log with settings header missing API version', () => { |
| 65 | + const doc = createMockTextDocument({ |
| 66 | + lines: [ |
| 67 | + 'APEX_CODE,FINE;APEX_PROFILING,INFO;CALLOUT,INFO;DB,FINEST;NBA,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WAVE,INFO;WORKFLOW,FINE', |
| 68 | + '17:23:32.3 (3925848)|USER_INFO|[EXTERNAL]|0054R00000B6Q3p|luke.cotter@example.com|(GMT+00:00) Greenwich Mean Time (Europe/London)|GMT+00:00', |
| 69 | + '17:23:32.3 (4000)|EXECUTION_STARTED', |
| 70 | + ], |
| 71 | + }); |
| 72 | + |
| 73 | + expect(isApexLogContent(doc)).toBe(true); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should not detect non-apex log file', () => { |
| 77 | + const doc = createMockTextDocument({ |
| 78 | + lines: [ |
| 79 | + '[2024-01-15 09:45:31] INFO: Application started', |
| 80 | + '[2024-01-15 09:45:32] DEBUG: Loading configuration', |
| 81 | + '[2024-01-15 09:45:33] ERROR: Connection failed', |
| 82 | + ], |
| 83 | + }); |
| 84 | + |
| 85 | + expect(isApexLogContent(doc)).toBe(false); |
| 86 | + }); |
| 87 | + |
| 88 | + it('should not detect empty document', () => { |
| 89 | + const doc = createMockTextDocument({ |
| 90 | + lines: [], |
| 91 | + }); |
| 92 | + |
| 93 | + expect(isApexLogContent(doc)).toBe(false); |
| 94 | + }); |
| 95 | +}); |
0 commit comments