Skip to content

Commit b25398f

Browse files
committed
mutations tests for userActions and userStore
1 parent 0bc9792 commit b25398f

File tree

4 files changed

+55
-15
lines changed

4 files changed

+55
-15
lines changed

src/store/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const actions = {
122122
[types.deleteComponent]: ({state, commit }, payload) => {
123123
console.log('payload in actions:', payload)
124124
commit(types.DELETE_COMPONENT, payload)
125-
},
125+
}
126126
}
127127

128128
export default actions

src/store/mutations.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ const mutations = {
199199
state.routes[state.activeRoute] = compArr
200200
console.log('new state', state)
201201

202+
},
203+
[types.ADD_USER_ACTION]: (state, payload) => {
204+
if (typeof(payload)==='string') state.userActions.push(payload);
205+
},
206+
[types.ADD_TO_USER_STORE]: (state, payload) => {
207+
const key = Object.keys(payload);
208+
state.userStore[key] = payload[key];
202209
}
203210
}
204211

src/store/types.js

Lines changed: 4 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 ADD_USER_ACTION = 'ADD_USER_ACTION'
45+
export const ADD_TO_USER_STORE = 'ADD_TO_USER_STORE'
4446

4547
// Actions
4648
export const registerComponent = 'registerComponent'
@@ -75,3 +77,5 @@ export const updateOpenModal = 'updateOpenModal'
7577
export const parentSelected = 'parentSelected'
7678
export const deleteRoute = 'deleteRoute'
7779
export const deleteComponent = 'deleteComponent'
80+
export const addUserAction = 'addUserAction'
81+
export const addToUserStore = 'addToUserStore'

test/jest/__tests__/App.spec.js

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
/**
33
* @jest-environment jsdom
44
*/
5-
import actions from '../../store/actions';
5+
import mutations from '../../../src/store/mutations';
66
import { mount, createLocalVue, shallowMount } from '@vue/test-utils'
7+
import Vuex from 'vuex';
78
import QBUTTON from './demo/QBtn-demo.vue'
89
import * as All from 'quasar'
10+
911
// import langEn from 'quasar/lang/en-us' // change to any language you wish! => this breaks wallaby :(
1012
const { Quasar, date } = All
1113

12-
const localVue = createLocalVue()
14+
//const localVue = createLocalVue()
1315

14-
localVue.use(Vuex)
16+
// localVue.use(Vuex)
1517

1618
const components = Object.keys(All).reduce((object, key) => {
1719
const val = All[key]
@@ -64,23 +66,50 @@ describe('Mount Quasar', () => {
6466
})
6567
})
6668
*/
67-
describe('actions', () => {
69+
describe('userActions mutation', () => {
6870
let actions;
6971
let store;
7072
beforeEach(() => {
71-
const dummyFunction = jest.fn(() => 'hello')
72-
actions = {
73-
userActionInput: dummyFunction,
74-
userStore: dummyFunction
73+
store = {
74+
userActions: []
7575
}
76-
store = new Vuex.Store({
77-
actions
78-
})
7976
})
77+
it ('should push user defined action to end of userActions array', () => {
78+
mutations.ADD_USER_ACTION(store, 'actionnnn')
79+
expect(store.userActions[store.userActions.length-1]).toBe('actionnnn');
80+
})
81+
it ('should only push to array if payload is of type string', () => {
82+
mutations.ADD_USER_ACTION(store, 66)
83+
expect(store.userActions).toStrictEqual([])
84+
})
85+
});
8086

81-
it('should take in a string and output a string into userActions array', () => {
82-
const wrapper = shallowMount(actions, {store, localVue })
83-
87+
describe('userStore mutation', () => {
88+
let actions;
89+
let store;
90+
store = {
91+
userStore : {}
92+
}
93+
it ('should be able to update store with a key defined by the user and a value of type object', () => {
94+
mutations.ADD_TO_USER_STORE(store, {'dummyKey': {}})
95+
// console.log('store.userStore.dummyKey', store.userStore.dummyKey);
96+
expect(store.userStore.dummyKey).toStrictEqual({})
97+
})
98+
it ('should update user store with a key value pair with value strictly equal to empty array', () => {
99+
mutations.ADD_TO_USER_STORE(store, {'dummyKey': []})
100+
expect(store.userStore.dummyKey).toStrictEqual([]);
101+
})
102+
it ('should be able to store booleans in the store as the key', () => {
103+
mutations.ADD_TO_USER_STORE(store, {boolean: true})
104+
expect (store.userStore.boolean).toBe(true)
105+
})
106+
it ('should add to userStore a key with a value of type number', () => {
107+
mutations.ADD_TO_USER_STORE(store, { number:696 })
108+
expect (store.userStore.number).toBe(696)
84109
})
85110

111+
it ('should work with strings too', () => {
112+
mutations.ADD_TO_USER_STORE(store, { string: 'string'})
113+
expect(store.userStore.string).toBe('string')
114+
})
86115
});

0 commit comments

Comments
 (0)