Skip to content

Commit c7d003e

Browse files
committed
added tests
2 parents b975c3d + 1fb707b commit c7d003e

File tree

16 files changed

+266
-176
lines changed

16 files changed

+266
-176
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ node_modules
66
/src-cordova/node_modules
77
/src-cordova/platforms
88
/src-cordova/plugins
9-
/src-cordova/www
9+
/src-cordova/www\
10+
/test/jest/coverage
1011
npm-debug.log*
1112
yarn-debug.log*
1213
yarn-error.log*

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/store/actions.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ const actions = {
133133
},
134134
[types.clearImage]: ({ commit }) => {
135135
commit(types.CLEAR_IMAGE)
136+
},
137+
[types.deleteUserActions]: ({ state, commit }, payload) => {
138+
console.log('invoking deleteUserActions')
139+
if (state.activeComponent) { commit(types.REMOVE_ACTION_FROM_COMPONENT, payload) }
140+
commit(types.DELETE_USER_ACTIONS, payload)
141+
},
142+
[types.removeActionFromComponent]: ({ state, commit }, payload) => {
143+
console.log('invoking removeActionFromComponent')
144+
commit(types.REMOVE_ACTION_FROM_COMPONENT, payload)
136145
}
137146
}
138147

src/store/mutations.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,30 @@ const mutations = {
212212
[types.CLEAR_IMAGE]: state => {
213213
console.log(`clear image invoked`)
214214
if (state.imagePath) state.imagePath = ''
215+
},
216+
[types.DELETE_USER_ACTIONS]: (state, payload) => {
217+
// payload should be a string of the name of the action to remove
218+
let index = state.userActions.indexOf(payload)
219+
state.userActions.splice(index, 1)
220+
},
221+
[types.REMOVE_ACTION_FROM_COMPONENT]: (state, payload) => {
222+
let index = state.componentMap[state.activeComponent].mapActions.indexOf(
223+
payload
224+
)
225+
state.componentMap[state.activeComponent].mapActions.splice(index, 1)
226+
},
227+
[types.ADD_TO_COMPONENT_ACTIONS]: (state, payload) => {
228+
state.componentMap[state.activeComponent].componentActions.push(payload)
229+
},
230+
[types.ADD_TO_COMPONENT_STATE]: (state, payload) => {
231+
state.componentMap[state.activeComponent].componentState.push(payload)
232+
},
233+
[types.ADD_USER_ACTION]: (state, payload) => {
234+
if (typeof payload === 'string') state.userActions.push(payload)
235+
},
236+
[types.ADD_TO_USER_STORE]: (state, payload) => {
237+
const key = Object.keys(payload)
238+
state.userStore[key] = payload[key]
215239
}
216240
}
217241

src/store/state/index.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,8 @@ const newState = {
2929
HomeView: []
3030
// NewView: []
3131
},
32-
userState: {
33-
userActions: false,
34-
activeStore: false,
35-
storeContents: {
36-
obj1: 'string',
37-
obj2: 'boolean',
38-
obj3: 'array'
39-
}
40-
},
41-
userActions: ['action1', 'action2'],
32+
userActions: [],
33+
userState: {},
4234
/**
4335
*
4436
*/

src/store/types.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ export const DELETE_COMPONENT = 'DELETE_COMPONENT'
4444
// Image upload mutations
4545
export const IMPORT_IMAGE = 'IMPORT_IMAGE'
4646
export const CLEAR_IMAGE = 'CLEAR_IMAGE'
47+
export const DELETE_USER_ACTIONS = 'DELETE_USER_ACTIONS'
48+
export const REMOVE_ACTION_FROM_COMPONENT = 'REMOVE_ACTION_FROM_COMPONENT'
49+
export const ADD_TO_COMPONENT_ACTIONS = 'ADD_TO_COMPONENT_ACTIONS'
50+
export const ADD_TO_COMPONENT_STATE = 'ADD_TO_COMPONENT_STATE'
51+
export const ADD_USER_ACTION = 'ADD_USER_ACTION'
52+
export const ADD_TO_USER_STORE = 'ADD_TO_USER_STORE'
4753

