Skip to content

Commit 2be964d

Browse files
committed
Merge branch 'linden-testing' into typescript
2 parents 897f087 + 91f32d2 commit 2be964d

File tree

1 file changed

+77
-26
lines changed

1 file changed

+77
-26
lines changed

test/jest/__tests__/openProject.spec.js

Lines changed: 77 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
// * = added to convert tests to OverVue 9.0, using Pinia instead of Vuex
12
import { mount, createLocalVue, shallowMount } from "@vue/test-utils";
23
import { createApp } from "vue";
34
import * as All from "quasar";
45
const { Quasar, date } = All;
56

7+
import { createTestingPinia } from "@pinia/testing"; // *
8+
import { useStore } from "../../src/store/main"; // *
9+
const piniaStore = useStore(); // *
10+
611
const components = Object.keys(All).reduce((object, key) => {
712
const val = All[key];
813
if (val && val.component && val.component.name != null) {
@@ -11,11 +16,11 @@ const components = Object.keys(All).reduce((object, key) => {
1116
return object;
1217
}, {});
1318

14-
import actions from "../../../src/store/options/actions";
15-
import mutations from "../../../src/store/options/mutations";
19+
// import actions from "../../../src/store/options/actions";
20+
// import mutations from "../../../src/store/options/mutations";
1621
import * as types from "../../../src/store/options/types";
17-
import Vuex from "vuex";
18-
import store from "../../../src/store/state/index";
22+
// import Vuex from "vuex";
23+
// import store from "../../../src/store/state/index";
1924

2025
/**
2126
* @description: Testing functionality of the openProject action and following mutations
@@ -27,7 +32,8 @@ import store from "../../../src/store/state/index";
2732
describe("Test Suite for Image Upload", () => {
2833
const App = {};
2934
const app = createApp(App);
30-
app.use(Quasar, Vuex, { components });
35+
app.use(Quasar, piniaStore, { components }); // *
36+
// app.use(Quasar, Vuex, { components });
3137
const payload = {
3238
icons: {
3339
div: "far fa-square fa-lg",
@@ -113,32 +119,46 @@ describe("Test Suite for Image Upload", () => {
113119
imagePath: { HomeView: "/Users/joju/Desktop/bootstrap1.png", b: "" },
114120
};
115121

116-
test('"[types.openProject]" action calls set_image_path, set_component_map, and set_routes', () => {
117-
const commit = jest.fn();
118-
actions[types.openProject]({ commit }, payload);
119-
expect(commit).toHaveBeenCalledWith("SET_IMAGE_PATH", payload.imagePath);
120-
expect(commit).toHaveBeenCalledWith(
121-
"SET_COMPONENT_MAP",
122-
payload.componentMap
123-
);
124-
expect(commit).toHaveBeenCalledWith("SET_ROUTES", payload.routes);
125-
expect(commit).toHaveBeenCalledWith("REMOVE_ALL_STATE_PROPS_ACTIONS");
126-
expect(commit).toHaveBeenCalledWith("SET_ACTIVE_ROUTE", "HomeView");
127-
expect(commit).toHaveBeenCalledWith("SET_ACTIVE_COMPONENT", "");
128-
});
122+
// test('"[types.openProject]" action calls set_image_path, set_component_map, and set_routes', () => {
123+
// const commit = jest.fn();
124+
// actions[types.openProject]({ commit }, payload);
125+
// expect(commit).toHaveBeenCalledWith("SET_IMAGE_PATH", payload.imagePath);
126+
// expect(commit).toHaveBeenCalledWith(
127+
// "SET_COMPONENT_MAP",
128+
// payload.componentMap
129+
// );
130+
// expect(commit).toHaveBeenCalledWith("SET_ROUTES", payload.routes);
131+
// expect(commit).toHaveBeenCalledWith("REMOVE_ALL_STATE_PROPS_ACTIONS");
132+
// expect(commit).toHaveBeenCalledWith("SET_ACTIVE_ROUTE", "HomeView");
133+
// expect(commit).toHaveBeenCalledWith("SET_ACTIVE_COMPONENT", "");
134+
// });
129135

130136
test('"[types.SET_IMAGE_PATH]" mutation expect add payload to imagePath object in state', () => {
131137
const openState = {
132138
imagePath: {
133139
HomeView: "",
134140
},
135141
};
136-
mutations[types.SET_IMAGE_PATH](openState, payload.imagePath);
137-
expect(openState.imagePath).toMatchObject({
142+
piniaStore.setImagePath(payload.imagePath);
143+
expect(piniaStore.imagePath).toMatchObject({
138144
...openState.imagePath,
139145
...payload.imagePath,
140146
});
141147
});
148+
149+
// test('"[types.SET_IMAGE_PATH]" mutation expect add payload to imagePath object in state', () => {
150+
// const openState = {
151+
// imagePath: {
152+
// HomeView: "",
153+
// },
154+
// };
155+
// mutations[types.SET_IMAGE_PATH](openState, payload.imagePath);
156+
// expect(openState.imagePath).toMatchObject({
157+
// ...openState.imagePath,
158+
// ...payload.imagePath,
159+
// });
160+
// });
161+
142162
test('"[types.SET_COMPONENT_MAP]" mutation expect state.componentMap object to match payload.componentMap', () => {
143163
const openState = {
144164
componentMap: {
@@ -154,17 +174,48 @@ describe("Test Suite for Image Upload", () => {
154174
},
155175
},
156176
};
157-
mutations[types.SET_COMPONENT_MAP](openState, payload.componentMap);
158-
expect(openState.componentMap).toMatchObject(payload.componentMap);
177+
piniaStore.setComponentMap(payload.componentMap);
178+
expect(piniaStore.componentMap).toMatchObject(payload.componentMap);
159179
});
180+
181+
// test('"[types.SET_COMPONENT_MAP]" mutation expect state.componentMap object to match payload.componentMap', () => {
182+
// const openState = {
183+
// componentMap: {
184+
// App: {
185+
// componentName: "App",
186+
// children: ["HomeView"],
187+
// htmlList: [],
188+
// },
189+
// HomeView: {
190+
// componentName: "HomeView",
191+
// children: [],
192+
// htmlList: [],
193+
// },
194+
// },
195+
// };
196+
// mutations[types.SET_COMPONENT_MAP](openState, payload.componentMap);
197+
// expect(openState.componentMap).toMatchObject(payload.componentMap);
198+
// });
199+
160200
test('"[types.SET_ROUTES]" mutation expect state.routes object to match payload.routes ', () => {
161201
const openState = {
162202
routes: {
163203
HomeView: [],
164204
},
165205
};
166-
167-
mutations[types.SET_ROUTES](openState, payload.routes);
168-
expect(openState.routes).toMatchObject(payload.routes);
206+
piniaStore.setRoutes(payload.routes);
207+
expect(piniaStore.routes).toMatchObject(payload.routes);
169208
});
170-
});
209+
210+
// test('"[types.SET_ROUTES]" mutation expect state.routes object to match payload.routes ', () => {
211+
// const openState = {
212+
// routes: {
213+
// HomeView: [],
214+
// },
215+
// };
216+
217+
// mutations[types.SET_ROUTES](openState, payload.routes);
218+
// expect(openState.routes).toMatchObject(payload.routes);
219+
// });
220+
221+
});

0 commit comments

Comments
 (0)