Skip to content

Commit 751a2aa

Browse files
committed
Merge remote-tracking branches 'origin/fix/orthogonal-wire-routing' and 'origin/test/add-spec-file-mocks' into refactor/test-workspace-configuration
3 parents 1e6071b + 0bcff8b + 93ad29e commit 751a2aa

22 files changed

+1736
-1008
lines changed
Lines changed: 62 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,66 @@
1-
import { setup } from '../src/setup';
2-
import { bitConverterDialog, setBaseValues, setupBitConvertor } from '../src/utils';
3-
import { createPinia, setActivePinia } from 'pinia';
4-
import { mount } from '@vue/test-utils';
5-
import { createRouter, createWebHistory } from 'vue-router';
6-
import i18n from '#/locales/i18n';
7-
import { routes } from '#/router';
8-
import vuetify from '#/plugins/vuetify';
9-
import simulator from '#/pages/simulator.vue';
1+
import { setup } from '../src/setup'
2+
import {
3+
bitConverterDialog,
4+
setBaseValues,
5+
setupBitConvertor,
6+
} from '../src/utils'
7+
import { createPinia, setActivePinia } from 'pinia'
8+
import { mount } from '@vue/test-utils'
9+
import { createRouter, createWebHistory } from 'vue-router'
10+
import i18n from '#/locales/i18n'
11+
import { routes } from '#/router'
12+
import vuetify from '#/plugins/vuetify'
13+
import simulator from '#/pages/simulator.vue'
14+
import { describe, test, expect, vi, beforeAll } from 'vitest'
15+
16+
vi.mock('@tauri-apps/api/event', () => ({
17+
listen: vi.fn(() => Promise.resolve(() => {})),
18+
}))
19+
20+
global.ResizeObserver = vi.fn().mockImplementation(() => ({
21+
observe: vi.fn(),
22+
unobserve: vi.fn(),
23+
disconnect: vi.fn(),
24+
}))
25+
26+
HTMLCanvasElement.prototype.getContext = vi.fn(() => ({
27+
clearRect: vi.fn(),
28+
fillRect: vi.fn(),
29+
fillText: vi.fn(),
30+
strokeRect: vi.fn(),
31+
beginPath: vi.fn(),
32+
moveTo: vi.fn(),
33+
lineTo: vi.fn(),
34+
stroke: vi.fn(),
35+
closePath: vi.fn(),
36+
arc: vi.fn(),
37+
fill: vi.fn(),
38+
}))
1039

1140
vi.mock('codemirror', async (importOriginal) => {
12-
const actual = await importOriginal();
41+
const actual = await importOriginal()
1342
return {
1443
...actual,
15-
fromTextArea: vi.fn(() => ({ setValue: () => { } })),
16-
};
17-
});
44+
fromTextArea: vi.fn(() => ({ setValue: () => {} })),
45+
}
46+
})
1847

1948
vi.mock('codemirror-editor-vue3', () => ({
2049
defineSimpleMode: vi.fn(),
21-
}));
50+
}))
2251

2352
describe('data dir working', () => {
24-
let pinia;
25-
let router;
53+
let pinia
54+
let router
2655

2756
beforeAll(async () => {
28-
pinia = createPinia();
29-
setActivePinia(pinia);
57+
pinia = createPinia()
58+
setActivePinia(pinia)
3059

3160
router = createRouter({
3261
history: createWebHistory(),
3362
routes,
34-
});
63+
})
3564

3665
const elem = document.createElement('div')
3766

@@ -57,32 +86,32 @@ describe('data dir working', () => {
5786
length: 0,
5887
[Symbol.iterator]: vi.fn(() => []),
5988
})),
60-
}));
89+
}))
6190

62-
global.globalScope = global.globalScope || {};
91+
global.globalScope = global.globalScope || {}
6392

6493
mount(simulator, {
6594
global: {
6695
plugins: [pinia, router, i18n, vuetify],
6796
},
6897
attachTo: elem,
69-
});
98+
})
7099

71-
setup();
72-
});
100+
setup()
101+
})
73102

74103
// Open BitConvertor Dialog
75104
test('bitConvertor Dialog working', () => {
76-
expect(() => bitConverterDialog()).not.toThrow();
77-
});
105+
expect(() => bitConverterDialog()).not.toThrow()
106+
})
78107

79108
test('function setupBitConvertor working', () => {
80-
expect(() => setupBitConvertor()).not.toThrow();
81-
});
109+
expect(() => setupBitConvertor()).not.toThrow()
110+
})
82111

