From 2fd40b4889b6198ee3c8bed3dd2bd5f78339f887 Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Wed, 6 Nov 2024 15:41:27 -0800 Subject: [PATCH] Add unit test. --- jest.config.js | 2 +- tests/unit/extra_model_config.test.ts | 31 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/unit/extra_model_config.test.ts diff --git a/jest.config.js b/jest.config.js index 46c74552..3d00a8b6 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,7 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', - testMatch: ['/src/__tests__/unit/**/*.test.ts'], + testMatch: ['/tests/unit/**/*.test.ts'], automock: false, transform: { '^.+\\.ts$': [ diff --git a/tests/unit/extra_model_config.test.ts b/tests/unit/extra_model_config.test.ts new file mode 100644 index 00000000..e1cfbdc8 --- /dev/null +++ b/tests/unit/extra_model_config.test.ts @@ -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'); + }); +});