mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-03 02:11:07 +05:30
- WelcomeDialog: add quick start, feature showcase, keyboard shortcuts, recent files, version display - ExportDocxDialog/ExportHtmlDialog/ExportPdfDialog: add header/footer, paper size, margin controls - GitStatusPanel: full staging/unstaging, discard, commit workflow - CommandPalette: fuzzy command search with keyboard navigation - FindReplaceBar: find/replace with regex, case, whole-word options - New dialogs: BatchMediaConverterDialog, HeaderFooterDialog, PdfEditorDialog, UniversalConverterDialog - Tests: comprehensive coverage for all new/updated components
93 lines
2.6 KiB
JavaScript
93 lines
2.6 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 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 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 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);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|