Files
bentopdf/src/tests/tools.test.ts
T
alam00000 9d0b68e18c Refactor and enhance type safety across various modules
- 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.
2026-03-31 17:59:49 +05:30

60 lines
2.3 KiB
TypeScript

// toolCategories.test.ts
import { categories } from '@/js/config/tools';
import { describe, it, expect } from 'vitest';
describe('Tool Categories Configuration', () => {
// 1. Basic Structure and Type Checking
it('should be an array of category objects', () => {
expect(Array.isArray(categories)).toBe(true);
expect(categories.length).toBeGreaterThan(0);
});
// 2. Loop through each category to perform specific checks
describe.each(categories)('Category: "$name"', (category) => {
// Check that the category object itself is well-formed
it('should have a non-empty "name" string and a non-empty "tools" array', () => {
expect(typeof category.name).toBe('string');
expect(category.name.length).toBeGreaterThan(0);
expect(Array.isArray(category.tools)).toBe(true);
expect(category.tools.length).toBeGreaterThan(0);
});
// **KEY CHANGE**: This test now ensures IDs are unique only WITHIN this specific category.
it('should not contain any duplicate tool IDs within its own list', () => {
const toolIds = category.tools.map((tool) => {
if ('id' in tool) return tool.id;
if ('href' in tool) {
const match = (tool as { href: string }).href.match(
/\/([^/]+)\.html$/
);
return match ? match[1] : (tool as { href: string }).href;
}
return 'unknown';
});
const uniqueToolIds = new Set(toolIds);
// This assertion checks for duplicates inside THIS category only.
expect(uniqueToolIds.size).toBe(toolIds.length);
});
// 3. Loop through each tool inside the category to validate its schema
describe.each(category.tools)('Tool: "$name"', (tool) => {
it('should have the correct properties with non-empty string values', () => {
// Check for property existence
expect(tool).toHaveProperty('id');
expect(tool).toHaveProperty('name');
expect(tool).toHaveProperty('icon');
expect(tool).toHaveProperty('subtitle');
// Check for non-empty string types for each property
for (const key of ['id', 'name', 'icon', 'subtitle']) {
const value = tool[key as keyof typeof tool];
expect(typeof value).toBe('string');
expect(value.length).toBeGreaterThan(0);
}
});
});
});
});