Skip to content

Commit 1fb707b

Browse files
authored
Merge pull request #49 from dnohashi/testing
Adding my test suite
2 parents d6615dc + cd16ea4 commit 1fb707b

File tree

4 files changed

+49
-13
lines changed

4 files changed

+49
-13
lines changed

src/store/actions.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,18 @@ const actions = {
119119
[types.deleteRoute]: ({ state, commit }, payload) => {
120120
commit(types.DELETE_ROUTE, payload)
121121
},
122-
[types.deleteComponent]: ({state, commit }, payload) => {
122+
[types.deleteComponent]: ({ state, commit }, payload) => {
123123
console.log('payload in actions:', payload)
124124
commit(types.DELETE_COMPONENT, payload)
125+
},
126+
[types.deleteUserActions]: ({ state, commit }, payload) => {
127+
console.log('invoking deleteUserActions')
128+
if(state.activeComponent) commit(types.REMOVE_ACTION_FROM_COMPONENT, payload)
129+
commit(types.DELETE_USER_ACTIONS, payload)
130+
},
131+
[types.removeActionFromComponent]: ({ state, commit }, payload) => {
132+
console.log('invoking removeActionFromComponent')
133+
commit(types.REMOVE_ACTION_FROM_COMPONENT, payload)
125134
}
126135
}
127136

src/store/mutations.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ const mutations = {
199199
state.routes[state.activeRoute] = compArr
200200
console.log('new state', state)
201201
},
202+
[types.DELETE_USER_ACTIONS]: (state, payload) => {
203+
//payload should be a string of the name of the action to remove
204+
let index = state.userActions.indexOf(payload)
205+
state.userActions.splice(index, 1)
206+
},
207+
[types.REMOVE_ACTION_FROM_COMPONENT]: (state, payload) => {
208+
let index = state.componentMap[state.activeComponent].mapActions.indexOf(payload)
209+
state.componentMap[state.activeComponent].mapActions.splice(index, 1)
210+
},
202211
[types.ADD_TO_COMPONENT_ACTIONS]: (state, payload) => {
203212
state.componentMap[state.activeComponent].componentActions.push(payload)
204213
},

src/store/types.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export const UPDATE_OPEN_MODAL = 'UPDATE_OPEN_MODAL'
4141
export const PARENT_SELECTED = 'PARENT_SELECTED'
4242
export const DELETE_ROUTE = 'DELETE_ROUTE'
4343
export const DELETE_COMPONENT = 'DELETE_COMPONENT'
44+
export const DELETE_USER_ACTIONS = 'DELETE_USER_ACTIONS'
45+
export const REMOVE_ACTION_FROM_COMPONENT = 'REMOVE_ACTION_FROM_COMPONENT'
4446
export const ADD_TO_COMPONENT_ACTIONS = 'ADD_TO_COMPONENT_ACTIONS'
4547
export const ADD_TO_COMPONENT_STATE = 'ADD_TO_COMPONENT_STATE'
4648
export const ADD_USER_ACTION = 'ADD_USER_ACTION'
@@ -79,5 +81,8 @@ export const updateOpenModal = 'updateOpenModal'
7981
export const parentSelected = 'parentSelected'
8082
export const deleteRoute = 'deleteRoute'
8183
export const deleteComponent = 'deleteComponent'
84+
85+
export const deleteUserActions = 'deleteUserActions'
86+
export const removeActionFromComponent = 'removeActionFromComponent'
8287
export const addUserAction = 'addUserAction'
8388
export const addToUserStore = 'addToUserStore'

test/jest/__tests__/App.spec.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,36 @@
44
*/
55
import mutations from '../../../src/store/mutations';
66
import { mount, createLocalVue, shallowMount } from '@vue/test-utils'
7-
import Vuex from 'vuex';
8-
import QBUTTON from './demo/QBtn-demo.vue'
97
import * as All from 'quasar'
10-
// import langEn from 'quasar/lang/en-us' // change to any language you wish! => this breaks wallaby :(
118
const { Quasar, date } = All
129

13-
//const localVue = createLocalVue()
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+
}
25+
})
1426

15-
// localVue.use(Vuex)
27+
it('deleting user action from state.userActions', () => {
28+
mutations.DELETE_USER_ACTIONS(state, 'action')
29+
expect(state.userActions.length).toBe(0)
30+
})
1631

17-
const components = Object.keys(All).reduce((object, key) => {
18-
const val = All[key]
19-
if (val && val.component && val.component.name != null) {
20-
object[key] = val
21-
}
22-
return object
23-
}, {})
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+
})
2437

2538
describe('Adding actions and state to components', () => {
2639
let state;

0 commit comments

Comments
 (0)