Skip to content

Commit 518a0c6

Browse files
Dean OhashiDean Ohashi
authored andcommitted
added to test suite, updated types actions and mutations
1 parent a83d5ad commit 518a0c6

File tree

4 files changed

+44
-65
lines changed

4 files changed

+44
-65
lines changed

src/store/actions.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,18 @@ const actions = {
119119
[types.deleteRoute]: ({ state, commit }, payload) => {
120120
commit(types.DELETE_ROUTE, payload)
121121
},
122-
[types.deleteComponent]: ({state, commit }, payload) => {
122+
[types.deleteComponent]: ({ state, commit }, payload) => {
123123
console.log('payload in actions:', payload)
124124
commit(types.DELETE_COMPONENT, payload)
125+
},
126+
[types.deleteUserActions]: ({ state, commit }, payload) => {
127+
console.log('invoking deleteUserActions')
128+
if(state.activeComponent) commit(types.REMOVE_ACTION_FROM_COMPONENT, payload)
129+
commit(types.DELETE_USER_ACTIONS, payload)
130+
},
131+
[types.removeActionFromComponent]: ({ state, commit }, payload) => {
132+
console.log('invoking removeActionFromComponent')
133+
commit(types.REMOVE_ACTION_FROM_COMPONENT, payload)
125134
}
126135
}
127136

src/store/mutations.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,15 @@ const mutations = {
198198
delete state.componentMap[payload.componentName]
199199
state.routes[state.activeRoute] = compArr
200200
console.log('new state', state)
201-
201+
},
202+
[types.DELETE_USER_ACTIONS]: (state, payload) => {
203+
//payload should be a string of the name of the action to remove
204+
let index = state.userActions.indexOf(payload)
205+
state.userActions.splice(index, 1)
206+
},
207+
[types.REMOVE_ACTION_FROM_COMPONENT]: (state, payload) => {
208+
let index = state.componentMap[state.activeComponent].mapActions.indexOf(payload)
209+
state.componentMap[state.activeComponent].mapActions.splice(index, 1)
202210
}
203211
}
204212

src/store/types.js

Lines changed: 5 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 DELETE_USER_ACTIONS = 'DELETE_USER_ACTIONS'
45+
export const REMOVE_ACTION_FROM_COMPONENT = 'REMOVE_ACTION_FROM_COMPONENT'
4446

4547
// Actions
4648
export const registerComponent = 'registerComponent'
@@ -75,3 +77,6 @@ export const updateOpenModal = 'updateOpenModal'
7577
export const parentSelected = 'parentSelected'
7678
export const deleteRoute = 'deleteRoute'
7779
export const deleteComponent = 'deleteComponent'
80+
81+
export const deleteUserActions = 'deleteUserActions'
82+
export const removeActionFromComponent = 'removeActionFromComponent'

test/jest/__tests__/App.spec.js

Lines changed: 20 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,76 +4,33 @@
44
*/
55

66
import { mount, createLocalVue, shallowMount } from '@vue/test-utils'
7-
import QBUTTON from './demo/QBtn-demo.vue'
87
import * as All from 'quasar'
9-
// import langEn from 'quasar/lang/en-us' // change to any language you wish! => this breaks wallaby :(
108
const { Quasar, date } = All
119

12-
const components = Object.keys(All).reduce((object, key) => {
13-
const val = All[key]
14-
if (val && val.component && val.component.name != null) {
15-
object[key] = val
10+
import mutations from '../../../src/store/mutations';
11+
12+
describe('Test mutations to remove action from component and userActions', () => {
13+
const state = {
14+
componentMap: {
15+
component: {
16+
componentName: 'App',
17+
children: ['HomeView'],
18+
htmlList: [],
19+
mapActions: ['action']
20+
}
21+
},
22+
activeComponent: 'component',
23+
userActions: ['action']
1624
}
17-
return object
18-
}, {})
1925

20-
describe('Dummy test', () => {
21-
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+
it('deleting user action from state.userActions', () => {
27+
mutations.DELETE_USER_ACTIONS(state, 'action')
28+
expect(state.userActions.length).toBe(0);
2629
})
27-
})
2830

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)
31+
it('deleting "action" from componentMap', () => {
32+
mutations.REMOVE_ACTION_FROM_COMPONENT(state, 'action');
33+
expect(state.componentMap.component.mapActions.length).toBe(0)
3534
})
3635
})
3736

38-
// describe('Mount Quasar', () => {
39-
// const localVue = createLocalVue()
40-
// localVue.use(Quasar, { components }) // , lang: langEn
41-
42-
// const wrapper = mount(QBUTTON, {
43-
// localVue
44-
// })
45-
// const vm = wrapper.vm
46-
47-
// it('passes the sanity check and creates a wrapper', () => {
48-
// expect(wrapper.isVueInstance()).toBe(true)
49-
// })
50-
51-
// it('has a created hook', () => {
52-
// expect(typeof vm.increment).toBe('function')
53-
// })
54-
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-
// })
60-
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-
// })
66-
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-
// })
72-
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-
// })

0 commit comments

Comments
 (0)