Skip to content

Commit abde05f

Browse files
authored
Merge pull request #47 from deanfchung/master
userAction and userStore mutations tests
2 parents a83d5ad + b25398f commit abde05f

File tree

4 files changed

+102
-55
lines changed

4 files changed

+102
-55
lines changed

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/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: 87 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,114 @@
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 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

14+
//const localVue = createLocalVue()
15+
16+
// localVue.use(Vuex)
17+
1218
const components = Object.keys(All).reduce((object, key) => {
1319
const val = All[key]
1420
if (val && val.component && val.component.name != null) {
1521
object[key] = val
1622
}
1723
return object
1824
}, {})
19-
20-
describe('Dummy test', () => {
25+
/*
26+
describe('Mount Quasar', () => {
2127
const localVue = createLocalVue()
22-
localVue.use(Quasar, { components })
23-
const testValue = false;
24-
it('does this produce the correct result', () => {
25-
expect(testValue).toBe(false)
26-
})
27-
})
28+
localVue.use(Quasar, { components }) // , lang: langEn
2829
29-
describe('Test Suite - Delete from userActions and/or componentMap', () => {
30-
const localVue = createLocalVue()
31-
localVue.use(Quasar, { components })
32-
const testValue = false;
33-
it('does this produce the correct result ahahaha', () => {
34-
expect(testValue).toBe(false)
30+
const wrapper = mount(QBUTTON, {
31+
localVue
3532
})
36-
})
33+
const vm = wrapper.vm
3734
38-
// describe('Mount Quasar', () => {
39-
// const localVue = createLocalVue()
40-
// localVue.use(Quasar, { components }) // , lang: langEn
35+
it('passes the sanity check and creates a wrapper', () => {
36+
expect(wrapper.isVueInstance()).toBe(true)
37+
})
4138
42-
// const wrapper = mount(QBUTTON, {
43-
// localVue
44-
// })
45-
// const vm = wrapper.vm
39+
it('has a created hook', () => {
40+
expect(typeof vm.increment).toBe('function')
41+
})
4642
47-
// it('passes the sanity check and creates a wrapper', () => {
48-
// expect(wrapper.isVueInstance()).toBe(true)
49-
// })
43+
it('accesses the shallowMount', () => {
44+
expect(vm.$el.textContent).toContain('rocket muffin')
45+
expect(wrapper.text()).toContain('rocket muffin') // easier
46+
expect(wrapper.find('p').text()).toContain('rocket muffin')
47+
})
5048
51-
// it('has a created hook', () => {
52-
// expect(typeof vm.increment).toBe('function')
53-
// })
49+
it('sets the correct default data', () => {
50+
expect(typeof vm.counter).toBe('number')
51+
const defaultData2 = QBUTTON.data()
52+
expect(defaultData2.counter).toBe(0)
53+
})
5454
55-
// it('accesses the shallowMount', () => {
56-
// expect(vm.$el.textContent).toContain('rocket muffin')
57-
// expect(wrapper.text()).toContain('rocket muffin') // easier
58-
// expect(wrapper.find('p').text()).toContain('rocket muffin')
59-
// })
55+
it('correctly updates data when button is pressed', () => {
56+
const button = wrapper.find('button')
57+
button.trigger('click')
58+
expect(vm.counter).toBe(1)
59+
})
6060
61-
// it('sets the correct default data', () => {
62-
// expect(typeof vm.counter).toBe('number')
63-
// const defaultData2 = QBUTTON.data()
64-
// expect(defaultData2.counter).toBe(0)
65-
// })
61+
it('formats a date without throwing exception', () => {
62+
// test will automatically fail if an exception is thrown
63+
// MMMM and MMM require that a language is 'installed' in Quasar
64+
let formattedString = date.formatDate(Date.now(), 'YYYY MMMM MMM DD')
65+
console.log('formattedString', formattedString)
66+
})
67+
})
68+
*/
69+
describe('userActions mutation', () => {
70+
let actions;
71+
let store;
72+
beforeEach(() => {
73+
store = {
74+
userActions: []
75+
}
76+
})
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+
});
6686

67-
// it('correctly updates data when button is pressed', () => {
68-
// const button = wrapper.find('button')
69-
// button.trigger('click')
70-
// expect(vm.counter).toBe(1)
71-
// })
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)
109+
})
72110

73-
// it('formats a date without throwing exception', () => {
74-
// // test will automatically fail if an exception is thrown
75-
// // MMMM and MMM require that a language is 'installed' in Quasar
76-
// let formattedString = date.formatDate(Date.now(), 'YYYY MMMM MMM DD')
77-
// console.log('formattedString', formattedString)
78-
// })
79-
// })
111+
it ('should work with strings too', () => {
112+
mutations.ADD_TO_USER_STORE(store, { string: 'string'})
113+
expect(store.userStore.string).toBe('string')
114+
})
115+
});

0 commit comments

Comments
 (0)