-
Notifications
You must be signed in to change notification settings - Fork 3
/
renderer.spec.js
143 lines (126 loc) · 5.05 KB
/
renderer.spec.js
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const RFExplorer = require('./scan_devices/rf_explorer.js');
const TinySA = require('./scan_devices/tiny_sa.js');
const electron = require('@electron/remote');
const renderer = require('./renderer.js')
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
describe('General', () => {
it('getFreqFromPercent()',() => {
global.START_FREQ = 80000000
global.STOP_FREQ = 90000000
expect(renderer.getFreqFromPercent(10)).toEqual(1000000)
});
it('move()', () => {
})
it('normalizeFreqString()',() => {
expect(renderer.normalizeFreqString('96,3')).toEqual(96300000);
expect(renderer.normalizeFreqString('96.3m')).toEqual(96300000);
expect(renderer.normalizeFreqString('96.3 M')).toEqual(96300000);
expect(renderer.normalizeFreqString('96,3Mhz')).toEqual(96300000);
expect(renderer.normalizeFreqString('96,3mhz')).toEqual(96300000);
expect(renderer.normalizeFreqString('96300k')).toEqual(96300000);
expect(renderer.normalizeFreqString('96300kHz')).toEqual(96300000);
expect(renderer.normalizeFreqString('96300KhZ')).toEqual(96300000);
expect(renderer.normalizeFreqString('96300000Hz')).toEqual(96300000);
expect(renderer.normalizeFreqString('96300000h')).toEqual(96300000);
expect(renderer.normalizeFreqString('ab96300kHz')).toEqual(false);
});
it('getBaudrate()', () => {
//jest.spyOn(app, 'getBaudrate');
global.SCAN_DEVICE = RFExplorer.HW_TYPE
expect(renderer.getBaudrate()).toEqual(RFExplorer.BAUD_RATE)
global.SCAN_DEVICE = TinySA.HW_TYPE
expect(renderer.getBaudrate()).toEqual(TinySA.BAUD_RATE)
//expect(app.relaunch).toHaveBeenCalled()
});
})
describe ('zoom() out', () => {
beforeEach( () => {
global.MIN_FREQ = 50 // 50 Hz
global.MAX_FREQ = 900 // 900 Hz
global.MIN_SPAN = 5 // 5 Hz
global.MAX_SPAN = 100 // 100 Hz
global.SWEEP_POINTS = 112
})
it('by 50% and exceed MAX_SPAN', () => {
global.START_FREQ = 100 // 100 Hz
global.STOP_FREQ = 180 // 180 Hz
renderer.zoom(-50) // Zoom out by 50%
expect(global.START_FREQ).toEqual(90)
expect(global.STOP_FREQ ).toEqual(190)
})
it('by 50% and exceed MAX_FREQ', () => {
global.START_FREQ = 880 // 880 Hz
global.STOP_FREQ = 900 // 900 Hz
renderer.zoom(-50) // Zoom out by 50%
expect(global.START_FREQ).toEqual(870)
expect(global.STOP_FREQ ).toEqual(900)
})
it('by 70% and exceed MIN_FREQ', () => {
global.START_FREQ = 60 // 60 Hz
global.STOP_FREQ = 100 // 100 Hz
renderer.zoom(-70) // Zoom out by 50%
expect(global.START_FREQ).toEqual(50)
expect(global.STOP_FREQ ).toEqual(118)
})
it('by 100% and exceed MAX_SPAN and MIN_FREQ', () => {
global.START_FREQ = 50 // 50 Hz
global.STOP_FREQ = 200 // 200 Hz
renderer.zoom(-100) // Zoom out by 100%
expect(global.START_FREQ).toEqual(75)
expect(global.STOP_FREQ ).toEqual(175)
})
});
describe ('zoom() in', () => {
beforeEach( () => {
global.MIN_FREQ = 50 // 50 Hz
global.MAX_FREQ = 900 // 900 Hz
global.MIN_SPAN = 20 // 20 Hz
global.MAX_SPAN = 100 // 100 Hz
global.SWEEP_POINTS = 112
})
it('by 50% and exceed MIN_SPAN and minimum SWEEP_POINTS', () => {
global.START_FREQ = 100 // 100 Hz
global.STOP_FREQ = 120 // 120 Hz
renderer.zoom(50) // Zoom in by 50%
expect(global.START_FREQ).toEqual(54)
expect(global.STOP_FREQ ).toEqual(166)
})
})
describe ('move()', () => {
beforeEach( () => {
global.MIN_FREQ = 50 // 50 Hz
global.MAX_FREQ = 900 // 900 Hz
global.MIN_SPAN = 20 // 20 Hz
global.MAX_SPAN = 100 // 100 Hz
global.SWEEP_POINTS = 112
})
it('left 10% within valid frequency range', () => {
global.START_FREQ = 100 // 100 Hz
global.STOP_FREQ = 120 // 120 Hz
renderer.move(-10) // Move left by 10%
expect(global.START_FREQ).toEqual(98)
expect(global.STOP_FREQ ).toEqual(118)
})
it('left 50% and exceed MIN_FREQ', () => {
global.START_FREQ = 60 // 100 Hz
global.STOP_FREQ = 120 // 120 Hz
renderer.move(-50) // Move left by 50%
expect(global.START_FREQ).toEqual(50)
expect(global.STOP_FREQ ).toEqual(110)
})
it('right 10% within valid frequency range', () => {
global.START_FREQ = 100 // 100 Hz
global.STOP_FREQ = 120 // 120 Hz
renderer.move(10) // Move right by 10%
expect(global.START_FREQ).toEqual(102)
expect(global.STOP_FREQ ).toEqual(122)
})
it('right 50% and exceed MAX_FREQ', () => {
global.START_FREQ = 770 // 770 Hz
global.STOP_FREQ = 870 // 870 Hz
renderer.move(50) // Move right by 50%
expect(global.START_FREQ).toEqual(800)
expect(global.STOP_FREQ ).toEqual(900)
})
})