Skip to content

Commit bdd37b0

Browse files
committed
app.spec.js is finished. copyPaste.spec.js is in working condition
1 parent c9cf80b commit bdd37b0

File tree

2 files changed

+96
-47
lines changed

2 files changed

+96
-47
lines changed

test/jest/__tests__/App.spec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// import mutations from "../../../src/store/options/mutations";
66
import { setActivePinia, createPinia } from 'pinia'
77
import { useStore } from "src/store/main.js";
8-
const store = useStore();
8+
99

1010
/**
1111
* @description: Tests for deleting state
@@ -17,6 +17,10 @@ const store = useStore();
1717

1818
describe("Delete state/actions in userStore/componentMap", () => {
1919
beforeEach(() => {
20+
21+
setActivePinia(createPinia());
22+
const store = useStore();
23+
2024
store.componentMap = {
2125
testComp: {
2226
componentName: "test",

test/jest/__tests__/copyPaste.spec.js

Lines changed: 91 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,107 @@
1-
import { mount, shallowMount } from "@vue/test-utils";
1+
// import { mount, shallowMount } from "@vue/test-utils";
22
import { createApp } from "vue";
33
import * as All from "quasar";
4+
import { setActivePinia, createPinia } from 'pinia'
5+
import * as types from "../../../types";
6+
import { useStore } from "src/store/main.js";
7+
// import Vuex from "vuex";
48
const { Quasar, date } = All;
5-
import actions from "../../../src/store/options/actions";
6-
import mutations from "../../../src/store/options/mutations";
7-
import * as types from "../../../src/store/options/types";
8-
import Vuex from "vuex";
9+
// import actions from "../../../src/store/options/actions";
10+
// import mutations from "../../../src/store/options/mutations";
11+
// import * as types from "../../../src/store/options/types";
912

1013
describe("Tests for copy and pasting", () => {
1114
const App = {};
1215
const app = createApp(App);
13-
app.use(Quasar, Vuex);
14-
let state;
16+
const pinia = setActivePinia(createPinia());
17+
app.use(Quasar, pinia);
18+
// app.use(Quasar, Vuex);
19+
const store = useStore();
20+
// let state;
1521
beforeEach(() => {
16-
state = {
17-
componentMap: {
18-
testComp: {
19-
componentName: "testComp",
20-
children: [],
21-
htmlList: [],
22-
componentActions: [],
23-
state: ["state1", "state2"],
24-
actions: ["action1", "action2"],
25-
},
26-
},
27-
activeComponent: "test",
28-
userState: ["state1", "state2"],
29-
userActions: ["action1", "action2"],
30-
userProps: ["prop1", "prop2"],
31-
routes: {
32-
HomeView: [{ componentName: "testComp", parent: [] }],
33-
},
34-
activeRoute: "HomeView",
35-
pasteTimer: 0,
36-
};
37-
});
22+
store.componentMap = {
23+
testComp: {
24+
componentName: "testComp",
25+
children: [],
26+
htmlList: [],
27+
componentActions: [],
28+
state: ["state1", "state2"],
29+
actions: ["action1", "action2"],
30+
}
31+
};
32+
store.activeComponent = "test";
33+
store.userState = ["state1", "state2"];
34+
store.userActions = ["action1", "action2"];
35+
store.userProps = ["prop1", "prop2"];
36+
store.routes = {
37+
HomeView: [{ componentName: "testComp", parent: [] }]
38+
};
39+
store.activeRoute = "HomeView";
40+
store.pasteTimer = 0;
41+
});
42+
// state = {
43+
// componentMap: {
44+
// testComp: {
45+
// componentName: "testComp",
46+
// children: [],
47+
// htmlList: [],
48+
// componentActions: [],
49+
// state: ["state1", "state2"],
50+
// actions: ["action1", "action2"],
51+
// },
52+
// },
53+
// activeComponent: "test",
54+
// userState: ["state1", "state2"],
55+
// userActions: ["action1", "action2"],
56+
// userProps: ["prop1", "prop2"],
57+
// routes: {
58+
// HomeView: [{ componentName: "testComp", parent: [] }],
59+
// },
60+
// activeRoute: "HomeView",
61+
// pasteTimer: 0,
62+
// };
3863

39-
test('"[types.copyActiveComponent]" action to commit COPY_ACTIVE_COMPONENT', () => {
40-
const commit = jest.fn();
41-
actions[types.copyActiveComponent]({ commit });
42-
expect(commit).toHaveBeenCalledWith(types.COPY_ACTIVE_COMPONENT);
43-
});
4464

45-
test('"[types.COPY_ACTIVE_COMPONENT]" to update state successfully', () => {
46-
mutations[types.SET_ACTIVE_COMPONENT](state, "testComp");
47-
mutations[types.COPY_ACTIVE_COMPONENT](state);
48-
expect(state.copiedComponent.componentName).toBe("testComp");
65+
// test('"[types.copyActiveComponent]" action to commit COPY_ACTIVE_COMPONENT', () => {
66+
// const commit = jest.fn();
67+
// actions[types.copyActiveComponent]({ commit });
68+
// expect(commit).toHaveBeenCalledWith(types.COPY_ACTIVE_COMPONENT);
69+
// });
70+
71+
test('"function copyActiveComponent to update state successfully', () => {
72+
store.setActiveComponent("testComp");
73+
store.copyActiveComponent;
74+
expect(store.copiedComponent.componentName).toBe("testComp");
4975
});
5076

51-
test('"[types.PASTE_ACTIVE_COMPONENT]" to update state successfully', () => {
52-
mutations[types.SET_ACTIVE_COMPONENT](state, "testComp");
53-
mutations[types.COPY_ACTIVE_COMPONENT](state);
54-
mutations[types.PASTE_ACTIVE_COMPONENT](state);
55-
expect(Object.keys(state.componentMap).length).toBe(2);
77+
// test('"[types.COPY_ACTIVE_COMPONENT]" to update state successfully', () => {
78+
// mutations[types.SET_ACTIVE_COMPONENT](state, "testComp");
79+
// mutations[types.COPY_ACTIVE_COMPONENT](state);
80+
// expect(state.copiedComponent.componentName).toBe("testComp");
81+
// });
82+
83+
84+
test('"function pasteActiveComponent to update state successfully', () => {
85+
store.setActiveComponent("testComp");
86+
store.copyActiveComponent();
87+
store.pasteActiveComponent();
88+
expect(Object.keys(store.componentMap).length).toBe(2);
5689
});
5790

58-
test('"[types.PASTE_ACTIVE_COMPONENT]" to throttle via state paste timer', () => {
59-
mutations[types.UPDATE_PASTE_TIMER](state);
60-
expect(state.pasteTimer).not.toBe(0);
91+
// test('"[types.PASTE_ACTIVE_COMPONENT]" to update state successfully', () => {
92+
// mutations[types.SET_ACTIVE_COMPONENT](state, "testComp");
93+
// mutations[types.COPY_ACTIVE_COMPONENT](state);
94+
// mutations[types.PASTE_ACTIVE_COMPONENT](state);
95+
// expect(Object.keys(state.componentMap).length).toBe(2);
96+
// });
97+
98+
test('function pasteActiveComponent to throttle via state paste timer', () => {
99+
store.updatePasteTimer();
100+
expect(store.pasteTimer).not.toBe(0);
61101
});
102+
103+
// test('"[types.PASTE_ACTIVE_COMPONENT]" to throttle via state paste timer', () => {
104+
// mutations[types.UPDATE_PASTE_TIMER](state);
105+
// expect(state.pasteTimer).not.toBe(0);
106+
// });
62107
});

0 commit comments

Comments
 (0)