Skip to content

Commit

Permalink
Add unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
robinjhuang committed Nov 6, 2024
1 parent 942dff7 commit 2fd40b4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['<rootDir>/src/__tests__/unit/**/*.test.ts'],
testMatch: ['<rootDir>/tests/unit/**/*.test.ts'],
automock: false,
transform: {
'^.+\\.ts$': [
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/extra_model_config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { app } from 'electron';
import path from 'path';
import { getModelConfigPath } from '../../src/config/extra_model_config';

// Mock electron
jest.mock('electron', () => ({
app: {
getPath: jest.fn(),
},
}));

describe('getModelConfigPath', () => {
it('should return the correct path', async () => {
// Mock the userData path
const mockUserDataPath = '/fake/user/data';
(app.getPath as jest.Mock).mockImplementation((key: string) => {
if (key === 'userData') {
return mockUserDataPath;
}
throw new Error(`Unexpected getPath key: ${key}`);
});

const result = await getModelConfigPath();

// Verify the path is correctly joined
expect(result).toBe(path.join(mockUserDataPath, 'extra_model_paths.yaml'));

// Verify app.getPath was called with correct argument
expect(app.getPath).toHaveBeenCalledWith('userData');
});
});

0 comments on commit 2fd40b4

Please sign in to comment.