83112
test('function setBaseValues working', () => {
84-
const randomBaseValue = Math.floor(Math.random() * 100);
85-
console.log('Testing for Base Value --> ', randomBaseValue);
86-
expect(() => setBaseValues(randomBaseValue)).not.toThrow();
87-
});
88-
});
113+
const randomBaseValue = Math.floor(Math.random() * 100)
114+
console.log('Testing for Base Value --> ', randomBaseValue)
115+
expect(() => setBaseValues(randomBaseValue)).not.toThrow()
116+
})
117+
})
Lines changed: 68 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,67 @@
1-
import { setup } from '../src/setup';
2-
import { runAll } from '../src/testbench';
3-
import testData from './testData/gates-testdata.json';
4-
import { GenerateCircuit, performCombinationalAnalysis } from '../src/combinationalAnalysis';
5-
import { createPinia, setActivePinia } from 'pinia';
6-
import { mount } from '@vue/test-utils';
7-
import { createRouter, createWebHistory } from 'vue-router';
8-
import i18n from '#/locales/i18n';
9-
import { routes } from '#/router';
10-
import vuetify from '#/plugins/vuetify';
11-
import simulator from '#/pages/simulator.vue';
1+
import { setup } from '../src/setup'
2+
import { runAll } from '../src/testbench'
3+
import testData from './testData/gates-testdata.json'
4+
import {
5+
GenerateCircuit,
6+
performCombinationalAnalysis,
7+
} from '../src/combinationalAnalysis'
8+
import { createPinia, setActivePinia } from 'pinia'
9+
import { mount } from '@vue/test-utils'
10+
import { createRouter, createWebHistory } from 'vue-router'
11+
import i18n from '#/locales/i18n'
12+
import { routes } from '#/router'
13+
import vuetify from '#/plugins/vuetify'
14+
import simulator from '#/pages/simulator.vue'
15+
import { describe, test, expect, vi, beforeAll } from 'vitest'
16+
17+
vi.mock('@tauri-apps/api/event', () => ({
18+
listen: vi.fn(() => Promise.resolve(() => {})),
19+
}))
20+
21+
global.ResizeObserver = vi.fn().mockImplementation(() => ({
22+
observe: vi.fn(),
23+
unobserve: vi.fn(),
24+
disconnect: vi.fn(),
25+
}))
26+
27+
HTMLCanvasElement.prototype.getContext = vi.fn(() => ({
28+
clearRect: vi.fn(),
29+
fillRect: vi.fn(),
30+
fillText: vi.fn(),
31+
strokeRect: vi.fn(),
32+
beginPath: vi.fn(),
33+
moveTo: vi.fn(),
34+
lineTo: vi.fn(),
35+
stroke: vi.fn(),
36+
closePath: vi.fn(),
37+
arc: vi.fn(),
38+
fill: vi.fn(),
39+
}))
1240

1341
vi.mock('codemirror', async (importOriginal) => {
14-
const actual = await importOriginal();
42+
const actual = await importOriginal()
1543
return {
1644
...actual,
17-
fromTextArea: vi.fn(() => ({ setValue: () => { } })),
18-
};
19-
});
45+
fromTextArea: vi.fn(() => ({ setValue: () => {} })),
46+
}
47+
})
2048

2149
vi.mock('codemirror-editor-vue3', () => ({
2250
defineSimpleMode: vi.fn(),
23-
}));
51+
}))
2452

2553
describe('Combinational Analysis Testing', () => {
26-
let pinia;
27-
let router;
54+
let pinia
55+
let router
2856

2957
beforeAll(async () => {
30-
pinia = createPinia();
31-
setActivePinia(pinia);
58+
pinia = createPinia()
59+
setActivePinia(pinia)
3260

3361
router = createRouter({
3462
history: createWebHistory(),
3563
routes,
36-
});
64+
})
3765

3866
const elem = document.createElement('div')
3967

@@ -59,34 +87,36 @@ describe('Combinational Analysis Testing', () => {
5987
length: 0,
6088
[Symbol.iterator]: vi.fn(() => []),
6189
})),
62-
}));
90+
}))
6391

64-
global.globalScope = global.globalScope || {};
92+
global.globalScope = global.globalScope || {}
6593

6694
mount(simulator, {
6795
global: {
6896
plugins: [pinia, router, i18n, vuetify],
6997
},
7098
attachTo: elem,
71-
});
99+
})
72100

73-
setup();
74-
});
101+
setup()
102+
})
75103

76104
test('performCombinationalAnalysis function working', () => {
77-
expect(() => performCombinationalAnalysis('', '', 'AB')).not.toThrow();
78-
});
105+
expect(() => performCombinationalAnalysis('', '', 'AB')).not.toThrow()
106+
})
79107

80108
test('Generating Circuit', () => {
81-
expect(() => GenerateCircuit([13], ['A', 'B'], [0, 0, 0, 1], 'AB')).not.toThrow();
82-
});
109+
expect(() =>
110+
GenerateCircuit([13], ['A', 'B'], [0, 0, 0, 1], 'AB')
111+
).not.toThrow()
112+
})
83113

84114
test('testing Combinational circuit', () => {
85-
testData.AndGate.groups[0].inputs[0].label = 'A';
86-
testData.AndGate.groups[0].inputs[1].label = 'B';
87-
testData.AndGate.groups[0].outputs[0].label = 'AB';
88-
89-
const result = runAll(testData.AndGate);
90-
expect(result.summary.passed).toBe(3);
91-
});
92-
});
115+
testData.AndGate.groups[0].inputs[0].label = 'A'
116+
testData.AndGate.groups[0].inputs[1].label = 'B'
117+
testData.AndGate.groups[0].outputs[0].label = 'AB'
118+
119+
const result = runAll(testData.AndGate)
120+
expect(result.summary.passed).toBe(3)
121+
})
122+
})

0 commit comments

Comments
 (0)