parser-frontmatter-ts/tests/constants.test.ts

193 lines
7.1 KiB
TypeScript

import {
AUDIENCE_VALUES,
DOC_PURPOSE_VALUES,
PROFILE_VALUES,
DEFAULTS,
BALANCED_FIELDS,
PARSER_PROFILES
} from '../src';
describe('Constants', () => {
describe('AUDIENCE_VALUES', () => {
it('should contain all valid audience levels', () => {
expect(AUDIENCE_VALUES).toContain('all');
expect(AUDIENCE_VALUES).toContain('beginner');
expect(AUDIENCE_VALUES).toContain('intermediate');
expect(AUDIENCE_VALUES).toContain('expert');
expect(AUDIENCE_VALUES).toHaveLength(4);
});
});
describe('DOC_PURPOSE_VALUES', () => {
it('should contain all valid doc purposes', () => {
expect(DOC_PURPOSE_VALUES).toContain('reference');
expect(DOC_PURPOSE_VALUES).toContain('tutorial');
expect(DOC_PURPOSE_VALUES).toContain('troubleshooting');
expect(DOC_PURPOSE_VALUES).toContain('conceptual');
expect(DOC_PURPOSE_VALUES).toContain('guide');
expect(DOC_PURPOSE_VALUES).toContain('specification');
expect(DOC_PURPOSE_VALUES).toHaveLength(6);
});
});
describe('PROFILE_VALUES', () => {
it('should contain all valid profile types', () => {
const expectedProfiles = [
'scraped', 'research', 'technical', 'code', 'data', 'changelog',
'legal', 'test', 'schema', 'troubleshoot', 'meeting', 'faq', 'config'
];
expectedProfiles.forEach(profile => {
expect(PROFILE_VALUES).toContain(profile);
});
expect(PROFILE_VALUES).toHaveLength(13);
});
});
describe('DEFAULTS', () => {
it('should have correct default values', () => {
expect(DEFAULTS.profile).toBe('data');
expect(DEFAULTS.audience).toBe('all');
expect(DEFAULTS.extractionConfidence).toBe(1.0);
expect(DEFAULTS.contentQuality).toBe(1.5);
expect(DEFAULTS.complexity).toBe(3);
});
it('should have confidence in valid range', () => {
expect(DEFAULTS.extractionConfidence).toBeGreaterThanOrEqual(0);
expect(DEFAULTS.extractionConfidence).toBeLessThanOrEqual(1);
});
it('should have quality in valid range', () => {
expect(DEFAULTS.contentQuality).toBeGreaterThanOrEqual(0);
expect(DEFAULTS.contentQuality).toBeLessThanOrEqual(2);
});
});
describe('PARSER_PROFILES', () => {
it('should have profiles for all parsers', () => {
const expectedParsers = [
'fss-parse-pdf',
'fss-parse-word',
'fss-parse-excel',
'fss-parse-image',
'fss-parse-audio',
'fss-parse-video',
'fss-parse-email',
'fss-parse-presentation',
'fss-parse-data',
'fss-parse-diagram'
];
expectedParsers.forEach(parser => {
expect(PARSER_PROFILES[parser]).toBeDefined();
});
});
it('should use valid profile types', () => {
Object.values(PARSER_PROFILES).forEach(profile => {
expect(PROFILE_VALUES).toContain(profile);
});
});
it('should have appropriate profiles for parser types', () => {
expect(PARSER_PROFILES['fss-parse-pdf']).toBe('technical');
expect(PARSER_PROFILES['fss-parse-word']).toBe('technical');
expect(PARSER_PROFILES['fss-parse-excel']).toBe('data');
expect(PARSER_PROFILES['fss-parse-audio']).toBe('meeting');
expect(PARSER_PROFILES['fss-parse-video']).toBe('meeting');
expect(PARSER_PROFILES['fss-parse-email']).toBe('data');
expect(PARSER_PROFILES['fss-parse-diagram']).toBe('schema');
});
});
describe('BALANCED_FIELDS', () => {
it('should include universal document fields', () => {
expect(BALANCED_FIELDS).toContain('word_count');
expect(BALANCED_FIELDS).toContain('page_count');
expect(BALANCED_FIELDS).toContain('character_count');
expect(BALANCED_FIELDS).toContain('author');
expect(BALANCED_FIELDS).toContain('format');
});
it('should include PDF/Word structure fields', () => {
expect(BALANCED_FIELDS).toContain('has_tables');
expect(BALANCED_FIELDS).toContain('has_images');
expect(BALANCED_FIELDS).toContain('table_count');
expect(BALANCED_FIELDS).toContain('image_count');
expect(BALANCED_FIELDS).toContain('has_toc');
expect(BALANCED_FIELDS).toContain('has_forms');
});
it('should include Excel/Data fields', () => {
expect(BALANCED_FIELDS).toContain('sheet_count');
expect(BALANCED_FIELDS).toContain('row_count');
expect(BALANCED_FIELDS).toContain('column_count');
expect(BALANCED_FIELDS).toContain('record_count');
expect(BALANCED_FIELDS).toContain('format_detected');
});
it('should include image fields', () => {
expect(BALANCED_FIELDS).toContain('width');
expect(BALANCED_FIELDS).toContain('height');
expect(BALANCED_FIELDS).toContain('channels');
expect(BALANCED_FIELDS).toContain('has_alpha');
expect(BALANCED_FIELDS).toContain('ocr_confidence');
});
it('should include audio fields', () => {
expect(BALANCED_FIELDS).toContain('duration');
expect(BALANCED_FIELDS).toContain('bitrate');
expect(BALANCED_FIELDS).toContain('sample_rate');
expect(BALANCED_FIELDS).toContain('codec');
expect(BALANCED_FIELDS).toContain('has_transcript');
expect(BALANCED_FIELDS).toContain('speaker_count');
});
it('should include video fields', () => {
expect(BALANCED_FIELDS).toContain('fps');
expect(BALANCED_FIELDS).toContain('aspect_ratio');
expect(BALANCED_FIELDS).toContain('video_codec');
expect(BALANCED_FIELDS).toContain('audio_codec');
});
it('should include email fields', () => {
expect(BALANCED_FIELDS).toContain('from');
expect(BALANCED_FIELDS).toContain('to');
expect(BALANCED_FIELDS).toContain('cc');
expect(BALANCED_FIELDS).toContain('sender');
expect(BALANCED_FIELDS).toContain('recipients');
expect(BALANCED_FIELDS).toContain('message_id');
expect(BALANCED_FIELDS).toContain('has_attachments');
expect(BALANCED_FIELDS).toContain('attachment_count');
expect(BALANCED_FIELDS).toContain('importance');
});
it('should include presentation fields', () => {
expect(BALANCED_FIELDS).toContain('slide_count');
expect(BALANCED_FIELDS).toContain('total_slides');
expect(BALANCED_FIELDS).toContain('chart_count');
expect(BALANCED_FIELDS).toContain('has_speaker_notes');
});
it('should include diagram fields', () => {
expect(BALANCED_FIELDS).toContain('diagram_count');
expect(BALANCED_FIELDS).toContain('diagram_type');
expect(BALANCED_FIELDS).toContain('valid_diagrams');
expect(BALANCED_FIELDS).toContain('invalid_diagrams');
expect(BALANCED_FIELDS).toContain('node_count');
expect(BALANCED_FIELDS).toContain('edge_count');
});
it('should not contain duplicate fields', () => {
const uniqueFields = new Set(BALANCED_FIELDS);
expect(uniqueFields.size).toBe(BALANCED_FIELDS.length);
});
it('should have reasonable number of fields', () => {
// Should have enough fields to cover all parser types
expect(BALANCED_FIELDS.length).toBeGreaterThan(50);
// But not so many that balanced mode becomes complete mode
expect(BALANCED_FIELDS.length).toBeLessThan(100);
});
});
});