fix(batch): resolve pandoc path handling and include-subfolders option

- Normalize pandoc command parsing with path.basename() to support bundled binary paths
- Use bundled pandoc binary in convertWithPandoc instead of relying on PATH
- Forward includeSubfolders checkbox state from renderer to main process
- Add pandoc availability check before batch conversion
- Re-enable Start button when batch conversion completes
- Clean up obsolete dist build artifact causing test snapshot warning
- Bump version to 4.4.4
This commit is contained in:
2026-06-30 12:56:33 +05:30
parent 02e307f758
commit d705cfc30b
86 changed files with 16876 additions and 13476 deletions
+234 -234
View File
@@ -9,272 +9,272 @@
const { ModalManager } = require('../src/utils/ModalManager');
function createModalElement(id = 'test-modal') {
const modal = document.createElement('div');
modal.id = id;
modal.className = 'modal hidden';
modal.setAttribute('role', 'dialog');
modal.setAttribute('aria-modal', 'true');
const modal = document.createElement('div');
modal.id = id;
modal.className = 'modal hidden';
modal.setAttribute('role', 'dialog');
modal.setAttribute('aria-modal', 'true');
const backdrop = document.createElement('div');
backdrop.className = 'modal-backdrop';
backdrop.setAttribute('data-close', '');
const backdrop = document.createElement('div');
backdrop.className = 'modal-backdrop';
backdrop.setAttribute('data-close', '');
const content = document.createElement('div');
content.className = 'modal-content';
const content = document.createElement('div');
content.className = 'modal-content';
const header = document.createElement('div');
header.className = 'modal-header';
const header = document.createElement('div');
header.className = 'modal-header';
const closeBtn = document.createElement('button');
closeBtn.className = 'modal-close';
closeBtn.setAttribute('aria-label', 'Close');
const closeBtn = document.createElement('button');
closeBtn.className = 'modal-close';
closeBtn.setAttribute('aria-label', 'Close');
const body = document.createElement('div');
body.className = 'modal-body';
const body = document.createElement('div');
body.className = 'modal-body';
const input = document.createElement('input');
input.type = 'text';
const input = document.createElement('input');
input.type = 'text';
body.appendChild(input);
header.appendChild(closeBtn);
content.appendChild(header);
content.appendChild(body);
modal.appendChild(backdrop);
modal.appendChild(content);
document.body.appendChild(modal);
body.appendChild(input);
header.appendChild(closeBtn);
content.appendChild(header);
content.appendChild(body);
modal.appendChild(backdrop);
modal.appendChild(content);
document.body.appendChild(modal);
return modal;
return modal;
}
describe('ModalManager', () => {
let modal;
let manager;
let modal;
let manager;
beforeEach(() => {
modal = createModalElement();
manager = new ModalManager(modal);
});
afterEach(() => {
manager.destroy();
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
document.body.style.overflow = '';
});
// =========================================================
// open()
// =========================================================
describe('open()', () => {
test('removes hidden class and adds open class', () => {
expect(modal.classList.contains('hidden')).toBe(true);
expect(modal.classList.contains('open')).toBe(false);
manager.open();
expect(modal.classList.contains('hidden')).toBe(false);
expect(modal.classList.contains('open')).toBe(true);
});
test('sets isOpen to true', () => {
expect(manager.isOpen()).toBe(false);
manager.open();
expect(manager.isOpen()).toBe(true);
});
test('prevents body scroll', () => {
manager.open();
expect(document.body.style.overflow).toBe('hidden');
});
test('does not open again if already open', () => {
manager.open();
manager.open(); // second call should be no-op
expect(manager.isOpen()).toBe(true);
});
test('calls onOpen callback', () => {
const onOpen = jest.fn();
manager.destroy();
manager = new ModalManager(modal, { onOpen });
manager.open();
expect(onOpen).toHaveBeenCalledTimes(1);
});
test('dispatches modal:open custom event', () => {
const handler = jest.fn();
modal.addEventListener('modal:open', handler);
manager.open();
expect(handler).toHaveBeenCalledTimes(1);
});
});
// =========================================================
// close()
// =========================================================
describe('close()', () => {
beforeEach(() => {
modal = createModalElement();
manager = new ModalManager(modal);
manager.open();
});
afterEach(() => {
manager.destroy();
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
document.body.style.overflow = '';
test('removes open class', () => {
expect(modal.classList.contains('open')).toBe(true);
manager.close();
expect(modal.classList.contains('open')).toBe(false);
});
// =========================================================
// open()
// =========================================================
describe('open()', () => {
test('removes hidden class and adds open class', () => {
expect(modal.classList.contains('hidden')).toBe(true);
expect(modal.classList.contains('open')).toBe(false);
manager.open();
expect(modal.classList.contains('hidden')).toBe(false);
expect(modal.classList.contains('open')).toBe(true);
});
test('sets isOpen to true', () => {
expect(manager.isOpen()).toBe(false);
manager.open();
expect(manager.isOpen()).toBe(true);
});
test('prevents body scroll', () => {
manager.open();
expect(document.body.style.overflow).toBe('hidden');
});
test('does not open again if already open', () => {
manager.open();
manager.open(); // second call should be no-op
expect(manager.isOpen()).toBe(true);
});
test('calls onOpen callback', () => {
const onOpen = jest.fn();
manager.destroy();
manager = new ModalManager(modal, { onOpen });
manager.open();
expect(onOpen).toHaveBeenCalledTimes(1);
});
test('dispatches modal:open custom event', () => {
const handler = jest.fn();
modal.addEventListener('modal:open', handler);
manager.open();
expect(handler).toHaveBeenCalledTimes(1);
});
test('sets isOpen to false immediately', () => {
manager.close();
expect(manager.isOpen()).toBe(false);
});
// =========================================================
// close()
// =========================================================
describe('close()', () => {
beforeEach(() => {
manager.open();
});
test('removes open class', () => {
expect(modal.classList.contains('open')).toBe(true);
manager.close();
expect(modal.classList.contains('open')).toBe(false);
});
test('sets isOpen to false immediately', () => {
manager.close();
expect(manager.isOpen()).toBe(false);
});
test('restores body scroll when no modals remain open', () => {
manager.close();
expect(document.body.style.overflow).toBe('');
});
test('adds hidden class after transitionend event fires', () => {
manager.close();
// Immediately after close(): hidden should NOT yet be added —
// the close animation is still in progress.
// (This is the bug that existed before the fix.)
expect(modal.classList.contains('hidden')).toBe(false);
// Simulate the CSS transition completing
const event = new Event('transitionend');
Object.defineProperty(event, 'target', { value: modal, writable: false });
modal.dispatchEvent(event);
expect(modal.classList.contains('hidden')).toBe(true);
});
test('adds hidden class via 250ms timeout fallback when transitionend never fires', () => {
jest.useFakeTimers();
manager.close();
expect(modal.classList.contains('hidden')).toBe(false);
// Advance past the fallback timeout (250ms)
jest.advanceTimersByTime(300);
expect(modal.classList.contains('hidden')).toBe(true);
jest.useRealTimers();
});
test('does not add hidden class if modal is reopened before timeout fires', () => {
jest.useFakeTimers();
manager.close();
jest.advanceTimersByTime(100); // halfway through timeout
// Re-open the modal before the timeout fires
manager.open();
jest.advanceTimersByTime(200); // past original timeout expiry
// Modal was reopened, so hidden must NOT have been added
expect(modal.classList.contains('hidden')).toBe(false);
expect(modal.classList.contains('open')).toBe(true);
jest.useRealTimers();
});
test('calls onClose callback', () => {
const onClose = jest.fn();
manager.destroy();
manager = new ModalManager(modal, { onClose });
manager.open();
manager.close();
expect(onClose).toHaveBeenCalledTimes(1);
});
test('dispatches modal:close custom event', () => {
const handler = jest.fn();
modal.addEventListener('modal:close', handler);
manager.close();
expect(handler).toHaveBeenCalledTimes(1);
});
test('is a no-op when modal is already closed', () => {
manager.close(); // close from open
const onClose = jest.fn();
manager.destroy();
manager = new ModalManager(modal, { onClose });
manager.close(); // call close on an already-closed modal
expect(onClose).not.toHaveBeenCalled();
});
test('restores body scroll when no modals remain open', () => {
manager.close();
expect(document.body.style.overflow).toBe('');
});
// =========================================================
// Keyboard interaction
// =========================================================
test('adds hidden class after transitionend event fires', () => {
manager.close();
describe('keyboard shortcuts', () => {
test('Escape key closes an open modal', () => {
manager.open();
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
expect(manager.isOpen()).toBe(false);
});
// Immediately after close(): hidden should NOT yet be added —
// the close animation is still in progress.
// (This is the bug that existed before the fix.)
expect(modal.classList.contains('hidden')).toBe(false);
test('Escape key does nothing when modal is already closed', () => {
expect(() => {
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
}).not.toThrow();
});
// Simulate the CSS transition completing
const event = new Event('transitionend');
Object.defineProperty(event, 'target', { value: modal, writable: false });
modal.dispatchEvent(event);
test('closeOnEscape: false prevents Escape from closing', () => {
manager.destroy();
manager = new ModalManager(modal, { closeOnEscape: false });
manager.open();
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
expect(manager.isOpen()).toBe(true);
});
expect(modal.classList.contains('hidden')).toBe(true);
});
// =========================================================
// Close triggers
// =========================================================
test('adds hidden class via 250ms timeout fallback when transitionend never fires', () => {
jest.useFakeTimers();
describe('close triggers', () => {
test('clicking the × close button closes the modal', () => {
manager.open();
modal.querySelector('.modal-close').click();
expect(manager.isOpen()).toBe(false);
});
manager.close();
expect(modal.classList.contains('hidden')).toBe(false);
test('clicking backdrop (data-close) closes the modal', () => {
manager.open();
modal.querySelector('.modal-backdrop').click();
expect(manager.isOpen()).toBe(false);
});
// Advance past the fallback timeout (250ms)
jest.advanceTimersByTime(300);
test('closeOnBackdrop: false prevents backdrop from closing', () => {
manager.destroy();
manager = new ModalManager(modal, { closeOnBackdrop: false });
manager.open();
modal.querySelector('.modal-backdrop').click();
expect(manager.isOpen()).toBe(true);
});
expect(modal.classList.contains('hidden')).toBe(true);
jest.useRealTimers();
});
// =========================================================
// destroy()
// =========================================================
test('does not add hidden class if modal is reopened before timeout fires', () => {
jest.useFakeTimers();
describe('destroy()', () => {
test('closes modal if open', () => {
manager.open();
manager.destroy();
expect(manager.isOpen()).toBe(false);
});
manager.close();
jest.advanceTimersByTime(100); // halfway through timeout
test('does not throw when destroying a closed modal', () => {
expect(() => manager.destroy()).not.toThrow();
});
// Re-open the modal before the timeout fires
manager.open();
jest.advanceTimersByTime(200); // past original timeout expiry
// Modal was reopened, so hidden must NOT have been added
expect(modal.classList.contains('hidden')).toBe(false);
expect(modal.classList.contains('open')).toBe(true);
jest.useRealTimers();
});
test('calls onClose callback', () => {
const onClose = jest.fn();
manager.destroy();
manager = new ModalManager(modal, { onClose });
manager.open();
manager.close();
expect(onClose).toHaveBeenCalledTimes(1);
});
test('dispatches modal:close custom event', () => {
const handler = jest.fn();
modal.addEventListener('modal:close', handler);
manager.close();
expect(handler).toHaveBeenCalledTimes(1);
});
test('is a no-op when modal is already closed', () => {
manager.close(); // close from open
const onClose = jest.fn();
manager.destroy();
manager = new ModalManager(modal, { onClose });
manager.close(); // call close on an already-closed modal
expect(onClose).not.toHaveBeenCalled();
});
});
// =========================================================
// Keyboard interaction
// =========================================================
describe('keyboard shortcuts', () => {
test('Escape key closes an open modal', () => {
manager.open();
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
expect(manager.isOpen()).toBe(false);
});
test('Escape key does nothing when modal is already closed', () => {
expect(() => {
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
}).not.toThrow();
});
test('closeOnEscape: false prevents Escape from closing', () => {
manager.destroy();
manager = new ModalManager(modal, { closeOnEscape: false });
manager.open();
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
expect(manager.isOpen()).toBe(true);
});
});
// =========================================================
// Close triggers
// =========================================================
describe('close triggers', () => {
test('clicking the × close button closes the modal', () => {
manager.open();
modal.querySelector('.modal-close').click();
expect(manager.isOpen()).toBe(false);
});
test('clicking backdrop (data-close) closes the modal', () => {
manager.open();
modal.querySelector('.modal-backdrop').click();
expect(manager.isOpen()).toBe(false);
});
test('closeOnBackdrop: false prevents backdrop from closing', () => {
manager.destroy();
manager = new ModalManager(modal, { closeOnBackdrop: false });
manager.open();
modal.querySelector('.modal-backdrop').click();
expect(manager.isOpen()).toBe(true);
});
});
// =========================================================
// destroy()
// =========================================================
describe('destroy()', () => {
test('closes modal if open', () => {
manager.open();
manager.destroy();
expect(manager.isOpen()).toBe(false);
});
test('does not throw when destroying a closed modal', () => {
expect(() => manager.destroy()).not.toThrow();
});
});
});