-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdweb-keyboard-overlay.test.ts
More file actions
62 lines (49 loc) · 1.82 KB
/
dweb-keyboard-overlay.test.ts
File metadata and controls
62 lines (49 loc) · 1.82 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
import { describe, expect, it, vi } from 'vitest'
import {
applyDwebKeyboardOverlay,
type DwebPluginsModule,
} from './dweb-keyboard-overlay'
describe('dweb keyboard overlay', () => {
it('skips when current environment is not dweb', async () => {
const loadPlugins = vi.fn<() => Promise<DwebPluginsModule>>()
const result = await applyDwebKeyboardOverlay({
isDweb: () => false,
loadPlugins,
})
expect(result).toBe(false)
expect(loadPlugins).not.toHaveBeenCalled()
})
it('disables overlay in dweb environment', async () => {
const setOverlay = vi.fn<(overlay: boolean) => Promise<void>>().mockResolvedValue()
const loadPlugins = vi.fn<() => Promise<DwebPluginsModule>>().mockResolvedValue({
virtualKeyboardPlugin: { setOverlay },
})
const result = await applyDwebKeyboardOverlay({
isDweb: () => true,
loadPlugins,
})
expect(result).toBe(true)
expect(loadPlugins).toHaveBeenCalledTimes(1)
expect(setOverlay).toHaveBeenCalledWith(false)
})
it('returns false when virtual keyboard plugin is unavailable', async () => {
const loadPlugins = vi.fn<() => Promise<DwebPluginsModule>>().mockResolvedValue({})
const result = await applyDwebKeyboardOverlay({
isDweb: () => true,
loadPlugins,
})
expect(result).toBe(false)
expect(loadPlugins).toHaveBeenCalledTimes(1)
})
it('returns false when plugin loading fails', async () => {
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
const loadPlugins = vi.fn<() => Promise<DwebPluginsModule>>().mockRejectedValue(new Error('load-failed'))
const result = await applyDwebKeyboardOverlay({
isDweb: () => true,
loadPlugins,
})
expect(result).toBe(false)
expect(warnSpy).toHaveBeenCalledTimes(1)
warnSpy.mockRestore()
})
})