mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-19 14:09:31 +02:00
fix: tests
This commit is contained in:
128
.idea/workspace.xml
generated
128
.idea/workspace.xml
generated
@@ -4,11 +4,8 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="fix: path">
|
||||
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="fix: vite worker format">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/lib/ghostscript/background-worker.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/ghostscript/background-worker.js" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/pdf/compress-pdf/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/pdf/compress-pdf/index.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/pdf/compress-pdf/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/pdf/compress-pdf/service.ts" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -160,56 +157,56 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"ASKED_ADD_EXTERNAL_FILES": "true",
|
||||
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"Docker.Dockerfile build.executor": "Run",
|
||||
"Docker.Dockerfile.executor": "Run",
|
||||
"Playwright.Create transparent PNG.should make png color transparent.executor": "Run",
|
||||
"Playwright.JoinText Component.executor": "Run",
|
||||
"Playwright.JoinText Component.should merge text pieces with specified join character.executor": "Run",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"Vitest.compute function (1).executor": "Run",
|
||||
"Vitest.compute function.executor": "Run",
|
||||
"Vitest.mergeText.executor": "Run",
|
||||
"Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor": "Run",
|
||||
"Vitest.mergeText.should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false.executor": "Run",
|
||||
"Vitest.parsePageRanges.executor": "Run",
|
||||
"Vitest.removeDuplicateLines function.executor": "Run",
|
||||
"Vitest.removeDuplicateLines function.newlines option.executor": "Run",
|
||||
"Vitest.removeDuplicateLines function.newlines option.should filter newlines when newlines is set to filter.executor": "Run",
|
||||
"Vitest.replaceText function (regexp mode).should return the original text when passed an invalid regexp.executor": "Run",
|
||||
"Vitest.replaceText function.executor": "Run",
|
||||
"Vitest.timeBetweenDates.executor": "Run",
|
||||
"git-widget-placeholder": "compression",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "C:/Users/Ibrahima/IdeaProjects/omni-tools/src",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"npm.build.executor": "Run",
|
||||
"npm.dev.executor": "Run",
|
||||
"npm.lint.executor": "Run",
|
||||
"npm.prebuild.executor": "Run",
|
||||
"npm.script:create:tool.executor": "Run",
|
||||
"npm.test.executor": "Run",
|
||||
"npm.test:e2e.executor": "Run",
|
||||
"npm.test:e2e:run.executor": "Run",
|
||||
"prettierjs.PrettierConfiguration.Package": "C:\\Users\\Ibrahima\\IdeaProjects\\omni-tools\\node_modules\\prettier",
|
||||
"project.structure.last.edited": "Problems",
|
||||
"project.structure.proportion": "0.0",
|
||||
"project.structure.side.proportion": "0.2",
|
||||
"settings.editor.selected.configurable": "refactai_advanced_settings",
|
||||
"ts.external.directory.path": "C:\\Users\\Ibrahima\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"ASKED_ADD_EXTERNAL_FILES": "true",
|
||||
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"Docker.Dockerfile build.executor": "Run",
|
||||
"Docker.Dockerfile.executor": "Run",
|
||||
"Playwright.Create transparent PNG.should make png color transparent.executor": "Run",
|
||||
"Playwright.JoinText Component.executor": "Run",
|
||||
"Playwright.JoinText Component.should merge text pieces with specified join character.executor": "Run",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"Vitest.compute function (1).executor": "Run",
|
||||
"Vitest.compute function.executor": "Run",
|
||||
"Vitest.mergeText.executor": "Run",
|
||||
"Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor": "Run",
|
||||
"Vitest.mergeText.should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false.executor": "Run",
|
||||
"Vitest.parsePageRanges.executor": "Run",
|
||||
"Vitest.removeDuplicateLines function.executor": "Run",
|
||||
"Vitest.removeDuplicateLines function.newlines option.executor": "Run",
|
||||
"Vitest.removeDuplicateLines function.newlines option.should filter newlines when newlines is set to filter.executor": "Run",
|
||||
"Vitest.replaceText function (regexp mode).should return the original text when passed an invalid regexp.executor": "Run",
|
||||
"Vitest.replaceText function.executor": "Run",
|
||||
"Vitest.timeBetweenDates.executor": "Run",
|
||||
"git-widget-placeholder": "main",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "C:/Users/Ibrahima/IdeaProjects/omni-tools/src",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"npm.build.executor": "Run",
|
||||
"npm.dev.executor": "Run",
|
||||
"npm.lint.executor": "Run",
|
||||
"npm.prebuild.executor": "Run",
|
||||
"npm.script:create:tool.executor": "Run",
|
||||
"npm.test.executor": "Run",
|
||||
"npm.test:e2e.executor": "Run",
|
||||
"npm.test:e2e:run.executor": "Run",
|
||||
"prettierjs.PrettierConfiguration.Package": "C:\\Users\\Ibrahima\\IdeaProjects\\omni-tools\\node_modules\\prettier",
|
||||
"project.structure.last.edited": "Problems",
|
||||
"project.structure.proportion": "0.0",
|
||||
"project.structure.side.proportion": "0.2",
|
||||
"settings.editor.selected.configurable": "refactai_advanced_settings",
|
||||
"ts.external.directory.path": "C:\\Users\\Ibrahima\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
}
|
||||
}]]></component>
|
||||
}</component>
|
||||
<component name="ReactDesignerToolWindowState">
|
||||
<option name="myId2Visible">
|
||||
<map>
|
||||
@@ -314,11 +311,11 @@
|
||||
</list>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="npm.dev" />
|
||||
<item itemvalue="Vitest.replaceText function (regexp mode).should return the original text when passed an invalid regexp" />
|
||||
<item itemvalue="Vitest.parsePageRanges" />
|
||||
<item itemvalue="Vitest.timeBetweenDates" />
|
||||
<item itemvalue="Vitest.calculateTimeBetweenDates" />
|
||||
<item itemvalue="npm.dev" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
@@ -408,14 +405,7 @@
|
||||
<workItem from="1743348610793" duration="21855000" />
|
||||
<workItem from="1743397561176" duration="25000" />
|
||||
<workItem from="1743458576265" duration="13083000" />
|
||||
</task>
|
||||
<task id="LOCAL-00137" summary="docs: readme">
|
||||
<option name="closed" value="true" />
|
||||
<created>1740788899030</created>
|
||||
<option name="number" value="00137" />
|
||||
<option name="presentableId" value="LOCAL-00137" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1740788899030</updated>
|
||||
<workItem from="1743690613245" duration="77000" />
|
||||
</task>
|
||||
<task id="LOCAL-00138" summary="feat: remove duplicate lines">
|
||||
<option name="closed" value="true" />
|
||||
@@ -801,7 +791,15 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1743645074051</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="186" />
|
||||
<task id="LOCAL-00186" summary="fix: vite worker format">
|
||||
<option name="closed" value="true" />
|
||||
<created>1743647707334</created>
|
||||
<option name="number" value="00186" />
|
||||
<option name="presentableId" value="LOCAL-00186" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1743647707334</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="187" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@@ -848,7 +846,6 @@
|
||||
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
|
||||
<option name="CHECK_NEW_TODO" value="false" />
|
||||
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
|
||||
<MESSAGE value="fix: tools by category scroll" />
|
||||
<MESSAGE value="fix: missing meta" />
|
||||
<MESSAGE value="feat: trim video" />
|
||||
<MESSAGE value="refactor: file inputs" />
|
||||
@@ -873,7 +870,8 @@
|
||||
<MESSAGE value="refactor: compress pdf" />
|
||||
<MESSAGE value="refactor: lib" />
|
||||
<MESSAGE value="fix: path" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="fix: path" />
|
||||
<MESSAGE value="fix: vite worker format" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="fix: vite worker format" />
|
||||
</component>
|
||||
<component name="XSLT-Support.FileAssociations.UIState">
|
||||
<expand />
|
||||
|
@@ -1,107 +0,0 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { compressPdf } from './service';
|
||||
import { CompressionLevel } from './types';
|
||||
|
||||
// Mock the mupdf module
|
||||
vi.mock('mupdf', () => {
|
||||
return {
|
||||
Document: {
|
||||
openDocument: vi.fn(() => ({
|
||||
countPages: vi.fn(() => 2),
|
||||
loadPage: vi.fn(() => ({}))
|
||||
}))
|
||||
},
|
||||
PDFWriter: vi.fn(() => ({
|
||||
addPage: vi.fn(),
|
||||
asBuffer: vi.fn(() => Buffer.from('test'))
|
||||
}))
|
||||
};
|
||||
});
|
||||
|
||||
// Mock the pdf-lib module
|
||||
vi.mock('pdf-lib', () => {
|
||||
return {
|
||||
PDFDocument: {
|
||||
load: vi.fn(() => ({
|
||||
getPageCount: vi.fn(() => 2)
|
||||
}))
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
describe('compressPdf', () => {
|
||||
it('should compress a PDF file with low compression', async () => {
|
||||
// Create a mock File
|
||||
const mockFile = new File(['test'], 'test.pdf', {
|
||||
type: 'application/pdf'
|
||||
});
|
||||
|
||||
// Mock arrayBuffer method
|
||||
mockFile.arrayBuffer = vi.fn().mockResolvedValue(new ArrayBuffer(4));
|
||||
|
||||
// Call the function with low compression
|
||||
const result = await compressPdf(mockFile, {
|
||||
compressionLevel: 'low' as CompressionLevel
|
||||
});
|
||||
|
||||
// Check the result
|
||||
expect(result).toBeInstanceOf(File);
|
||||
expect(result.name).toBe('test-compressed.pdf');
|
||||
expect(result.type).toBe('application/pdf');
|
||||
});
|
||||
|
||||
it('should compress a PDF file with medium compression', async () => {
|
||||
// Create a mock File
|
||||
const mockFile = new File(['test'], 'test.pdf', {
|
||||
type: 'application/pdf'
|
||||
});
|
||||
|
||||
// Mock arrayBuffer method
|
||||
mockFile.arrayBuffer = vi.fn().mockResolvedValue(new ArrayBuffer(4));
|
||||
|
||||
// Call the function with medium compression
|
||||
const result = await compressPdf(mockFile, {
|
||||
compressionLevel: 'medium' as CompressionLevel
|
||||
});
|
||||
|
||||
// Check the result
|
||||
expect(result).toBeInstanceOf(File);
|
||||
expect(result.name).toBe('test-compressed.pdf');
|
||||
expect(result.type).toBe('application/pdf');
|
||||
});
|
||||
|
||||
it('should compress a PDF file with high compression', async () => {
|
||||
// Create a mock File
|
||||
const mockFile = new File(['test'], 'test.pdf', {
|
||||
type: 'application/pdf'
|
||||
});
|
||||
|
||||
// Mock arrayBuffer method
|
||||
mockFile.arrayBuffer = vi.fn().mockResolvedValue(new ArrayBuffer(4));
|
||||
|
||||
// Call the function with high compression
|
||||
const result = await compressPdf(mockFile, {
|
||||
compressionLevel: 'high' as CompressionLevel
|
||||
});
|
||||
|
||||
// Check the result
|
||||
expect(result).toBeInstanceOf(File);
|
||||
expect(result.name).toBe('test-compressed.pdf');
|
||||
expect(result.type).toBe('application/pdf');
|
||||
});
|
||||
|
||||
it('should handle errors during compression', async () => {
|
||||
// Create a mock File
|
||||
const mockFile = new File(['test'], 'test.pdf', {
|
||||
type: 'application/pdf'
|
||||
});
|
||||
|
||||
// Mock arrayBuffer method to throw an error
|
||||
mockFile.arrayBuffer = vi.fn().mockRejectedValue(new Error('Test error'));
|
||||
|
||||
// Check that the function throws an error
|
||||
await expect(
|
||||
compressPdf(mockFile, { compressionLevel: 'medium' as CompressionLevel })
|
||||
).rejects.toThrow('Failed to compress PDF: Test error');
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user