Skip to content

Commit 8f47f01

Browse files
committed
Fixed some tests that were broken from changes to actions and mutations. Added tests for note functionality, typescript export and some other new actions and types
1 parent 9f0eb33 commit 8f47f01

File tree

6 files changed

+138
-208
lines changed

6 files changed

+138
-208
lines changed

src/store/actions.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const actions = {
164164
[types.setActiveRoute]: ({ state, commit }, payload) => {
165165
if (state.routes[payload].length === 0){
166166
commit(types.SET_ACTIVE_COMPONENT, '');
167-
}
167+
}
168168
commit(types.SET_ACTIVE_ROUTE, payload);
169169
},
170170

@@ -297,7 +297,7 @@ const actions = {
297297

298298
// Loading ///////////////////////////////////////////////////////
299299

300-
[types.openProject]: ({ commit, state }, payload) => {
300+
[types.openProject]: ({ commit }, payload) => {
301301
commit(types.REMOVE_ALL_STATE_PROPS_ACTIONS)
302302
commit(types.SET_ACTIVE_ROUTE, "HomeView");
303303
payload.userProps.forEach((prop)=>{commit(types.CREATE_PROP, prop)})
@@ -309,11 +309,6 @@ const actions = {
309309
commit(types.SET_ACTIVE_COMPONENT, '')
310310
},
311311

312-
[types.importComponent]: ({ commit }, payload) => {
313-
//import component
314-
console.log(payload)
315-
},
316-
317312
// Add project
318313
[types.addProject]: ({ commit }, payload) => {
319314
commit(types.ADD_PROJECT, payload);

test/jest/__tests__/App.spec.js

Lines changed: 22 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -8,167 +8,6 @@ import { mount, createLocalVue, shallowMount } from "@vue/test-utils";
88
import * as All from "quasar";
99
const { Quasar, date } = All;
1010

11-
describe("Test mutations + actions to remove action from component and userActions", () => {
12-
let state;
13-
beforeEach(() => {
14-
// state = {
15-
// componentMap: {
16-
// component: {
17-
// componentName: "App",
18-
// children: ["HomeView"],
19-
// htmlList: [],
20-
// mapActions: ["action"]
21-
// }
22-
// },
23-
// activeComponent: "component",
24-
// userActions: ["action"]
25-
// };
26-
state = {
27-
// state below is what is used when exporting a project
28-
componentMap: {
29-
App: {
30-
componentName: 'component',
31-
children: ['HomeView'],
32-
htmlList: []
33-
},
34-
HomeView: {
35-
componentName: 'HomeView',
36-
children: [],
37-
htmlList: []
38-
}
39-
},
40-
routes: {
41-
HomeView: []
42-
},
43-
userActions: [],
44-
userProps: [],
45-
userState: [],
46-
imagePath: {
47-
HomeView: ''
48-
},
49-
// state below is not used when exporting a project
50-
componentNameInputValue: '',
51-
projects: [{ filename: 'Untitled-1', lastSavedLocation: '' }],
52-
53-
activeRoute: 'HomeView',
54-
// need to change to activeComponentName
55-
activeComponent: '',
56-
activeComponentObj: null,
57-
activeHTML: '',
58-
activeLayer: {
59-
id: '',
60-
lineage: []
61-
},
62-
63-
selectedProps: [],
64-
selectedState: [],
65-
selectedActions: [],
66-
selectedElementList: [],
67-
projectNumber: 2,
68-
activeTab: 0,
69-
componentChildrenMultiselectValue: [],
70-
modalOpen: false,
71-
parentSelected: false,
72-
// for storing copied component
73-
copiedComponent: {},
74-
copyNumber: 0,
75-
pastedComponent: {}
76-
}
77-
});
78-
79-
it("deleting user action from state.userActions", () => {
80-
mutations.DELETE_USER_ACTIONS(state, "action");
81-
expect(state.userActions.length).toBe(0);
82-
});
83-
84-
// it('deleting "action" from componentMap', () => {
85-
// mutations.REMOVE_ACTION_FROM_COMPONENT(state, "action");
86-
// expect(state.componentMap.component.mapActions.length).toBe(0);
87-
// });
88-
});
89-
90-
describe("Adding actions and state to components", () => {
91-
let state;
92-
beforeEach(() => {
93-
state = {
94-
componentMap: {
95-
testComponent: {
96-
componentName: "testComponent",
97-
children: [],
98-
htmlList: [],
99-
componentActions: [],
100-
componentState: []
101-
}
102-
},
103-
activeComponent: "testComponent"
104-
};
105-
});
106-
describe("Adding actions to components", () => {
107-
// it("should add a single action to active component", () => {
108-
// mutations.ADD_TO_COMPONENT_ACTIONS(state, "testAction");
109-
// expect(
110-
// state.componentMap[state.activeComponent].componentActions
111-
// ).toEqual(["testAction"]);
112-
// });
113-
});
114-
describe("Adding state to components", () => {
115-
it("should add a single state string to active component", () => {
116-
// mutations.ADD_TO_COMPONENT_STATE(state, "testState");
117-
// expect(state.componentMap[state.activeComponent].componentState).toEqual([
118-
// "testState"
119-
// ]);
120-
});
121-
});
122-
});
123-
124-
// describe("userActions mutation", () => {
125-
// let actions;
126-
// let store;
127-
// beforeEach(() => {
128-
// store = {
129-
// userActions: []
130-
// };
131-
// });
132-
// it("should push user defined action to end of userActions array", () => {
133-
// // mutations.ADD_USER_ACTION(store, "actionnnn");
134-
// // expect(store.userActions[store.userActions.length - 1]).toBe("actionnnn");
135-
// // });
136-
// it("should only push to array if payload is of type string", () => {
137-
// // mutations.ADD_USER_ACTION(store, 66);
138-
// // expect(store.userActions).toStrictEqual([]);
139-
// // });
140-
// });
141-
142-
// describe("userStore mutation", () => {
143-
// let actions;
144-
// let store;
145-
// store = {
146-
// userStore: {}
147-
// };
148-
// it("should be able to update store with a key defined by the user and a value of type object", () => {
149-
// mutations.ADD_TO_USER_STORE(store, { dummyKey: {} });
150-
// // console.log('store.userStore.dummyKey', store.userStore.dummyKey);
151-
// expect(store.userStore.dummyKey).toStrictEqual({});
152-
// });
153-
// it("should update user store with a key value pair with value strictly equal to empty array", () => {
154-
// mutations.ADD_TO_USER_STORE(store, { dummyKey: [] });
155-
// expect(store.userStore.dummyKey).toStrictEqual([]);
156-
// });
157-
// it("should be able to store booleans in the store as the key", () => {
158-
// mutations.ADD_TO_USER_STORE(store, { boolean: true });
159-
// expect(store.userStore.boolean).toBe(true);
160-
// });
161-
// it("should add to userStore a key with a value of type number", () => {
162-
// mutations.ADD_TO_USER_STORE(store, { number: 696 });
163-
// expect(store.userStore.number).toBe(696);
164-
// });
165-
166-
// it("should work with strings too", () => {
167-
// mutations.ADD_TO_USER_STORE(store, { string: "string" });
168-
// expect(store.userStore.string).toBe("string");
169-
// });
170-
// });
171-
17211
/**
17312
* @description: Tests for deleting state
17413
* @summary:
@@ -177,42 +16,40 @@ describe("Adding actions and state to components", () => {
17716
* `userStore` holds the user defined state objects
17817
*/
17918

180-
describe("Delete state in userStore/componentMap", () => {
19+
describe("Delete state/actions in userStore/componentMap", () => {
18120
let state;
18221
beforeEach(() => {
18322
state = {
18423
componentMap: {
185-
test: {
24+
testComp: {
18625
componentName: "test",
18726
children: [],
18827
htmlList: [],
18928
componentActions: [],
190-
state: ["state1", "state2"]
29+
state: ["state1", "state2"],
30+
actions: ["action1", "action2"]
19131
}
19232
},
19333
activeComponent: "test",
194-
userState: ['state1', 'state2']
34+
userState: ['state1', 'state2'],
35+
userActions: ['action1', 'action2'],
36+
userProps: ['prop1', 'prop2']
19537
};
19638
});
197-
describe('"DELETE_USER_STATE" should delete property from "userStore" object', () => {
198-
it("should delete a single state property", () => {
199-
mutations.DELETE_USER_STATE(state, "state1");
200-
expect(state.userState).toEqual(['state2']);
201-
});
39+
test("'[types.DELETE_USER_STATE]' should delete a single state property", () => {
40+
mutations.DELETE_USER_STATE(state, "state1");
41+
expect(state.userState).toEqual(['state2']);
42+
});
43+
test("'[types.DELETE_USER_ACTIONS]' should delete a single action property", () => {
44+
mutations.DELETE_USER_ACTIONS(state, "action1");
45+
expect(state.userActions).toEqual(['action2']);
20246
});
203-
// describe('"REMOVE_STATE_FROM_COMPONENT" should delete state in "activeComponent"', () => {
204-
// it("should remove state from active component", () => {
205-
// mutations.REMOVE_STATE_FROM_COMPONENT(state, "state2");
206-
// expect(state.componentMap.test.componentState).toEqual(["state1"]);
207-
// });
208-
// });
209-
// describe('"deleteUserState" should delete state in "activeComponent" when deleted from "userStore"', () => {
210-
// const commit = jest.fn();
211-
// it("should remove state from active component", () => {
212-
// actions.deleteUserState({ commit }, "state2");
213-
// expect(state.componentMap[state.activeComponent].componentState).toEqual([
214-
// "state1"
215-
// ]);
216-
// });
217-
// });
47+
test("'[types.REMOVE_ALL_STATE_PROPS_ACTIONS]' should delete all props, state and action", () => {
48+
mutations.REMOVE_ALL_STATE_PROPS_ACTIONS(state);
49+
expect(state.userState.length).toEqual(0);
50+
expect(state.userActions.length).toEqual(0);
51+
expect(state.userProps.length).toEqual(0);
52+
});
53+
21854
});
55+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
import store from "../../../src/store/state/index";
10+
11+
12+
//testing that export as typescript on/off, showTutorial, all update properly
13+
describe("Test for exportAsTypescript flag to flip when mutation committed", () => {
14+
const App = {}
15+
const app = createApp(App);
16+
app.use(Quasar, Vuex);
17+
const state = { ...store }
18+
19+
//tests that the export as typescript mutation properly updates state to on/off
20+
test('"[types.EXPORT_AS_TYPESCRIPT]" to update state successfully', ()=>{
21+
mutations[types.EXPORT_AS_TYPESCRIPT](state, 'on');
22+
expect(state.exportAsTypescript).toEqual('on');
23+
mutations[types.EXPORT_AS_TYPESCRIPT](state, 'off');
24+
expect(state.exportAsTypescript).toEqual('off');
25+
})
26+
27+
//tests that the tutorial toggle successfully updates state to true/false
28+
test('"[types.toggleTutorial]" action to commit TOGGLE_TUTORIAL', () => {
29+
const commit = jest.fn();
30+
actions[types.toggleTutorial]({ state, commit });
31+
expect(commit).toHaveBeenCalledWith(types.TOGGLE_TUTORIAL);
32+
});
33+
34+
test('"[types.TOGGLE_TUTORIAL]" to mutate state true/false', () => {
35+
mutations[types.TOGGLE_TUTORIAL](state);
36+
expect(state.showTutorial).toBe(false)
37+
mutations[types.TOGGLE_TUTORIAL](state);
38+
expect(state.showTutorial).toBe(true)
39+
});
40+
41+
});

test/jest/__tests__/noteTests.spec.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
import store from "../../../src/store/state/index";
10+
11+
describe("Test for component note data population", () => {
12+
const App = {}
13+
const app = createApp(App);
14+
app.use(Quasar, Vuex);
15+
const state = { ...store }
16+
17+
//tests that ADD_ACTIVE_COMPONENT_NOTE mutation successfully populates activeComponent with notes
18+
test('"[types.ADD_ACTIVE_COMPONENT_NOTE]" to update state successfully', ()=>{
19+
mutations[types.ADD_COMPONENT_TO_COMPONENT_MAP](state, {componentName: 'testComponent'})
20+
mutations[types.SET_ACTIVE_COMPONENT](state, 'testComponent')
21+
mutations[types.ADD_ACTIVE_COMPONENT_NOTE](state, 'test note here');
22+
expect(state.componentMap[state.activeComponent].noteList[0]).toEqual('test note here');
23+
mutations[types.ADD_ACTIVE_COMPONENT_NOTE](state, 'another test here');
24+
expect(state.componentMap[state.activeComponent].noteList[1]).toEqual('another test here');
25+
})
26+
27+
//tests that the action addActiveComponentNote commits the mutation
28+
test('"[types.addActiveComponentNote]" action to commit ADD_ACTIVE_COMPONENT_NOTE', () => {
29+
const commit = jest.fn();
30+
actions[types.addActiveComponentNote]({ commit }, 'test note');
31+
expect(commit).toHaveBeenCalledWith(types.ADD_ACTIVE_COMPONENT_NOTE, 'test note');
32+
});
33+
34+
//tests that DELETE_ACTIVE_COMPONENT_NOTE mutation successfully deletes activeComponent notes
35+
test('"[types.DELETE_ACTIVE_COMPONENT_NOTE]" to update state successfully', ()=>{
36+
mutations[types.DELETE_ACTIVE_COMPONENT_NOTE](state, 'test note here');
37+
expect(state.componentMap[state.activeComponent].noteList[0]).toEqual('another test here');
38+
mutations[types.DELETE_ACTIVE_COMPONENT_NOTE](state, 'another test here');
39+
expect(state.componentMap[state.activeComponent].noteList.length).toEqual(0);
40+
})
41+
42+
test('"[types.deleteActiveComponentNote]" action to commit DELETE_ACTIVE_COMPONENT_NOTE', () => {
43+
const commit = jest.fn();
44+
actions[types.deleteActiveComponentNote]({ commit }, 'test note');
45+
expect(commit).toHaveBeenCalledWith(types.DELETE_ACTIVE_COMPONENT_NOTE, 'test note');
46+
});
47+
48+
test('expect mutation to check and handle for duplicate note entry', () =>{
49+
mutations[types.ADD_ACTIVE_COMPONENT_NOTE](state, 'test note here');
50+
mutations[types.ADD_ACTIVE_COMPONENT_NOTE](state, 'test note here');
51+
expect(state.componentMap[state.activeComponent].noteList[1]).toEqual('DUPLICATE: test note here');
52+
});
53+
54+
test('"[types.openNoteModal]" action to commit OPEN_NOTE_MODAL', () => {
55+
const commit = jest.fn();
56+
actions[types.openNoteModal]({ commit });
57+
expect(commit).toHaveBeenCalledWith(types.OPEN_NOTE_MODAL);
58+
});
59+
60+
test('"[types.OPEN_NOTE_MODAL]" to update state successfully', ()=>{
61+
mutations[types.OPEN_NOTE_MODAL](state);
62+
expect(state.noteModalOpen).toEqual(true);
63+
mutations[types.OPEN_NOTE_MODAL](state);
64+
expect(state.noteModalOpen).toEqual(false);
65+
})
66+
67+
});

0 commit comments

Comments
 (0)