Skip to content

Commit

Permalink
chore: update test case app service
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur committed Jan 29, 2025
1 parent 26bbaf6 commit 1fe3ef0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 34 deletions.
3 changes: 2 additions & 1 deletion web/hooks/useGetSystemResources.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useCallback, useEffect, useState } from 'react'

import { ExtensionTypeEnum, HardwareManagementExtension } from '@janhq/core'
Expand Down Expand Up @@ -83,7 +84,7 @@ export default function useGetSystemResources() {
setRamUtilitized,
setCpuUsage,
setGpus,
// setTotalNvidiaVram,
setTotalNvidiaVram,
setAvailableVram,
])

Expand Down
5 changes: 3 additions & 2 deletions web/screens/Settings/Engines/LocalEngineSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@janhq/core'
import { Button, ScrollArea, Badge, Select, Progress } from '@janhq/joi'

import { useAtom } from 'jotai'
import { twMerge } from 'tailwind-merge'

import { useActiveModel } from '@/hooks/useActiveModel'
Expand All @@ -27,8 +28,8 @@ import { formatDownloadPercentage } from '@/utils/converter'
import ExtensionSetting from '../ExtensionSetting'

import DeleteEngineVariant from './DeleteEngineVariant'

import { LocalEngineDefaultVariantAtom } from '@/helpers/atoms/App.atom'
import { useAtom } from 'jotai'
const os = () => {
switch (PLATFORM) {
case 'win32':
Expand Down Expand Up @@ -104,7 +105,7 @@ const LocalEngineSettings = ({ engine }: { engine: InferenceEngine }) => {
if (defaultEngineVariant?.variant) {
setSelectedVariants(defaultEngineVariant.variant || '')
}
}, [defaultEngineVariant])
}, [defaultEngineVariant, setSelectedVariants])

const handleEngineUpdate = useCallback(
async (event: { id: string; type: DownloadEvent; percent: number }) => {
Expand Down
39 changes: 18 additions & 21 deletions web/services/appService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,33 @@ import { extensionManager } from '@/extension'
import { appService } from './appService'

test('should return correct system information when monitoring extension is found', async () => {
const mockGpuSetting = { name: 'NVIDIA GeForce GTX 1080', memory: 8192 }
const mockOsInfo = { platform: 'win32', release: '10.0.19041' }
const mockHardwareInfo = {
cpu: { arch: 'arc' },
ram: { available: 4000, total: 8000 },
}
const mockMonitoringExtension = {
getGpuSetting: jest.fn().mockResolvedValue(mockGpuSetting),
getOsInfo: jest.fn().mockResolvedValue(mockOsInfo),
getHardware: jest.fn().mockResolvedValue(mockHardwareInfo),

(global as any).isMac = false;
(global as any).PLATFORM = "win32";

const mock = { cpu: { arch: 'arc' }, ram: { available: 4000, total: 8000 }, gpus: [{name: 'NVIDIA GeForce GTX 1080', total_vram: 8192}] }

const mockHardwareExtension = {
getHardware: jest.fn().mockResolvedValue(mock),
}
extensionManager.get = jest.fn().mockReturnValue(mockMonitoringExtension)
extensionManager.get = jest.fn().mockReturnValue(mockHardwareExtension)

const result = await appService.systemInformation()

expect(mockMonitoringExtension.getGpuSetting).toHaveBeenCalled()
expect(mockMonitoringExtension.getOsInfo).toHaveBeenCalled()
expect(mockMonitoringExtension.getHardware).toHaveBeenCalled()
expect(mockHardwareExtension.getHardware).toHaveBeenCalled()

expect(result).toEqual({
gpuSetting: mockGpuSetting,
gpuSetting: {gpus: mock.gpus, vulkan: false},
osInfo: {
...mockOsInfo,
arch: mockHardwareInfo.cpu.arch,
freeMem: mockHardwareInfo.ram.available,
totalMem: mockHardwareInfo.ram.total,
platform: 'win32',
arch: mock.cpu.arch,
freeMem: mock.ram.available,
totalMem: mock.ram.total,
},
})
})

test('should log a warning when monitoring extension is not found', async () => {
test('should log a warning when hardware extension is not found', async () => {
const consoleWarnMock = jest
.spyOn(console, 'warn')
.mockImplementation(() => {})
Expand All @@ -40,7 +37,7 @@ test('should log a warning when monitoring extension is not found', async () =>
await appService.systemInformation()

expect(consoleWarnMock).toHaveBeenCalledWith(
'System monitoring extension not found'
'Hardware extension not found'
)
consoleWarnMock.mockRestore()
})
10 changes: 0 additions & 10 deletions web/services/appService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
SystemInformation,
GpuSetting,
GpuSettingInfo,
EngineManagementExtension,
} from '@janhq/core'

import { getDefaultStore } from 'jotai'
Expand All @@ -27,20 +26,11 @@ export const appService = {
ExtensionTypeEnum.Hardware
)

const engineExtension = extensionManager?.get<EngineManagementExtension>(
ExtensionTypeEnum.Engine
)

if (!hardwareExtension) {
console.warn('Hardware extension not found')
return undefined
}

if (!engineExtension) {
console.warn('Engine extension not found')
return undefined
}

const hardwareInfo = await hardwareExtension?.getHardware()

const gpuSettingInfo: GpuSetting | undefined = {
Expand Down

0 comments on commit 1fe3ef0

Please sign in to comment.