Skip to content

Commit 69d47e2

Browse files
committed
delete state tests
1 parent c7d003e commit 69d47e2

File tree

6 files changed

+80
-98
lines changed

6 files changed

+80
-98
lines changed

src/store/actions.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,30 @@ const actions = {
136136
},
137137
[types.deleteUserActions]: ({ state, commit }, payload) => {
138138
console.log('invoking deleteUserActions')
139-
if (state.activeComponent) { commit(types.REMOVE_ACTION_FROM_COMPONENT, payload) }
139+
if (state.activeComponent) {
140+
commit(types.REMOVE_ACTION_FROM_COMPONENT, payload)
141+
}
140142
commit(types.DELETE_USER_ACTIONS, payload)
141143
},
142144
[types.removeActionFromComponent]: ({ state, commit }, payload) => {
143145
console.log('invoking removeActionFromComponent')
144146
commit(types.REMOVE_ACTION_FROM_COMPONENT, payload)
147+
},
148+
[types.removeStateFromComponent]: ({ commit }, payload) => {
149+
console.log('removeStateFromComponent invoked')
150+
commit(types.REMOVE_STATE_FROM_COMPONENT, payload)
151+
},
152+
[types.deleteUserState]: ({ state, commit }, payload) => {
153+
console.log('deleteUserState invoked')
154+
if (state.activeComponent) {
155+
commit(types.REMOVE_STATE_FROM_COMPONENT, payload)
156+
}
157+
// loops through component map and deletes all props
158+
Object.keys(state.componentMap).forEach(prop => {
159+
commit(types.SET_ACTIVE_COMPONENT, prop.componentName)
160+
commit(types.REMOVE_ACTION_FROM_COMPONENT, payload)
161+
})
162+
commit(types.DELETE_USER_STATE, payload)
145163
}
146164
}
147165

src/store/mutations.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ const mutations = {
236236
[types.ADD_TO_USER_STORE]: (state, payload) => {
237237
const key = Object.keys(payload)
238238
state.userStore[key] = payload[key]
239+
},
240+
[types.REMOVE_STATE_FROM_COMPONENT]: (state, payload) => {
241+
let prop = state.componentMap[state.activeComponent].componentState
242+
prop.splice(prop.indexOf(payload), 1)
243+
},
244+
[types.DELETE_USER_STATE]: (state, payload) => {
245+
delete state.userStore[payload]
239246
}
240247
}
241248

src/store/types.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export const ADD_TO_COMPONENT_ACTIONS = 'ADD_TO_COMPONENT_ACTIONS'
5050
export const ADD_TO_COMPONENT_STATE = 'ADD_TO_COMPONENT_STATE'
5151
export const ADD_USER_ACTION = 'ADD_USER_ACTION'
5252
export const ADD_TO_USER_STORE = 'ADD_TO_USER_STORE'
53+
export const REMOVE_STATE_FROM_COMPONENT = 'REMOVE_STATE_FROM_COMPONENT'
54+
export const DELETE_USER_STATE = 'DELETE_USER_STATE'
5355

5456
// Actions
5557
export const registerComponent = 'registerComponent'
@@ -92,3 +94,5 @@ export const deleteUserActions = 'deleteUserActions'
9294
export const removeActionFromComponent = 'removeActionFromComponent'
9395
export const addUserAction = 'addUserAction'
9496
export const addToUserStore = 'addToUserStore'
97+
export const removeStateFromComponent = 'removeStateFromComponent'
98+
export const deleteUserState = 'deleteUserState'

test/jest/__tests__/App.spec.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @jest-environment jsdom
44
*/
55
import mutations from "../../../src/store/mutations";
6+
import actions from "../../../src/store/actions";
67
import { mount, createLocalVue, shallowMount } from "@vue/test-utils";
78
import * as All from "quasar";
89
const { Quasar, date } = All;
@@ -116,3 +117,51 @@ describe("userStore mutation", () => {
116117
expect(store.userStore.string).toBe("string");
117118
});
118119
});
120+
121+
/**
122+
* @description: Tests for deleting state
123+
* @summary:
124+
* `deleteUserState` action invokes removeStateFromComponent
125+
* `removeStateFromComponent` mutation that deletes state from userStore
126+
* `userStore` holds the user defined state objects
127+
*/
128+
129+
describe("Delete state in userStore/componentMap", () => {
130+
let state;
131+
beforeEach(() => {
132+
state = {
133+
componentMap: {
134+
test: {
135+
componentName: "test",
136+
children: [],
137+
htmlList: [],
138+
componentActions: [],
139+
componentState: ["state1", "state2"]
140+
}
141+
},
142+
activeComponent: "test",
143+
userStore: { state1: true, state2: [] }
144+
};
145+
});
146+
describe('"DELETE_USER_STATE" should delete property from "userStore" object', () => {
147+
it("should delete a single state property", () => {
148+
mutations.DELETE_USER_STATE(state, "state1");
149+
expect(state.userStore).toEqual({ state2: [] });
150+
});
151+
});
152+
describe('"REMOVE_STATE_FROM_COMPONENT" should delete state in "activeComponent"', () => {
153+
it("should remove state from active component", () => {
154+
mutations.REMOVE_STATE_FROM_COMPONENT(state, "state2");
155+
expect(state.componentMap.test.componentState).toEqual(["state1"]);
156+
});
157+
});
158+
// describe('"deleteUserState" should delete state in "activeComponent" when deleted from "userStore"', () => {
159+
// const commit = jest.fn();
160+
// it("should remove state from active component", () => {
161+
// actions.deleteUserState({ commit }, "state2");
162+
// expect(state.componentMap[state.activeComponent].componentState).toEqual([
163+
// "state1"
164+
// ]);
165+
// });
166+
// });
167+
});

test/jest/__tests__/mutations.spec.js

Lines changed: 0 additions & 96 deletions
This file was deleted.

test/jest/__tests__/uploadImage.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import actions from "../../../src/store/actions";
2121
import mutations from "../../../src/store/mutations";
2222
import * as types from "../../../src/store/types";
2323
import Vuex from "vuex";
24-
// import store from "../../../src/store/state/index";
24+
import store from "../../../src/store/state/index";
2525

2626
/**
2727
* @description: Testing functionality of the uploadImage mutations and actions

0 commit comments

Comments
 (0)