Skip to content

Commit e790755

Browse files
committed
added test and mutation to add an action to active component
1 parent 6e614d8 commit e790755

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/store/mutations.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ const mutations = {
198198
delete state.componentMap[payload.componentName]
199199
state.routes[state.activeRoute] = compArr
200200
console.log('new state', state)
201-
201+
},
202+
[types.ADD_TO_COMPONENT_ACTIONS]: (state, payload) => {
203+
state.componentMap[state.activeComponent].componentActions.push(payload)
202204
}
203205
}
204206

src/store/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ 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 ADD_TO_COMPONENT_ACTIONS = 'ADD_TO_COMPONENT_ACTIONS'
4445

4546
// Actions
4647
export const registerComponent = 'registerComponent'

test/jest/__tests__/App.spec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { mount, createLocalVue, shallowMount } from '@vue/test-utils'
77
import QBUTTON from './demo/QBtn-demo.vue'
88
import * as All from 'quasar'
9+
import mutations from '../../../src/store/mutations'
910
// import langEn from 'quasar/lang/en-us' // change to any language you wish! => this breaks wallaby :(
1011
const { Quasar, date } = All
1112

@@ -27,7 +28,22 @@ describe('Dummy test', () => {
2728
})
2829

2930
describe('Adding actions to components', () => {
30-
31+
const state = {
32+
componentMap: {
33+
testComponent: {
34+
componentName: 'testComponent',
35+
children: [],
36+
htmlList: [],
37+
componentActions: [],
38+
componentState: []
39+
}
40+
},
41+
activeComponent: 'testComponent'
42+
}
43+
it('should add a single action to a component based on active component', () => {
44+
mutations.ADD_TO_COMPONENT_ACTIONS(state, 'testAction')
45+
expect(state.componentMap[state.activeComponent].componentActions).toEqual(['testAction'])
46+
})
3147
})
3248

3349
// describe('Mount Quasar', () => {

0 commit comments

Comments
 (0)