Skip to content

Commit d6615dc

Browse files
authored
Merge pull request #48 from jeisele2/testing
Added tests and mutations for adding state/actions to active component
2 parents abde05f + 3cfb55c commit d6615dc

File tree

14 files changed

+151
-119
lines changed

14 files changed

+151
-119
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ node_modules
66
/src-cordova/node_modules
77
/src-cordova/platforms
88
/src-cordova/plugins
9-
/src-cordova/www
9+
/src-cordova/www\
10+
/test/jest/coverage
1011
npm-debug.log*
1112
yarn-debug.log*
1213
yarn-error.log*

src/store/mutations.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,13 @@ 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)
204+
},
205+
[types.ADD_TO_COMPONENT_STATE]: (state, payload) => {
206+
state.componentMap[state.activeComponent].componentState.push(payload)
207+
202208
},
203209
[types.ADD_USER_ACTION]: (state, payload) => {
204210
if (typeof(payload)==='string') state.userActions.push(payload);

src/store/state/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const newState = {
2323
HomeView: []
2424
// NewView: []
2525
},
26+
userActions: [],
27+
userState: {},
2628
/**
2729
*
2830
*/

src/store/types.js

Lines changed: 2 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_TO_COMPONENT_ACTIONS = 'ADD_TO_COMPONENT_ACTIONS'
45+
export const ADD_TO_COMPONENT_STATE = 'ADD_TO_COMPONENT_STATE'
4446
export const ADD_USER_ACTION = 'ADD_USER_ACTION'
4547
export const ADD_TO_USER_STORE = 'ADD_TO_USER_STORE'
4648

test/jest/__tests__/App.spec.js

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { mount, createLocalVue, shallowMount } from '@vue/test-utils'
77
import Vuex from 'vuex';
88
import QBUTTON from './demo/QBtn-demo.vue'
99
import * as All from 'quasar'
10-
1110
// import langEn from 'quasar/lang/en-us' // change to any language you wish! => this breaks wallaby :(
1211
const { Quasar, date } = All
1312

@@ -22,50 +21,37 @@ const components = Object.keys(All).reduce((object, key) => {
2221
}
2322
return object
2423
}, {})
25-
/*
26-
describe('Mount Quasar', () => {
27-
const localVue = createLocalVue()
28-
localVue.use(Quasar, { components }) // , lang: langEn
29-
30-
const wrapper = mount(QBUTTON, {
31-
localVue
32-
})
33-
const vm = wrapper.vm
34-
35-
it('passes the sanity check and creates a wrapper', () => {
36-
expect(wrapper.isVueInstance()).toBe(true)
37-
})
38-
39-
it('has a created hook', () => {
40-
expect(typeof vm.increment).toBe('function')
41-
})
4224

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-
})
48-
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)
25+
describe('Adding actions and state to components', () => {
26+
let state;
27+
beforeEach(() => {
28+
state = {
29+
componentMap: {
30+
testComponent: {
31+
componentName: 'testComponent',
32+
children: [],
33+
htmlList: [],
34+
componentActions: [],
35+
componentState: []
36+
}
37+
},
38+
activeComponent: 'testComponent'
39+
}
5340
})
54-
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)
41+
describe('Adding actions to components', () => {
42+
it('should add a single action to active component', () => {
43+
mutations.ADD_TO_COMPONENT_ACTIONS(state, 'testAction')
44+
expect(state.componentMap[state.activeComponent].componentActions).toEqual(['testAction'])
45+
})
5946
})
60-
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)
47+
describe('Adding state to components', () => {
48+
it('should add a single state string to active component', () => {
49+
mutations.ADD_TO_COMPONENT_STATE(state, 'testState')
50+
expect(state.componentMap[state.activeComponent].componentState).toEqual(['testState'])
51+
})
6652
})
6753
})
68-
*/
54+
6955
describe('userActions mutation', () => {
7056
let actions;
7157
let store;
@@ -112,4 +98,4 @@ describe('userStore mutation', () => {
11298
mutations.ADD_TO_USER_STORE(store, { string: 'string'})
11399
expect(store.userStore.string).toBe('string')
114100
})
115-
});
101+
});

test/jest/coverage/clover.xml

Lines changed: 34 additions & 34 deletions
Large diffs are not rendered by default.

test/jest/coverage/coverage-final.json

Lines changed: 35 additions & 0 deletions
Large diffs are not rendered by default.

test/jest/coverage/lcov-report/src/components/CodeSnippet.vue.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ <h1>
432432
font-size: 12px;
433433
}
434434
.codesnippet-container {
435-
margin-bottom: 1rem;
435+
margin-bottom: 1rem;
436436
}
437437
::-webkit-scrollbar {
438438
display: none;

test/jest/coverage/lcov-report/src/components/ComponentDisplay.vue.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ <h1>
615615
},
616616
<span class="fstat-no" title="function not covered" > childList () {</span>
617617
<span class="cstat-no" title="statement not covered" > return this.componentMap[componentData.componentName].children</span>
618-
},
618+
},
619619
<span class="fstat-no" title="function not covered" > options () {</span>
620620
// PROBLEM: the objects on childrenmultiselectvalue are applied
621621
<span class="cstat-no" title="statement not covered" > const routes = Object.keys(this.routes)</span>

test/jest/coverage/lcov-report/src/components/Footer.vue.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,11 @@ <h1>
456456
background: #11120F;
457457
}
458458
.toolbar-background {
459-
background: black;
459+
background: black;
460460
}
461461
.full-footer {
462462
// height: 100vh;
463-
padding-bottom: 0px;
463+
padding-bottom: 0px;
464464
}
465465
&lt;/style&gt;
466466
&nbsp;</pre></td></tr>

0 commit comments

Comments
 (0)