Skip to content

Commit dc6a287

Browse files
authored
Merge pull request #147 from open-source-labs/bryan/testRefactorTwo
Bryan/test refactor two
2 parents fc8882e + 2561b0c commit dc6a287

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

src/store/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const actions = {
100100

101101
// copy the active component
102102
[types.copyActiveComponent]: ({ commit }, payload) => {
103-
commit(types.COPY_ACTIVE_COMPONENT, payload);
103+
commit(types.COPY_ACTIVE_COMPONENT);
104104
},
105105
// paste the active component copy
106106
[types.pasteActiveComponent]: ({ commit, state }) => {

src/store/mutations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ const mutations = {
248248
state.userActions.splice(index, 1);
249249
},
250250
// copy and paste functionality
251-
[types.COPY_ACTIVE_COMPONENT]: (state, payload) => {
251+
[types.COPY_ACTIVE_COMPONENT]: (state) => {
252252
// copy activeComponentObj and place in the state but without children
253253
const copy = { ...state.activeComponentObj };
254254
// copy.componentName;

test/jest/__tests__/copyPaste.spec.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { mount, shallowMount } from "@vue/test-utils";
2+
import { createApp } from "vue";
3+
import * as All from "quasar";
4+
const { Quasar, date } = All;
5+
import actions from "../../../src/store/actions";
6+
import mutations from "../../../src/store/mutations";
7+
import * as types from "../../../src/store/types";
8+
import Vuex from "vuex";
9+
10+
describe("Tests for copy and pasting", () => {
11+
const App = {}
12+
const app = createApp(App);
13+
app.use(Quasar, Vuex);
14+
let state;
15+
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+
});
38+
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+
});
44+
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');
49+
})
50+
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);
56+
});
57+
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);
61+
});
62+
63+
});

test/jest/__tests__/routeTests.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,14 @@ describe("Test Suite for route actions and related mutations", () => {
9393
test('"[types.ADD_COMPONENT_TO_COMPONENT_CHILDREN]" mutation to add created route as one of Apps children', () => {
9494
let component = 'App';
9595
let value = state.componentMap[state.activeRoute].componentName;
96-
// console.log('pre: ', state.componentMap[component].children);
9796
expect(state.componentMap[component].children.length).toBe(1);
9897
mutations[types.ADD_COMPONENT_TO_COMPONENT_CHILDREN](state, {component, value});
99-
// console.log('post: ', state.componentMap[component].children);
10098
expect(state.componentMap[component].children.length).toBe(2);
10199
expect(state.componentMap[component].children[state.componentMap[component].children.length-1]).toBe(value);
102100

103101
});
104102

105-
test('"[types.DELETE_ROUTE]" mutation to ---', () => {
103+
test('"[types.DELETE_ROUTE]" mutation to update state by removing a route', () => {
106104
const payload = 'testRoute';
107105
let flag = false;
108106
// pre mutation tests

0 commit comments

Comments
 (0)