Skip to content

Commit 2561b0c

Browse files
committed
additional testing for copy and paste functionality not implemented previously.
1 parent d25e619 commit 2561b0c

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
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: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,58 @@ import actions from "../../../src/store/actions";
66
import mutations from "../../../src/store/mutations";
77
import * as types from "../../../src/store/types";
88
import Vuex from "vuex";
9-
import store from "../../../src/store/state/index";
109

1110
describe("Tests for copy and pasting", () => {
1211
const App = {}
1312
const app = createApp(App);
1413
app.use(Quasar, Vuex);
15-
const state = { ...store }
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+
});
1638

1739
test('"[types.copyActiveComponent]" action to commit COPY_ACTIVE_COMPONENT', () => {
1840
const commit = jest.fn();
19-
actions[types.copyActiveComponent]({ commit }, {});
20-
expect(commit).toHaveBeenCalledWith(types.COPY_ACTIVE_COMPONENT, {});
41+
actions[types.copyActiveComponent]({ commit });
42+
expect(commit).toHaveBeenCalledWith(types.COPY_ACTIVE_COMPONENT);
2143
});
22-
test('"[types.pasteActiveComponent]" action to commit PASTE_ACTIVE_COMPONENT', () => {
23-
const commit = jest.fn();
24-
actions[types.pasteActiveComponent]({ commit }, {});
25-
expect(commit).toHaveBeenCalledWith(types.PASTE_ACTIVE_COMPONENT, {});
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);
2656
});
2757

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+
});
2862

2963
});

0 commit comments

Comments
 (0)