chore: fix tests

This commit is contained in:
Louis 2025-04-07 14:11:25 +07:00
parent a10cec1a66
commit f3326bc161
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2
3 changed files with 5 additions and 21 deletions

View File

@ -3,7 +3,6 @@ import * as Events from './events'
import * as FileSystem from './fs' import * as FileSystem from './fs'
import * as Extension from './extension' import * as Extension from './extension'
import * as Extensions from './extensions' import * as Extensions from './extensions'
import * as Tools from './tools'
import * as Models from './models' import * as Models from './models'
describe('Module Tests', () => { describe('Module Tests', () => {
@ -27,10 +26,6 @@ describe('Module Tests', () => {
expect(Extensions).toBeDefined() expect(Extensions).toBeDefined()
}) })
it('should export all base tools', () => {
expect(Tools).toBeDefined()
})
it('should export all base tools', () => { it('should export all base tools', () => {
expect(Models).toBeDefined() expect(Models).toBeDefined()
}) })

View File

@ -4,7 +4,6 @@ import { fs, joinPath } from '@janhq/core'
import { useAtom, useAtomValue, useSetAtom } from 'jotai' import { useAtom, useAtomValue, useSetAtom } from 'jotai'
import { useLoadTheme } from './useLoadTheme' import { useLoadTheme } from './useLoadTheme'
import { janDataFolderPathAtom } from '@/helpers/atoms/AppConfig.atom'
import { import {
selectedThemeIdAtom, selectedThemeIdAtom,
themeDataAtom, themeDataAtom,
@ -27,8 +26,6 @@ describe('useLoadTheme', () => {
jest.clearAllMocks() jest.clearAllMocks()
}) })
const mockJanDataFolderPath = '/mock/path'
const mockThemesPath = '/mock/path/themes'
const mockSelectedThemeId = 'joi-light' const mockSelectedThemeId = 'joi-light'
const mockThemeData = { const mockThemeData = {
id: 'joi-light', id: 'joi-light',
@ -51,8 +48,6 @@ describe('useLoadTheme', () => {
// Mock Jotai hooks // Mock Jotai hooks
;(useAtomValue as jest.Mock).mockImplementation((atom) => { ;(useAtomValue as jest.Mock).mockImplementation((atom) => {
switch (atom) { switch (atom) {
case janDataFolderPathAtom:
return mockJanDataFolderPath
default: default:
return undefined return undefined
} }
@ -80,15 +75,6 @@ describe('useLoadTheme', () => {
const mockSetTheme = jest.fn() const mockSetTheme = jest.fn()
;(useTheme as jest.Mock).mockReturnValue({ setTheme: mockSetTheme }) ;(useTheme as jest.Mock).mockReturnValue({ setTheme: mockSetTheme })
// Mock window.electronAPI
Object.defineProperty(window, 'electronAPI', {
value: {
setNativeThemeLight: jest.fn(),
setNativeThemeDark: jest.fn(),
},
writable: true,
})
const { result } = renderHook(() => useLoadTheme()) const { result } = renderHook(() => useLoadTheme())
await act(async () => { await act(async () => {
@ -96,12 +82,11 @@ describe('useLoadTheme', () => {
}) })
// Assertions // Assertions
expect(readTheme).toHaveBeenLastCalledWith({ theme: 'joi-light' }) expect(readTheme).toHaveBeenLastCalledWith({ themeName: 'joi-light' })
}) })
it('should set default theme if no selected theme', async () => { it('should set default theme if no selected theme', async () => {
// Mock Jotai hooks with empty selected theme // Mock Jotai hooks with empty selected theme
;(useAtomValue as jest.Mock).mockReturnValue(mockJanDataFolderPath)
;(useSetAtom as jest.Mock).mockReturnValue(jest.fn()) ;(useSetAtom as jest.Mock).mockReturnValue(jest.fn())
;(useAtom as jest.Mock).mockReturnValue(['', jest.fn()]) ;(useAtom as jest.Mock).mockReturnValue(['', jest.fn()])
;(useAtom as jest.Mock).mockReturnValue([{}, jest.fn()]) ;(useAtom as jest.Mock).mockReturnValue([{}, jest.fn()])

View File

@ -1,3 +1,7 @@
/**
* @jest-environment jsdom
*/
import 'openai/shims/node'
import React from 'react' import React from 'react'
import { act, render, screen, waitFor } from '@testing-library/react' import { act, render, screen, waitFor } from '@testing-library/react'
import ThreadScreen from './index' import ThreadScreen from './index'