3
3
* @jest -environment jsdom
4
4
*/
5
5
// import { mount, createLocalVue, shallowMount } from "@vue/test-utils";
6
- import { mount , shallowMount } from "@vue/test-utils" ;
6
+ // import { mount, shallowMount } from "@vue/test-utils";
7
7
import { createApp } from "vue" ;
8
8
import * as All from "quasar" ;
9
9
const { Quasar, date } = All ;
@@ -16,11 +16,15 @@ const components = Object.keys(All).reduce((object, key) => {
16
16
return object ;
17
17
} , { } ) ;
18
18
19
- import actions from "../../../src/store/options/actions" ;
20
- import mutations from "../../../src/store/options/mutations" ;
21
- import * as types from "../../../src/store/options/types" ;
22
- import Vuex from "vuex" ;
23
- import store from "../../../src/store/state/index" ;
19
+ // import actions from "../../../src/store/options/actions";
20
+ // import mutations from "../../../src/store/options/mutations";
21
+ // import * as types from "../../../src/store/options/types";
22
+ // import Vuex from "vuex";
23
+ // import store from "../../../src/store/state/index";
24
+ import { setActivePinia , createPinia } from 'pinia'
25
+ import * as types from "../../../types" ;
26
+ import { useStore } from "src/store/main.js" ;
27
+
24
28
25
29
/**
26
30
* @description : Testing functionality of route actions and mutations
@@ -34,116 +38,180 @@ describe("Test Suite for route actions and related mutations", () => {
34
38
// localVue.use(Quasar, Vuex, { components });
35
39
const App = { } ;
36
40
const app = createApp ( App ) ;
37
- app . use ( Quasar , Vuex , { components } ) ;
38
- const state = { ...store } ;
39
-
40
- test ( '"[types.addRouteToRouteMap]" action to commit 4 mutations' , ( ) => {
41
- const commit = jest . fn ( ) ;
41
+ const pinia = setActivePinia ( createPinia ( ) ) ;
42
+ app . use ( Quasar , pinia , { components } ) ;
43
+ const store = useStore ( ) ;
44
+ // const state = { ...store };
45
+
46
+ // test('"[types.addRouteToRouteMap]" action to commit 4 mutations', () => {
47
+ // const commit = jest.fn();
48
+ // const payload = "testRoute";
49
+ // actions[types.addRouteToRouteMap]({ state, commit }, payload);
50
+ // expect(commit).toHaveBeenCalledWith(types.ADD_ROUTE, payload);
51
+ // expect(commit).toHaveBeenCalledWith(types.SET_ACTIVE_ROUTE, payload);
52
+ // expect(commit).toHaveBeenCalledWith(types.ADD_ROUTE_TO_COMPONENT_MAP, {
53
+ // route: state.activeRoute,
54
+ // children: [],
55
+ // });
56
+ // expect(commit).toHaveBeenCalledWith(
57
+ // types.ADD_COMPONENT_TO_COMPONENT_CHILDREN,
58
+ // {
59
+ // component: "App",
60
+ // value: state.componentMap[state.activeRoute].componentName,
61
+ // }
62
+ // );
63
+ // });
64
+
65
+ // test('"[types.setActiveRoute]" action to commit SET_ACTIVE_ROUTE mutation with string payload', () => {
66
+ // const commit = jest.fn();
67
+ // const payload = "HomeView";
68
+ // actions[types.setActiveRoute]({ state, commit }, payload);
69
+ // expect(commit).toHaveBeenCalledWith(types.SET_ACTIVE_ROUTE, payload);
70
+ // });
71
+
72
+ // test('"[types.deleteRoute]" action to commit DELETE_ROUTE mutation with string payload', () => {
73
+ // const commit = jest.fn();
74
+ // const payload = "HomeView";
75
+ // actions[types.deleteRoute]({ state, commit }, payload);
76
+ // expect(commit).toHaveBeenCalledWith(types.DELETE_ROUTE, payload);
77
+ // });
78
+
79
+ test ( 'addRoute function to add new route and set route imagePath to default' , ( ) => {
42
80
const payload = "testRoute" ;
43
- actions [ types . addRouteToRouteMap ] ( { state, commit } , payload ) ;
44
- expect ( commit ) . toHaveBeenCalledWith ( types . ADD_ROUTE , payload ) ;
45
- expect ( commit ) . toHaveBeenCalledWith ( types . SET_ACTIVE_ROUTE , payload ) ;
46
- expect ( commit ) . toHaveBeenCalledWith ( types . ADD_ROUTE_TO_COMPONENT_MAP , {
47
- route : state . activeRoute ,
48
- children : [ ] ,
49
- } ) ;
50
- expect ( commit ) . toHaveBeenCalledWith (
51
- types . ADD_COMPONENT_TO_COMPONENT_CHILDREN ,
52
- {
53
- component : "App" ,
54
- value : state . componentMap [ state . activeRoute ] . componentName ,
55
- }
56
- ) ;
81
+ store . addRoute ( payload ) ;
82
+ expect ( store . routes ) . toMatchObject ( { HomeView : [ ] , [ payload ] : [ ] } ) ;
57
83
} ) ;
58
84
59
- test ( '"[types.setActiveRoute]" action to commit SET_ACTIVE_ROUTE mutation with string payload' , ( ) => {
60
- const commit = jest . fn ( ) ;
61
- const payload = "HomeView" ;
62
- actions [ types . setActiveRoute ] ( { state, commit } , payload ) ;
63
- expect ( commit ) . toHaveBeenCalledWith ( types . SET_ACTIVE_ROUTE , payload ) ;
64
- } ) ;
65
-
66
- test ( '"[types.deleteRoute]" action to commit DELETE_ROUTE mutation with string payload' , ( ) => {
67
- const commit = jest . fn ( ) ;
68
- const payload = "HomeView" ;
69
- actions [ types . deleteRoute ] ( { state, commit } , payload ) ;
70
- expect ( commit ) . toHaveBeenCalledWith ( types . DELETE_ROUTE , payload ) ;
71
- } ) ;
72
-
73
- test ( '"[types.ADD_ROUTE]" mutation to add new route and set route imagePath to default' , ( ) => {
74
- const payload = "testRoute" ;
75
- mutations [ types . ADD_ROUTE ] ( state , payload ) ;
76
- expect ( state . routes ) . toMatchObject ( { HomeView : [ ] , [ payload ] : [ ] } ) ;
77
- } ) ;
85
+ // test('"[types.ADD_ROUTE]" mutation to add new route and set route imagePath to default', () => {
86
+ // const payload = "testRoute";
87
+ // mutations[types.ADD_ROUTE](state, payload);
88
+ // expect(state.routes).toMatchObject({ HomeView: [], [payload]: [] });
89
+ // });
78
90
79
- test ( '"[types.SET_ACTIVE_ROUTE]" mutation to ---' , ( ) => {
91
+ test ( 'setActiveRoute funtion to ---' , ( ) => {
80
92
const payload = "testRoute" ;
81
93
82
94
// expect at test start for there to be two routes and HomeView to be active Route
83
- expect ( state . routes ) . toMatchObject ( { HomeView : [ ] , [ payload ] : [ ] } ) ;
84
- expect ( state . activeRoute ) . toBe ( "HomeView" ) ;
95
+ expect ( store . routes ) . toMatchObject ( { HomeView : [ ] , [ payload ] : [ ] } ) ;
96
+ expect ( store . activeRoute ) . toBe ( "HomeView" ) ;
85
97
86
98
// start test
87
- mutations [ types . SET_ACTIVE_ROUTE ] ( state , payload ) ;
88
- expect ( state . activeRoute ) . toBe ( payload ) ;
99
+ store . setActiveRoute ( payload ) ;
100
+ expect ( store . activeRoute ) . toBe ( payload ) ;
89
101
} ) ;
90
102
91
- test ( '"[types.ADD_ROUTE_TO_COMPONENT_MAP]" mutation to add route object containing 3 keys to state.componentMap' , ( ) => {
92
- expect ( Object . keys ( state . componentMap ) . length ) . toBe ( 2 ) ;
93
- mutations [ types . ADD_ROUTE_TO_COMPONENT_MAP ] ( state , {
94
- route : state . activeRoute ,
103
+
104
+ // test('"[types.SET_ACTIVE_ROUTE]" mutation to ---', () => {
105
+ // const payload = "testRoute";
106
+
107
+ // // expect at test start for there to be two routes and HomeView to be active Route
108
+ // expect(state.routes).toMatchObject({ HomeView: [], [payload]: [] });
109
+ // expect(state.activeRoute).toBe("HomeView");
110
+
111
+ // // start test
112
+ // mutations[types.SET_ACTIVE_ROUTE](state, payload);
113
+ // expect(state.activeRoute).toBe(payload);
114
+ // });
115
+
116
+ test ( 'addRouteToComponentMap function to add route object containing 3 keys to store.componentMap' , ( ) => {
117
+ expect ( Object . keys ( store . componentMap ) . length ) . toBe ( 2 ) ;
118
+ store . addRouteToComponentMap ( {
119
+ route : store . activeRoute ,
95
120
children : [ ] ,
96
121
} ) ;
97
- expect ( Object . keys ( state . componentMap ) . length ) . toBe ( 3 ) ;
122
+ expect ( Object . keys ( store . componentMap ) . length ) . toBe ( 3 ) ;
98
123
// to contain componentName, children, and htmlList keys
99
- expect ( Object . keys ( state . componentMap [ state . activeRoute ] ) ) . toMatchObject ( [
124
+ expect ( Object . keys ( store . componentMap [ store . activeRoute ] ) ) . toMatchObject ( [
100
125
"componentName" ,
101
126
"children" ,
102
127
"htmlList" ,
103
128
] ) ;
104
129
} ) ;
105
130
106
- test ( '"[types.ADD_COMPONENT_TO_COMPONENT_CHILDREN]" mutation to add created route as one of Apps children' , ( ) => {
107
- let component = "App" ;
108
- let value = state . componentMap [ state . activeRoute ] . componentName ;
109
- expect ( state . componentMap [ component ] . children . length ) . toBe ( 1 ) ;
110
- mutations [ types . ADD_COMPONENT_TO_COMPONENT_CHILDREN ] ( state , {
111
- component,
112
- value,
113
- } ) ;
114
- expect ( state . componentMap [ component ] . children . length ) . toBe ( 2 ) ;
115
- expect (
116
- state . componentMap [ component ] . children [
117
- state . componentMap [ component ] . children . length - 1
118
- ]
119
- ) . toBe ( value ) ;
120
- } ) ;
121
-
122
- test ( '"[types.DELETE_ROUTE]" mutation to update state by removing a route' , ( ) => {
131
+ // test('"[types.ADD_ROUTE_TO_COMPONENT_MAP]" mutation to add route object containing 3 keys to state.componentMap', () => {
132
+ // expect(Object.keys(state.componentMap).length).toBe(2);
133
+ // mutations[types.ADD_ROUTE_TO_COMPONENT_MAP](state, {
134
+ // route: state.activeRoute,
135
+ // children: [],
136
+ // });
137
+ // expect(Object.keys(state.componentMap).length).toBe(3);
138
+ // // to contain componentName, children, and htmlList keys
139
+ // expect(Object.keys(state.componentMap[state.activeRoute])).toMatchObject([
140
+ // "componentName",
141
+ // "children",
142
+ // "htmlList",
143
+ // ]);
144
+ // });
145
+
146
+ // test('"[types.ADD_COMPONENT_TO_COMPONENT_CHILDREN]" mutation to add created route as one of Apps children', () => {
147
+ // let component = "App";
148
+ // let value = state.componentMap[state.activeRoute].componentName;
149
+ // expect(state.componentMap[component].children.length).toBe(1);
150
+ // mutations[types.ADD_COMPONENT_TO_COMPONENT_CHILDREN](state, {
151
+ // component,
152
+ // value,
153
+ // });
154
+ // expect(state.componentMap[component].children.length).toBe(2);
155
+ // expect(
156
+ // state.componentMap[component].children[
157
+ // state.componentMap[component].children.length - 1
158
+ // ]
159
+ // ).toBe(value);
160
+ // });
161
+
162
+ test ( '"function deleteRoute to update state by removing a route' , ( ) => {
123
163
const payload = "testRoute" ;
124
164
let flag = false ;
125
165
// pre mutation tests
126
- expect ( state . routes [ payload ] ) . not . toBe ( undefined ) ;
127
- expect ( state . componentMap [ payload ] ) . not . toBe ( undefined ) ;
128
- expect ( state . imagePath [ payload ] ) . not . toBe ( undefined ) ;
129
- if ( state . activeRoute === payload ) {
166
+ expect ( store . routes [ payload ] ) . not . toBe ( undefined ) ;
167
+ expect ( store . componentMap [ payload ] ) . not . toBe ( undefined ) ;
168
+ expect ( store . imagePath [ payload ] ) . not . toBe ( undefined ) ;
169
+ if ( store . activeRoute === payload ) {
130
170
flag = true ;
131
171
}
132
- mutations [ types . DELETE_ROUTE ] ( state , payload ) ;
172
+ store . deleteRoute ( payload ) ;
133
173
134
174
// post mutation tests
135
- expect ( state . routes [ payload ] ) . toBe ( undefined ) ;
136
- expect ( state . componentMap [ payload ] ) . toBe ( undefined ) ;
137
- expect ( state . imagePath [ payload ] ) . toBe ( undefined ) ;
175
+ expect ( store . routes [ payload ] ) . toBe ( undefined ) ;
176
+ expect ( store . componentMap [ payload ] ) . toBe ( undefined ) ;
177
+ expect ( store . imagePath [ payload ] ) . toBe ( undefined ) ;
138
178
if ( flag ) {
139
- expect ( state . activeRoute ) . not . toBe ( payload ) ;
179
+ expect ( store . activeRoute ) . not . toBe ( payload ) ;
140
180
}
141
181
} ) ;
142
182
143
- test ( '"[types.SET_ACTIVE_ROUTE_ARRAY]" mutation to set state.routes[state.activeRoute] to newActiveRouteArray' , ( ) => {
183
+ // test('"[types.DELETE_ROUTE]" mutation to update state by removing a route', () => {
184
+ // const payload = "testRoute";
185
+ // let flag = false;
186
+ // // pre mutation tests
187
+ // expect(state.routes[payload]).not.toBe(undefined);
188
+ // expect(state.componentMap[payload]).not.toBe(undefined);
189
+ // expect(state.imagePath[payload]).not.toBe(undefined);
190
+ // if (state.activeRoute === payload) {
191
+ // flag = true;
192
+ // }
193
+ // mutations[types.DELETE_ROUTE](state, payload);
194
+
195
+ // // post mutation tests
196
+ // expect(state.routes[payload]).toBe(undefined);
197
+ // expect(state.componentMap[payload]).toBe(undefined);
198
+ // expect(state.imagePath[payload]).toBe(undefined);
199
+ // if (flag) {
200
+ // expect(state.activeRoute).not.toBe(payload);
201
+ // }
202
+ // });
203
+
204
+ test ( 'setActiveRouteArray function to set store.routes[store.activeRoute] to newActiveRouteArray' , ( ) => {
144
205
// invoked by delete active component action
145
- const newActiveRouteArray = state . routes [ state . activeRoute ] ;
146
- mutations [ types . SET_ACTIVE_ROUTE_ARRAY ] ( state , newActiveRouteArray ) ;
147
- expect ( state . routes [ state . activeRoute ] ) . toBe ( newActiveRouteArray ) ;
206
+ const newActiveRouteArray = store . routes [ store . activeRoute ] ;
207
+ store . setActiveRouteArray ( newActiveRouteArray ) ;
208
+ expect ( store . routes [ store . activeRoute ] ) . toBe ( newActiveRouteArray ) ;
148
209
} ) ;
210
+
211
+ // test('"[types.SET_ACTIVE_ROUTE_ARRAY]" mutation to set state.routes[state.activeRoute] to newActiveRouteArray', () => {
212
+ // // invoked by delete active component action
213
+ // const newActiveRouteArray = state.routes[state.activeRoute];
214
+ // mutations[types.SET_ACTIVE_ROUTE_ARRAY](state, newActiveRouteArray);
215
+ // expect(state.routes[state.activeRoute]).toBe(newActiveRouteArray);
216
+ // });
149
217
} ) ;
0 commit comments