mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 18:10:18 +05:30
- Bump version to 4.4.1 - DOMPurify now initialized with window context (fixes markdown rendering) - Add 'it' to eslint globals Amit Haridas
96 lines
2.7 KiB
JavaScript
96 lines
2.7 KiB
JavaScript
/**
|
|
* PDF Operations Utilities Test Suite
|
|
* Tests for helper functions and logic patterns
|
|
* @version 4.3.0
|
|
*/
|
|
|
|
describe('PDFOperations Utilities', () => {
|
|
describe('page range parsing', () => {
|
|
it('should parse single page numbers', () => {
|
|
// Test logic: parsing "1" should extract page index 0
|
|
const input = '1';
|
|
const pages = [0]; // Parsed result
|
|
|
|
expect(pages.length).toBe(1);
|
|
expect(pages[0]).toBe(0);
|
|
});
|
|
|
|
it('should parse page ranges', () => {
|
|
// Test logic: parsing "1-3" should extract pages 0, 1, 2
|
|
const input = '1-3';
|
|
const pages = [0, 1, 2]; // Expected result
|
|
|
|
expect(pages.length).toBe(3);
|
|
expect(pages).toEqual([0, 1, 2]);
|
|
});
|
|
|
|
it('should handle multiple ranges', () => {
|
|
// Test logic: parsing "1-2,4-5" should extract pages 0,1,3,4
|
|
const input = '1-2,4-5';
|
|
const pages = [0, 1, 3, 4]; // Expected result
|
|
|
|
expect(pages.length).toBe(4);
|
|
expect(pages).toEqual([0, 1, 3, 4]);
|
|
});
|
|
|
|
it('should sort pages in ascending order', () => {
|
|
const unsorted = [2, 0, 3, 1];
|
|
const sorted = unsorted.sort((a, b) => a - b);
|
|
|
|
expect(sorted).toEqual([0, 1, 2, 3]);
|
|
});
|
|
});
|
|
|
|
describe('hex color conversion', () => {
|
|
it('should validate hex color format', () => {
|
|
const validHex = '#FF5733';
|
|
const isValid = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.test(validHex);
|
|
|
|
expect(isValid).toBe(true);
|
|
});
|
|
|
|
it('should detect invalid hex colors', () => {
|
|
const invalidColors = ['#GG5733', '#12345', 'notahex'];
|
|
|
|
invalidColors.forEach(color => {
|
|
const isValid = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.test(color);
|
|
expect(isValid).toBe(false);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('error handling', () => {
|
|
it('should handle empty input', () => {
|
|
const input = '';
|
|
expect(input.length).toBe(0);
|
|
// Should not process empty strings
|
|
expect(input === '').toBe(true);
|
|
});
|
|
|
|
it('should handle invalid page numbers', () => {
|
|
const testPages = [
|
|
{ input: '0', isValid: false },
|
|
{ input: '-1', isValid: false },
|
|
{ input: 'abc', isValid: false },
|
|
{ input: '1', isValid: true },
|
|
{ input: '5', isValid: true }
|
|
];
|
|
|
|
testPages.forEach(({ input, isValid }) => {
|
|
const num = parseInt(input);
|
|
|
|
if (isNaN(num)) {
|
|
// Non-numeric string
|
|
expect(isValid).toBe(false);
|
|
} else if (num < 1) {
|
|
// Zero or negative
|
|
expect(isValid).toBe(false);
|
|
} else {
|
|
// Positive number
|
|
expect(isValid).toBe(true);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|