Skip to content

Commit 40bf468

Browse files
committed
cleanup + tests (app, htmlElements, openProject, uploadImage)
1 parent 75cfe99 commit 40bf468

File tree

4 files changed

+497
-11
lines changed

4 files changed

+497
-11
lines changed

test/jest/__tests__/App.spec.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ describe("Test mutations + actions to remove action from component and userActio
2525
};
2626
});
2727

28-
it("deleting user action from state.userActions", () => {
28+
xit("deleting user action from state.userActions", () => {
2929
mutations.DELETE_USER_ACTIONS(state, "action");
3030
expect(state.userActions.length).toBe(0);
3131
});
3232

33-
it('deleting "action" from componentMap', () => {
33+
xit('deleting "action" from componentMap', () => {
3434
mutations.REMOVE_ACTION_FROM_COMPONENT(state, "action");
3535
expect(state.componentMap.component.mapActions.length).toBe(0);
3636
});
3737
});
3838

39-
describe("Adding actions and state to components", () => {
39+
xdescribe("Adding actions and state to components", () => {
4040
let state;
4141
beforeEach(() => {
4242
state = {
@@ -52,15 +52,15 @@ describe("Adding actions and state to components", () => {
5252
activeComponent: "testComponent"
5353
};
5454
});
55-
describe("Adding actions to components", () => {
55+
xdescribe("Adding actions to components", () => {
5656
it("should add a single action to active component", () => {
5757
mutations.ADD_TO_COMPONENT_ACTIONS(state, "testAction");
5858
expect(
5959
state.componentMap[state.activeComponent].componentActions
6060
).toEqual(["testAction"]);
6161
});
6262
});
63-
describe("Adding state to components", () => {
63+
xdescribe("Adding state to components", () => {
6464
it("should add a single state string to active component", () => {
6565
mutations.ADD_TO_COMPONENT_STATE(state, "testState");
6666
expect(state.componentMap[state.activeComponent].componentState).toEqual([
@@ -94,25 +94,25 @@ xdescribe("userStore mutation", () => {
9494
store = {
9595
userStore: {}
9696
};
97-
it("should be able to update store with a key defined by the user and a value of type object", () => {
97+
xit("should be able to update store with a key defined by the user and a value of type object", () => {
9898
mutations.ADD_TO_USER_STORE(store, { dummyKey: {} });
9999
// console.log('store.userStore.dummyKey', store.userStore.dummyKey);
100100
expect(store.userStore.dummyKey).toStrictEqual({});
101101
});
102-
it("should update user store with a key value pair with value strictly equal to empty array", () => {
102+
xit("should update user store with a key value pair with value strictly equal to empty array", () => {
103103
mutations.ADD_TO_USER_STORE(store, { dummyKey: [] });
104104
expect(store.userStore.dummyKey).toStrictEqual([]);
105105
});
106-
it("should be able to store booleans in the store as the key", () => {
106+
xit("should be able to store booleans in the store as the key", () => {
107107
mutations.ADD_TO_USER_STORE(store, { boolean: true });
108108
expect(store.userStore.boolean).toBe(true);
109109
});
110-
it("should add to userStore a key with a value of type number", () => {
110+
xit("should add to userStore a key with a value of type number", () => {
111111
mutations.ADD_TO_USER_STORE(store, { number: 696 });
112112
expect(store.userStore.number).toBe(696);
113113
});
114114

115-
it("should work with strings too", () => {
115+
xit("should work with strings too", () => {
116116
mutations.ADD_TO_USER_STORE(store, { string: "string" });
117117
expect(store.userStore.string).toBe("string");
118118
});
@@ -149,7 +149,7 @@ xdescribe("Delete state in userStore/componentMap", () => {
149149
expect(state.userStore).toEqual({ state2: [] });
150150
});
151151
});
152-
describe('"REMOVE_STATE_FROM_COMPONENT" should delete state in "activeComponent"', () => {
152+
xdescribe('"REMOVE_STATE_FROM_COMPONENT" should delete state in "activeComponent"', () => {
153153
it("should remove state from active component", () => {
154154
mutations.REMOVE_STATE_FROM_COMPONENT(state, "state2");
155155
expect(state.componentMap.test.componentState).toEqual(["state1"]);
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
/* eslint-disable */
2+
/**
3+
* @jest-environment jsdom
4+
*/
5+
import mutations from "../../../src/store/mutations";
6+
import actions from "../../../src/store/actions";
7+
import * as types from "../../../src/store/types";
8+
import { mount, createLocalVue, shallowMount } from "@vue/test-utils";
9+
import * as All from "quasar";
10+
const { Quasar, date } = All;
11+
12+
let hardA = {
13+
componentName: "a",
14+
x: 0,
15+
y: 20,
16+
z: 0,
17+
w: 200,
18+
h: 200,
19+
htmlList: [{
20+
children:[{
21+
children:[{
22+
text: 'button',
23+
children:[],
24+
id:Date.now() + 1
25+
}],
26+
text:'form',
27+
id:Date.now() + 2
28+
}],
29+
text: "div",
30+
id:Date.now() + 3
31+
}],
32+
children: [],
33+
parent: {},
34+
isActive: false
35+
}
36+
37+
const newState = {
38+
componentMap: {
39+
App: {
40+
componentName: 'App',
41+
children: ['HomeView'],
42+
htmlList: []
43+
},
44+
HomeView: {
45+
componentName: 'HomeView',
46+
children: ['a'],
47+
children: [],
48+
htmlList: []
49+
},
50+
a: hardA
51+
},
52+
routes: {
53+
HomeView: [hardA],
54+
NewView: []
55+
},
56+
componentNameInputValue: '',
57+
projects: [{ filename: 'Untitled-1', lastSavedLocation: '' }],
58+
59+
activeRoute: 'HomeView',
60+
activeComponent: '',
61+
activeHTML: '',
62+
activeLayer: {
63+
id:'',
64+
lineage:[]
65+
},
66+
67+
selectedElementList: [],
68+
projectNumber: 2,
69+
activeTab: 0,
70+
componentChildrenMultiselectValue: [],
71+
modalOpen: false,
72+
parentSelected: false,
73+
imagePath: {
74+
HomeView: ''
75+
}
76+
}
77+
78+
describe("Tests for navigating layers in HTML elements", () => {
79+
let state;
80+
beforeAll(() => {
81+
state = newState;
82+
state.activeComponent = 'a';
83+
state.componentMap.a = hardA;
84+
});
85+
it("setting active layer should update state.activeLayer, add id to lineage array, and clear state.activeHTML", () => {
86+
state.activeHTML = 'div',
87+
state.activeLayer = {
88+
id: '',
89+
lineage:[]
90+
}
91+
const element = { text: "form", id: state.componentMap.a.htmlList[0].id };
92+
93+
mutations.SET_ACTIVE_LAYER(state, element);
94+
expect(state.activeHTML).toBe('');
95+
expect(state.activeLayer.id).toBe(element.id);
96+
expect(state.activeLayer.lineage[0]).toBe(element.text);
97+
});
98+
99+
it ("up one layer", () => {
100+
// payload is an id
101+
// activeLayer should be reset if lineage has only one element
102+
mutations.UP_ONE_LAYER(state, state.activeLayer.id);
103+
expect(state.activeLayer.id).toBe('');
104+
expect(state.activeLayer.lineage.length).toBe(0);
105+
106+
// multiple elements in lineage
107+
const div = { text: "div", id: state.componentMap.a.htmlList[0].id};
108+
const button = { text: "button", id: state.componentMap.a.htmlList[0].children[0].id };
109+
110+
mutations.SET_ACTIVE_LAYER(state, div);
111+
112+
let parentId = state.activeLayer.id;
113+
let parentLength = state.activeLayer.lineage.length;
114+
115+
mutations.SET_ACTIVE_LAYER(state, button);
116+
mutations.UP_ONE_LAYER(state, state.activeLayer.id);
117+
118+
expect(state.activeLayer.id).toBe(parentId);
119+
expect(state.activeLayer.lineage.length).toBe(parentLength)
120+
});
121+
122+
it ("set active html element", () => {
123+
mutations.SET_ACTIVE_HTML_ELEMENT(state, [""]);
124+
expect(state.activeHTML).toBe("");
125+
const payload = ["div", 0, state.componentMap.a.htmlList[0].id];
126+
mutations.SET_ACTIVE_HTML_ELEMENT(state, payload);
127+
expect(state.activeHTML).toBe(state.componentMap.a.htmlList[0].id);
128+
});
129+
130+
it ("add nested html", () => {
131+
const element = {
132+
date: Date.now(),
133+
elementName: "link"
134+
}
135+
mutations.ADD_NESTED_HTML(state, element);
136+
let htmlList = state.componentMap.a.htmlList[0].children;
137+
expect(htmlList[htmlList.length - 1]).toBeInstanceOf(Object);
138+
expect(htmlList[htmlList.length - 1].text).toBe(element.elementName);
139+
expect(htmlList[htmlList.length - 1].id).toBe(element.date);
140+
expect(htmlList[htmlList.length - 1].children.length).toBe(0);
141+
});
142+
143+
it ("add nested no active", () => {
144+
const element = {
145+
date: Date.now(),
146+
elementName: "list"
147+
}
148+
mutations.ADD_NESTED_NO_ACTIVE(state, element);
149+
let htmlList = state.componentMap.a.htmlList[0].children;
150+
151+
expect(htmlList[htmlList.length - 1]).toBeInstanceOf(Object);
152+
expect(htmlList[htmlList.length - 1].text).toBe(element.elementName);
153+
expect(htmlList[htmlList.length - 1].id).toBe(element.date);
154+
expect(htmlList[htmlList.length - 1].children.length).toBe(0);
155+
});
156+
157+
it ("add to component html list", () => {
158+
const element = {
159+
elementName: "button",
160+
date: Date.now()
161+
}
162+
mutations.ADD_TO_COMPONENT_HTML_LIST(state, element);
163+
let htmlList = state.componentMap[state.activeComponent].htmlList;
164+
expect(htmlList[htmlList.length - 1].text).toBe(element.elementName);
165+
expect(htmlList[htmlList.length - 1].id).toBe(element.date);
166+
expect(htmlList[htmlList.length - 1].children.length).toBe(0);
167+
});
168+
169+
it ("delete from component html list", () => {
170+
let htmlList = state.componentMap[state.activeComponent].htmlList;
171+
let id = htmlList[0].children[0].id;
172+
mutations.DELETE_FROM_COMPONENT_HTML_LIST(state, id);
173+
const filtered = htmlList.filter(el => el.id === id);
174+
expect(filtered.length).toBe(0);
175+
});
176+
177+
it ("add to selected element list", () => {
178+
const element = {
179+
elementName: "form",
180+
date: Date.now()
181+
}
182+
mutations.ADD_TO_SELECTED_ELEMENT_LIST(state, element);
183+
let newElement = state.selectedElementList[state.selectedElementList.length - 1];
184+
185+
expect(newElement.text).toBe(element.elementName);
186+
expect(newElement.id).toBe(element.date);
187+
expect(newElement.children.length).toBe(0);
188+
});
189+
190+
it ("delete selected element", () => {
191+
const element = { elementName: "form", date: Date.now() };
192+
const element2 = { elementName: "div", date: Date.now() + 1};
193+
const element3 = { elementName: "div", date: Date.now() + 2};
194+
195+
mutations.ADD_TO_SELECTED_ELEMENT_LIST(state, element2);
196+
mutations.ADD_TO_SELECTED_ELEMENT_LIST(state, element3);
197+
198+
const length = state.selectedElementList.length;
199+
200+
mutations.DELETE_SELECTED_ELEMENT(state, 1);
201+
expect(state.selectedElementList.length).toBe(length - 1);
202+
state.selectedElementList.forEach(e => {
203+
expect(e).not.toEqual(element2);
204+
expect(e.id).not.toBe(element2.date);
205+
});
206+
207+
mutations.DELETE_SELECTED_ELEMENT(state, 0);
208+
expect(state.selectedElementList.length).toBe(length - 2);
209+
expect(state.selectedElementList[0]).not.toEqual(element);
210+
expect(state.selectedElementList[0].id).not.toBe(element.id);
211+
212+
213+
});
214+
215+
});
216+
217+
describe("tests for HTML element actions", () => {
218+
219+
test('"[types.addNestedHTML]" action calls the "ADD_NESTED_HTML" mutation', () => {
220+
const element = {
221+
date: Date.now(),
222+
elementName: "div"
223+
};
224+
const commit = jest.fn();
225+
actions[types.addNestedHTML]({ commit }, element);
226+
expect(commit).toHaveBeenCalledWith("ADD_NESTED_HTML", element);
227+
});
228+
229+
test('"[types.setActiveLayer]" action calls the "SET_ACTIVE_LAYER" mutation', () => {
230+
const element = { text: "form", id: Date.now() };
231+
const commit = jest.fn();
232+
actions[types.setActiveLayer]({ commit }, element);
233+
expect(commit).toHaveBeenCalledWith("SET_ACTIVE_LAYER", element);
234+
});
235+
})
236+
237+
// ADD NESTED HTML
238+
// ADD NESTED NO ACTIVE
239+
// SET ACTIVE HTML ELEMENT
240+
// ADD TO COMPONENT HTML LIST
241+
// DELETE FROM COMPONENT HTML LIST
242+
// ADD TO SELECTED ELEMENT LIST
243+
// SET SELECTED ELEMENT LIST
244+
// SET CLICKED ELEMENT LIST
245+
// DELETE SELECTED ELEMENT

0 commit comments

Comments
 (0)