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
1341vi . 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
2149vi . mock ( 'codemirror-editor-vue3' , ( ) => ( {
2250 defineSimpleMode : vi . fn ( ) ,
23- } ) ) ;
51+ } ) )
2452
2553describe ( '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