Skip to content

Commit d7bc835

Browse files
committed
added test and mutation for adding state to active component
1 parent e790755 commit d7bc835

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

src/store/mutations.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ const mutations = {
201201
},
202202
[types.ADD_TO_COMPONENT_ACTIONS]: (state, payload) => {
203203
state.componentMap[state.activeComponent].componentActions.push(payload)
204+
},
205+
[types.ADD_TO_COMPONENT_STATE]: (state, payload) => {
206+
state.componentMap[state.activeComponent].componentState.push(payload)
204207
}
205208
}
206209

src/store/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const PARENT_SELECTED = 'PARENT_SELECTED'
4242
export const DELETE_ROUTE = 'DELETE_ROUTE'
4343
export const DELETE_COMPONENT = 'DELETE_COMPONENT'
4444
export const ADD_TO_COMPONENT_ACTIONS = 'ADD_TO_COMPONENT_ACTIONS'
45+
export const ADD_TO_COMPONENT_STATE = 'ADD_TO_COMPONENT_STATE'
4546

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

test/jest/__tests__/App.spec.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,33 @@ describe('Dummy test', () => {
2727
})
2828
})
2929

30-
describe('Adding actions to components', () => {
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'])
30+
describe('Adding actions and state to components', () => {
31+
let state;
32+
beforeEach(() => {
33+
state = {
34+
componentMap: {
35+
testComponent: {
36+
componentName: 'testComponent',
37+
children: [],
38+
htmlList: [],
39+
componentActions: [],
40+
componentState: []
41+
}
42+
},
43+
activeComponent: 'testComponent'
44+
}
45+
})
46+
describe('Adding actions to components', () => {
47+
it('should add a single action to active component', () => {
48+
mutations.ADD_TO_COMPONENT_ACTIONS(state, 'testAction')
49+
expect(state.componentMap[state.activeComponent].componentActions).toEqual(['testAction'])
50+
})
51+
})
52+
describe('Adding state to components', () => {
53+
it('should add a single state string to active component', () => {
54+
mutations.ADD_TO_COMPONENT_STATE(state, 'testState')
55+
expect(state.componentMap[state.activeComponent].componentState).toEqual(['testState'])
56+
})
4657
})
4758
})
4859

0 commit comments

Comments
 (0)