chore: fix tests

This commit is contained in:
Louis 2025-03-27 16:35:09 +07:00
parent 01964d3d03
commit 57c537f6a4
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2
3 changed files with 8 additions and 18 deletions

View File

@ -1,3 +1,6 @@
/**
* @jest-environment jsdom
*/
import { openExternalUrl } from './core'
import { joinPath } from './core'
import { openFileExplorer } from './core'
@ -51,20 +54,6 @@ describe('test core apis', () => {
expect(globalThis.core.api.getJanDataFolderPath).toHaveBeenCalled()
expect(result).toBe('/path/to/jan/data')
})
it('should execute function on main process', async () => {
const extension = 'testExtension'
const method = 'testMethod'
const args = ['arg1', 'arg2']
globalThis.core = {
api: {
invokeExtensionFunc: jest.fn().mockResolvedValue('result'),
},
}
const result = await executeOnMain(extension, method, ...args)
expect(globalThis.core.api.invokeExtensionFunc).toHaveBeenCalledWith(extension, method, ...args)
expect(result).toBe('result')
})
})
describe('dirName - just a pass thru api', () => {

View File

@ -40,9 +40,12 @@ describe('useLoadTheme', () => {
}
it('should load theme and set variables', async () => {
const readTheme = jest.fn().mockResolvedValue("{}")
global.window.core = {
api: {
getThemes: () => ['joi-light', 'joi-dark'],
readTheme,
},
}
// Mock Jotai hooks
@ -93,10 +96,7 @@ describe('useLoadTheme', () => {
})
// Assertions
expect(fs.readFileSync).toHaveBeenLastCalledWith(
`file://themes/joi-light/theme.json`,
'utf-8'
)
expect(readTheme).toHaveBeenLastCalledWith({ theme: 'joi-light' })
})
it('should set default theme if no selected theme', async () => {

View File

@ -37,6 +37,7 @@ export const useLoadTheme = () => {
)
const applyTheme = (theme: Theme) => {
if (!theme.variables) return
const variables = cssVars(theme.variables)
const headTag = document.getElementsByTagName('head')[0]
const styleTag = document.createElement('style')