mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-05 20:02:47 +01:00
- Updated function parameters and return types in `page-preview.ts`, `pdf-decrypt.ts`, and `pymupdf-loader.ts` for improved type safety. - Introduced type definitions for `CpdfInstance`, `PyMuPDFInstance`, and other related types to ensure better type checking. - Enhanced error handling in `sanitize.ts` by creating a utility function for error messages. - Removed unnecessary type assertions and improved type inference in `editor.ts`, `serialization.ts`, and `tools.test.ts`. - Added type definitions for markdown-it plugins to improve compatibility and type safety. - Enforced stricter TypeScript settings by enabling `noImplicitAny` in `tsconfig.json`. - Cleaned up test files by refining type assertions and ensuring consistency in type usage.
62 lines
2.2 KiB
TypeScript
62 lines
2.2 KiB
TypeScript
import { state, resetState } from '@/js/state';
|
|
import { describe, it, expect, beforeEach } from 'vitest';
|
|
|
|
describe('State Management', () => {
|
|
// Test the initial state on import
|
|
describe('Initial State', () => {
|
|
it('should have the correct initial values', () => {
|
|
expect(state.activeTool).toBeNull();
|
|
expect(state.files).toEqual([]); // Use toEqual for arrays/objects
|
|
expect(state.pdfDoc).toBeNull();
|
|
expect(state.pdfPages).toEqual([]);
|
|
expect(state.currentPdfUrl).toBeNull();
|
|
});
|
|
});
|
|
|
|
// Test the resetState function
|
|
describe('resetState function', () => {
|
|
// Before each test in this block, we'll "dirty" the state
|
|
// to ensure the reset function is actually doing something.
|
|
beforeEach(() => {
|
|
// 1. Modify the state properties to non-default values
|
|
state.activeTool = 'merge';
|
|
state.files = [{ name: 'dummy.pdf', size: 1234 } as File];
|
|
state.pdfDoc = {
|
|
numPages: 5,
|
|
} as unknown as import('pdf-lib').PDFDocument;
|
|
state.pdfPages = [{}, {}]; // Mock page objects
|
|
state.currentPdfUrl = 'blob:http://localhost/some-uuid';
|
|
|
|
// 2. Create the DOM element that the function interacts with
|
|
// The setup.ts file will clean this up automatically after each test.
|
|
document.body.innerHTML =
|
|
'<div id="tool-content">Some old tool content</div>';
|
|
});
|
|
|
|
it('should reset all state properties to their initial values', () => {
|
|
// Call the function to test
|
|
resetState();
|
|
|
|
// Assert that all properties are back to their default state
|
|
expect(state.activeTool).toBeNull();
|
|
expect(state.files).toEqual([]);
|
|
expect(state.pdfDoc).toBeNull();
|
|
expect(state.pdfPages).toEqual([]);
|
|
expect(state.currentPdfUrl).toBeNull();
|
|
});
|
|
|
|
it('should clear the innerHTML of the #tool-content element', () => {
|
|
const toolContentElement = document.getElementById('tool-content');
|
|
|
|
// Sanity check: ensure the content exists before resetting
|
|
expect(toolContentElement?.innerHTML).toBe('Some old tool content');
|
|
|
|
// Call the function to test
|
|
resetState();
|
|
|
|
// Assert that the element's content has been cleared
|
|
expect(toolContentElement?.innerHTML).toBe('');
|
|
});
|
|
});
|
|
});
|