chore: fix tests
This commit is contained in:
parent
01964d3d03
commit
57c537f6a4
@ -1,3 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* @jest-environment jsdom
|
||||||
|
*/
|
||||||
import { openExternalUrl } from './core'
|
import { openExternalUrl } from './core'
|
||||||
import { joinPath } from './core'
|
import { joinPath } from './core'
|
||||||
import { openFileExplorer } from './core'
|
import { openFileExplorer } from './core'
|
||||||
@ -51,20 +54,6 @@ describe('test core apis', () => {
|
|||||||
expect(globalThis.core.api.getJanDataFolderPath).toHaveBeenCalled()
|
expect(globalThis.core.api.getJanDataFolderPath).toHaveBeenCalled()
|
||||||
expect(result).toBe('/path/to/jan/data')
|
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', () => {
|
describe('dirName - just a pass thru api', () => {
|
||||||
|
|||||||
@ -40,9 +40,12 @@ describe('useLoadTheme', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('should load theme and set variables', async () => {
|
it('should load theme and set variables', async () => {
|
||||||
|
const readTheme = jest.fn().mockResolvedValue("{}")
|
||||||
|
|
||||||
global.window.core = {
|
global.window.core = {
|
||||||
api: {
|
api: {
|
||||||
getThemes: () => ['joi-light', 'joi-dark'],
|
getThemes: () => ['joi-light', 'joi-dark'],
|
||||||
|
readTheme,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// Mock Jotai hooks
|
// Mock Jotai hooks
|
||||||
@ -93,10 +96,7 @@ describe('useLoadTheme', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Assertions
|
// Assertions
|
||||||
expect(fs.readFileSync).toHaveBeenLastCalledWith(
|
expect(readTheme).toHaveBeenLastCalledWith({ theme: 'joi-light' })
|
||||||
`file://themes/joi-light/theme.json`,
|
|
||||||
'utf-8'
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should set default theme if no selected theme', async () => {
|
it('should set default theme if no selected theme', async () => {
|
||||||
|
|||||||
@ -37,6 +37,7 @@ export const useLoadTheme = () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const applyTheme = (theme: Theme) => {
|
const applyTheme = (theme: Theme) => {
|
||||||
|
if (!theme.variables) return
|
||||||
const variables = cssVars(theme.variables)
|
const variables = cssVars(theme.variables)
|
||||||
const headTag = document.getElementsByTagName('head')[0]
|
const headTag = document.getElementsByTagName('head')[0]
|
||||||
const styleTag = document.createElement('style')
|
const styleTag = document.createElement('style')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user