forked from CherryHQ/cherry-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindowUtil.test.ts
More file actions
69 lines (55 loc) · 1.87 KB
/
windowUtil.test.ts
File metadata and controls
69 lines (55 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { afterEach, describe, expect, it, vi } from 'vitest'
const originalGetSystemVersion = process.getSystemVersion
async function loadWindowUtil({ isWin, systemVersion = '' }: { isWin: boolean; systemVersion?: string }) {
vi.resetModules()
vi.doMock('../../constant', () => ({
isDev: false,
isWin
}))
const getSystemVersionMock = vi.fn(() => systemVersion)
Object.defineProperty(process, 'getSystemVersion', {
value: getSystemVersionMock,
configurable: true
})
const windowUtil = await import('../windowUtil')
return { ...windowUtil }
}
afterEach(() => {
vi.resetModules()
vi.restoreAllMocks()
vi.doUnmock('../../constant')
Object.defineProperty(process, 'getSystemVersion', {
value: originalGetSystemVersion,
configurable: true
})
})
describe('getWindowsBackgroundMaterial', () => {
it('returns mica on Windows 11 22H2 and newer', async () => {
const { getWindowsBackgroundMaterial } = await loadWindowUtil({
isWin: true,
systemVersion: '10.0.22621'
})
expect(getWindowsBackgroundMaterial()).toBe('mica')
})
it('returns undefined below the Windows 11 22H2 build threshold', async () => {
const { getWindowsBackgroundMaterial } = await loadWindowUtil({
isWin: true,
systemVersion: '10.0.22000'
})
expect(getWindowsBackgroundMaterial()).toBeUndefined()
})
it('returns undefined when the system version cannot be parsed', async () => {
const { getWindowsBackgroundMaterial } = await loadWindowUtil({
isWin: true,
systemVersion: 'Windows 11'
})
expect(getWindowsBackgroundMaterial()).toBeUndefined()
})
it('returns undefined on non-Windows platforms', async () => {
const { getWindowsBackgroundMaterial } = await loadWindowUtil({
isWin: false,
systemVersion: '10.0.22621'
})
expect(getWindowsBackgroundMaterial()).toBeUndefined()
})
})