4854
// Actions
4955
export const registerComponent = 'registerComponent'
@@ -81,3 +87,8 @@ export const deleteComponent = 'deleteComponent'
8187
// image upload logic
8288
export const importImage = 'importImage'
8389
export const clearImage = 'clearImage'
90+
91+
export const deleteUserActions = 'deleteUserActions'
92+
export const removeActionFromComponent = 'removeActionFromComponent'
93+
export const addUserAction = 'addUserAction'
94+
export const addToUserStore = 'addToUserStore'

test/jest/__tests__/App.spec.js

Lines changed: 103 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,99 +2,117 @@
22
/**
33
* @jest-environment jsdom
44
*/
5-
5+
import mutations from "../../../src/store/mutations";
66
import { mount, createLocalVue, shallowMount } from "@vue/test-utils";
7-
import QBUTTON from "./demo/QBtn-demo.vue";
87
import * as All from "quasar";
9-
// import langEn from 'quasar/lang/en-us' // change to any language you wish! => this breaks wallaby :(
108
const { Quasar, date } = All;
119

12-
const components = Object.keys(All).reduce((object, key) => {
13-
const val = All[key];
14-
if (val && val.component && val.component.name != null) {
15-
object[key] = val;
16-
}
17-
return object;
18-
}, {});
19-
20-
describe("Test Suite - Delete from userActions and/or componentMap", () => {
21-
const localVue = createLocalVue();
22-
localVue.use(Quasar, { components });
23-
const testValue = false;
24-
it("does this produce the correct result ahahaha", () => {
25-
expect(testValue).toBe(false);
10+
describe("Test mutations + actions to remove action from component and userActions", () => {
11+
let state;
12+
beforeEach(() => {
13+
state = {
14+
componentMap: {
15+
component: {
16+
componentName: "App",
17+
children: ["HomeView"],
18+
htmlList: [],
19+
mapActions: ["action"]
20+
}
21+
},
22+
activeComponent: "component",
23+
userActions: ["action"]
24+
};
2625
});
27-
});
28-
29-
/**
30-
* @description: Tests for deleting state
31-
* @summary:
32-
* `deleteUserState` invokes removeStateFromComponent
33-
* `removeStateFromComponent` mutation that deletes state from userStore
34-
* `userStore` holds the user defined state objects
35-
*
36-
*/
37-
38-
// describe("Test Suite - Delete from userState(?) and/or componentMap", () => {
39-
// const localVue = createLocalVue();
40-
// localVue.use(Quasar, { components });
41-
// const dumVal = false;
42-
// it("removeStateFromComponent deletes item from userStore", () => {
4326

44-
// expect(dumVal).toBe(false);
45-
// });
46-
// it("removeStateFromComponent deletes the appropriate item from userStore", () => {
47-
// expect(dumVal).toBe(false);
48-
// });
49-
// it("removeStateFromComponent deletes the appropriate item from component in componentMap", () => {
50-
// expect(dumVal).toBe(false);
51-
// });
52-
// it("deleteUserState invokes removeStateFromComponent", () => {
53-
// expect(dumVal).toBe(false);
54-
// });
55-
// it("deleteUserState payload deletes the appropriate item from userStore", () => {
56-
// expect(dumVal).toBe(false);
57-
// });
58-
// });
59-
// describe('Mount Quasar', () => {
60-
// const localVue = createLocalVue()
61-
// localVue.use(Quasar, { components }) // , lang: langEn
62-
63-
// const wrapper = mount(QBUTTON, {
64-
// localVue
65-
// })
66-
// const vm = wrapper.vm
67-
68-
// it('passes the sanity check and creates a wrapper', () => {
69-
// expect(wrapper.isVueInstance()).toBe(true)
70-
// })
27+
it("deleting user action from state.userActions", () => {
28+
mutations.DELETE_USER_ACTIONS(state, "action");
29+
expect(state.userActions.length).toBe(0);
30+
});
7131

72-
// it('has a created hook', () => {
73-
// expect(typeof vm.increment).toBe('function')
74-
// })
32+
it('deleting "action" from componentMap', () => {
33+
mutations.REMOVE_ACTION_FROM_COMPONENT(state, "action");
34+
expect(state.componentMap.component.mapActions.length).toBe(0);
35+
});
36+
});
7537

76-
// it('accesses the shallowMount', () => {
77-
// expect(vm.$el.textContent).toContain('rocket muffin')
78-
// expect(wrapper.text()).toContain('rocket muffin') // easier
79-
// expect(wrapper.find('p').text()).toContain('rocket muffin')
80-
// })
38+
describe("Adding actions and state to components", () => {
39+
let state;
40+
beforeEach(() => {
41+
state = {
42+
componentMap: {
43+
testComponent: {
44+
componentName: "testComponent",
45+
children: [],
46+
htmlList: [],
47+
componentActions: [],
48+
componentState: []
49+
}
50+
},
51+
activeComponent: "testComponent"
52+
};
53+
});
54+
describe("Adding actions to components", () => {
55+
it("should add a single action to active component", () => {
56+
mutations.ADD_TO_COMPONENT_ACTIONS(state, "testAction");
57+
expect(
58+
state.componentMap[state.activeComponent].componentActions
59+
).toEqual(["testAction"]);
60+
});
61+
});
62+
describe("Adding state to components", () => {
63+
it("should add a single state string to active component", () => {
64+
mutations.ADD_TO_COMPONENT_STATE(state, "testState");
65+
expect(state.componentMap[state.activeComponent].componentState).toEqual([
66+
"testState"
67+
]);
68+
});
69+
});
70+
});
8171

82-
// it('sets the correct default data', () => {
83-
// expect(typeof vm.counter).toBe('number')
84-
// const defaultData2 = QBUTTON.data()
85-
// expect(defaultData2.counter).toBe(0)
86-
// })
72+
describe("userActions mutation", () => {
73+
let actions;
74+
let store;
75+
beforeEach(() => {
76+
store = {
77+
userActions: []
78+
};
79+
});
80+
it("should push user defined action to end of userActions array", () => {
81+
mutations.ADD_USER_ACTION(store, "actionnnn");
82+
expect(store.userActions[store.userActions.length - 1]).toBe("actionnnn");
83+
});
84+
it("should only push to array if payload is of type string", () => {
85+
mutations.ADD_USER_ACTION(store, 66);
86+
expect(store.userActions).toStrictEqual([]);
87+
});
88+
});
8789

88-
// it('correctly updates data when button is pressed', () => {
89-
// const button = wrapper.find('button')
90-
// button.trigger('click')
91-
// expect(vm.counter).toBe(1)
92-
// })
90+
describe("userStore mutation", () => {
91+
let actions;
92+
let store;
93+
store = {
94+
userStore: {}
95+
};
96+
it("should be able to update store with a key defined by the user and a value of type object", () => {
97+
mutations.ADD_TO_USER_STORE(store, { dummyKey: {} });
98+
// console.log('store.userStore.dummyKey', store.userStore.dummyKey);
99+
expect(store.userStore.dummyKey).toStrictEqual({});
100+
});
101+
it("should update user store with a key value pair with value strictly equal to empty array", () => {
102+
mutations.ADD_TO_USER_STORE(store, { dummyKey: [] });
103+
expect(store.userStore.dummyKey).toStrictEqual([]);
104+
});
105+
it("should be able to store booleans in the store as the key", () => {
106+
mutations.ADD_TO_USER_STORE(store, { boolean: true });
107+
expect(store.userStore.boolean).toBe(true);
108+
});
109+
it("should add to userStore a key with a value of type number", () => {
110+
mutations.ADD_TO_USER_STORE(store, { number: 696 });
111+
expect(store.userStore.number).toBe(696);
112+
});
93113

94-
// it('formats a date without throwing exception', () => {
95-
// // test will automatically fail if an exception is thrown
96-
// // MMMM and MMM require that a language is 'installed' in Quasar
97-
// let formattedString = date.formatDate(Date.now(), 'YYYY MMMM MMM DD')
98-
// console.log('formattedString', formattedString)
99-
// })
100-
// })
114+
it("should work with strings too", () => {
115+
mutations.ADD_TO_USER_STORE(store, { string: "string" });
116+
expect(store.userStore.string).toBe("string");
117+
});
118+
});

0 commit comments

Comments
 (0)