forked from CircuitVerse/cv-frontend-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitConvertor.spec.js
More file actions
117 lines (100 loc) · 2.94 KB
/
bitConvertor.spec.js
File metadata and controls
117 lines (100 loc) · 2.94 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { setup } from '../src/setup'
import {
bitConverterDialog,
setBaseValues,
setupBitConvertor,
} from '../src/utils'
import { createPinia, setActivePinia } from 'pinia'
import { mount } from '@vue/test-utils'
import { createRouter, createWebHistory } from 'vue-router'
import i18n from '#/locales/i18n'
import { routes } from '#/router'
import vuetify from '#/plugins/vuetify'
import simulator from '#/pages/simulator.vue'
import { vi } from 'vitest'
vi.mock('@tauri-apps/api/event', () => ({
listen: vi.fn(() => Promise.resolve(() => {})),
}))
global.ResizeObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}))
HTMLCanvasElement.prototype.getContext = vi.fn(() => ({
clearRect: vi.fn(),
fillRect: vi.fn(),
fillText: vi.fn(),
strokeRect: vi.fn(),
beginPath: vi.fn(),
moveTo: vi.fn(),
lineTo: vi.fn(),
stroke: vi.fn(),
closePath: vi.fn(),
arc: vi.fn(),
fill: vi.fn(),
}))
vi.mock('codemirror', async (importOriginal) => {
const actual = await importOriginal()
return {
...actual,
fromTextArea: vi.fn(() => ({ setValue: () => {} })),
}
})
vi.mock('codemirror-editor-vue3', () => ({
defineSimpleMode: vi.fn(),
}))
describe('data dir working', () => {
let pinia
let router
beforeAll(async () => {
pinia = createPinia()
setActivePinia(pinia)
router = createRouter({
history: createWebHistory(),
routes,
})
const elem = document.createElement('div')
if (document.body) {
document.body.appendChild(elem)
}
global.document.createRange = vi.fn(() => ({
setEnd: vi.fn(),
setStart: vi.fn(),
getBoundingClientRect: vi.fn(() => ({
x: 0,
y: 0,
width: 0,
height: 0,
top: 0,
right: 0,
bottom: 0,
left: 0,
})),
getClientRects: vi.fn(() => ({
item: vi.fn(() => null),
length: 0,
[Symbol.iterator]: vi.fn(() => []),
})),
}))
global.globalScope = global.globalScope || {}
mount(simulator, {
global: {
plugins: [pinia, router, i18n, vuetify],
},
attachTo: elem,
})
setup()
})
// Open BitConvertor Dialog
test('bitConvertor Dialog working', () => {
expect(() => bitConverterDialog()).not.toThrow()
})
test('function setupBitConvertor working', () => {
expect(() => setupBitConvertor()).not.toThrow()
})
test('function setBaseValues working', () => {
const randomBaseValue = Math.floor(Math.random() * 100)
console.log('Testing for Base Value --> ', randomBaseValue)
expect(() => setBaseValues(randomBaseValue)).not.toThrow()
})
})