Skip to content

Commit 99a09a3

Browse files
committed
Merge branch 'dev' into jace/sandbox
2 parents 4e00ac7 + 9239603 commit 99a09a3

File tree

5 files changed

+235
-15
lines changed

5 files changed

+235
-15
lines changed

src/components/left-sidebar/ComponentTab/CreateMenuHTMLQueue.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,17 @@ export default {
106106
},
107107
//METHODS FOR DRAG-AND-DROP
108108
startDrag (event, id) {
109-
//add a class of 'currentlyDragging' to the HTML element that you are currently dragging
109+
//add a class to make the html element currently being drag transparent
110110
event.target.classList.add('currentlyDragging')
111111
const dragId = id;
112+
//store the id of dragged element
112113
if (this.activeComponent === '') this.setSelectedIdDrag(dragId)
113114
else this.setIdDrag(dragId)
114115
},
115116
dragEnter (event, id) {
116117
event.preventDefault();
117118
const dropId = id;
119+
//store the id of the html element whose location the dragged html element could be dropped upon
118120
if (this.activeComponent === '') this.setSelectedIdDrop(dropId)
119121
else this.setIdDrop(dropId)
120122
},
@@ -123,7 +125,7 @@ export default {
123125
event.preventDefault();
124126
},
125127
endDrag (event) {
126-
//remove the 'currentlyDragging' class after the HTML is dropped
128+
//remove the 'currentlyDragging' class after the HTML is dropped to remove transparency
127129
event.preventDefault();
128130
event.target.classList.remove('currentlyDragging')
129131
//invoke the action that will use the idDrag and idDrop to sort the HtmlList

src/components/left-sidebar/ComponentTab/Icons.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Description:
1414
<br />
1515
<span>{{ elementName }}</span>
1616
</button>
17-
<!-- Child Component Icons-->
17+
<!-- Icons for activeComponent's Child Components-->
1818
<button
1919
@click.prevent="changeState(elementName)"
2020
v-for="(elementName, idx) in childrenComp"
@@ -27,7 +27,6 @@ Description:
2727
<span>{{ elementName }}</span>
2828
</button>
2929

30-
3130
</section>
3231
</template>
3332

src/components/right-sidebar/HTMLQueue.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export default {
9494
})
9595
return newTitle;
9696
},
97+
//make child components in htmlList exceptions
9798
moreExceptions: function () {
9899
let childComponent = [];
99100
if(this.activeComponent) {
@@ -141,15 +142,17 @@ export default {
141142
},
142143
//METHODS FOR DRAG-AND-DROP
143144
startDrag(event, id) {
144-
//add a class of 'currentlyDragging' to the HTML element that you are currently dragging
145+
//add a class to make the html element currently being drag transparent
145146
event.target.classList.add('currentlyDragging')
146147
const dragId = id;
148+
//store the id of dragged element
147149
if (this.activeComponent === '') this.setSelectedIdDrag(dragId)
148150
else this.setIdDrag(dragId)
149151
},
150152
dragEnter(event, id) {
151153
event.preventDefault();
152154
const dropId = id;
155+
//store the id of the html element whose location the dragged html element could be dropped upon
153156
if (this.activeComponent === '') this.setSelectedIdDrop(dropId)
154157
else this.setIdDrop(dropId)
155158
},
@@ -158,7 +161,7 @@ export default {
158161
event.preventDefault();
159162
},
160163
endDrag(event) {
161-
//remove the 'currentlyDragging' class after the HTML is dropped
164+
//remove the 'currentlyDragging' class after the HTML is dropped to remove transparency
162165
event.preventDefault();
163166
event.target.classList.remove('currentlyDragging')
164167
//invoke the action that will use the idDrag and idDrop to sort the HtmlList

src/store/mutations.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ const mutations = {
330330
}
331331
}
332332
}
333-
//update the component name in the htmlList of all components if it is a child component
333+
//update the the htmlList, find child components within the htmlLists with the old value, update it to the new value
334334
for (const item of Object.values(state.componentMap)) {
335335
if (item.htmlList) {
336336
const newArray = [...item.htmlList];
@@ -522,25 +522,26 @@ const mutations = {
522522
}
523523
state.activeHTML = "";
524524
},
525-
525+
//Drag-andDrop
526+
//store id of dragged html element in activeComponent
526527
[types.SET_ID_DRAG]: (state, payload) => {
527528
const componentName = state.activeComponent;
528529
state.componentMap[componentName].idDrag = payload;
529530
},
530-
531+
//store id of html element whose place the dragged html element is dropped on in activeComponent
531532
[types.SET_ID_DROP]: (state, payload) => {
532533
const componentName = state.activeComponent;
533534
state.componentMap[componentName].idDrop = payload;
534535
},
535-
536+
//store id of dragged selected html element when creating a component
536537
[types.SET_SELECTED_ID_DRAG]: (state, payload) => {
537538
state.selectedIdDrag = payload;
538539
},
539-
540+
//store id of html element whose place the dragged selected html element will be dropped when creating a component
540541
[types.SET_SELECTED_ID_DROP]: (state, payload) => {
541542
state.selectedIdDrop = payload;
542543
},
543-
544+
// use idDrag and idDrop to rearrange the htmlList of the activeComponent to perform drag-and-drop functionality
544545
[types.DRAG_DROP_SORT_HTML_ELEMENTS]: (state) => {
545546
const componentName = state.activeComponent;
546547
const idDrag = state.componentMap[componentName].idDrag;
@@ -552,27 +553,32 @@ const mutations = {
552553
const htmlList = state.componentMap[componentName].htmlList.slice(0)
553554

554555
if (state.activeLayer.id === "") {
556+
//find the indexes belonging to the html elements with idDrag and idDrop
555557
htmlList.forEach((el, i) => {
556558
if (el.id === idDrag) {
557559
indexDrag = i;
558560
} else if (el.id === idDrop) {
559561
indexDrop = i;
560562
}
561563
})
564+
//use the indexes to rearrange htmlList
562565
const draggedEl = htmlList.splice(indexDrag, 1)[0]
563566
htmlList.splice(indexDrop, 0, draggedEl)
564567
} else {
568+
//Use breadFirstSearchParent to find the parent and indexes of nested html elements with idDrag and idDrop
565569
const nestedDrag = breadthFirstSearchParent(htmlList, idDrag);
566570
const nestedDrop = breadthFirstSearchParent(htmlList, idDrop);
571+
//use the indexes and parents to rearrange htmlList
567572
let nestedEl = nestedDrag.evaluated.children.splice(nestedDrag.index, 1)[0]
568573
nestedDrop.evaluated.children.splice(nestedDrop.index, 0, nestedEl)
569574
}
570575
state.componentMap[componentName].htmlList = htmlList;
571576
}
577+
//reset the ids
572578
state.componentMap[componentName].idDrag = '';
573579
state.componentMap[componentName].idDrop = '';
574580
},
575-
581+
// use selectedIdDrag and selectedIdDrop to rearrange the selectedElementList to perform drag-and-drop functionality
576582
[types.DRAG_DROP_SORT_SELECTED_HTML_ELEMENTS]: (state) => {
577583
const selectedIdDrag = state.selectedIdDrag;
578584
const selectedIdDrop = state.selectedIdDrop;
@@ -582,19 +588,20 @@ const mutations = {
582588

583589
let indexDrag;
584590
let indexDrop;
585-
591+
//find the indexes belonging to the html elements with the selectedIdDrag and selectedIdDrop
586592
htmlList.forEach((el, i) => {
587593
if (el.id === selectedIdDrag) {
588594
indexDrag = i;
589595
} else if (el.id === selectedIdDrop) {
590596
indexDrop = i;
591597
}
592598
})
593-
599+
//use the indexes to delete the dragged element and place them into the new location
594600
const draggedEl = htmlList.splice(indexDrag, 1)[0]
595601
htmlList.splice(indexDrop, 0, draggedEl)
596602
state.selectedElementList = htmlList;
597603
}
604+
//reset the ids
598605
state.selectedIdDrag = '';
599606
state.selectedIdDrop = '';
600607
},
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
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+
import { iterate } from "localforage";
11+
const { Quasar, date } = All;
12+
13+
/**
14+
* @description: Testing mutations and actions related to the Drag and Drop functionality of html elements
15+
* in the HTMLQueue and the CreateMenuHTMLQueue components.
16+
* `actions:` `setIdDrag', `setIdDrop`, `setSelectedIdDrag`, `setSelectedIdDrop`,
17+
* `dragDropSortHtmlElements`, `dragDropSortSelectedHtmlElements`
18+
* `mutations: SET_ID_DRAG, SET_ID_DROP, SET_SELECTED_ID_DRAG, SET_SELECTED_ID_DROP,
19+
* DRAG_DROP_SORT_HTML_ELEMENTS, DRAG_DROP_SORT_SELECTED_HTML_ELEMENTS
20+
*/
21+
let aHtmlList = [{
22+
text: 'div',
23+
children:[],
24+
id:Date.now() + 1
25+
},
26+
{
27+
children:[],
28+
text:'img',
29+
id:Date.now() + 2
30+
},
31+
{
32+
children:[],
33+
text: 'paragraph',
34+
id:Date.now() + 3
35+
}]
36+
37+
let hardA = {
38+
componentName: "a",
39+
htmlList: [...aHtmlList],
40+
children: [],
41+
parent: {},
42+
isActive: false,
43+
idDrag: '',
44+
idDrop: ''
45+
}
46+
47+
const newState = {
48+
componentMap: {
49+
App: {
50+
componentName: 'App',
51+
children: ['HomeView'],
52+
htmlList: []
53+
},
54+
HomeView: {
55+
componentName: 'HomeView',
56+
children: ['a'],
57+
children: [],
58+
htmlList: []
59+
},
60+
a: hardA
61+
},
62+
routes: {
63+
HomeView: [hardA],
64+
NewView: []
65+
},
66+
componentNameInputValue: '',
67+
activeRoute: 'HomeView',
68+
activeComponent: '',
69+
activeHTML: '',
70+
activeLayer: {
71+
id:'',
72+
lineage:[]
73+
},
74+
selectedIdDrag: '',
75+
selectedIdDrop: '',
76+
selectedElementList: [],
77+
}
78+
79+
describe("Tests for html elements drag-and-drop functionality", () => {
80+
81+
describe("Test drag and drop functionality in active components", () => {
82+
let state;
83+
beforeEach(() => {
84+
state = newState;
85+
state.activeComponent = 'a';
86+
hardA.htmlList = aHtmlList;
87+
state.componentMap.a = hardA;
88+
});
89+
90+
afterEach(() => {
91+
state = newState;
92+
state.activeComponent = 'a';
93+
hardA.htmlList = aHtmlList;
94+
state.componentMap.a = hardA;
95+
});
96+
it("identify the id of the html element being dragged", () => {
97+
mutations[types.SET_ID_DRAG](state, hardA.htmlList[0].id);
98+
expect(state.componentMap[hardA.componentName].idDrag).toBe(hardA.htmlList[0].id);
99+
});
100+
101+
it("identify the id of the html element the dragged html element is dropped over", () => {
102+
mutations[types.SET_ID_DROP](state, hardA.htmlList[2].id);
103+
expect(state.componentMap[hardA.componentName].idDrop).toBe(hardA.htmlList[2].id);
104+
});
105+
106+
it("dropped html element is moved to location it was dropped", () => {
107+
mutations[types.SET_ID_DRAG](state, hardA.htmlList[0].id);
108+
mutations[types.SET_ID_DROP](state, hardA.htmlList[2].id);
109+
mutations[types.DRAG_DROP_SORT_HTML_ELEMENTS](state);
110+
expect(state.componentMap[hardA.componentName].htmlList[2].text).toBe('div');
111+
})
112+
113+
it("remainder html elements are still in order", () => {
114+
mutations[types.SET_ID_DRAG](state, hardA.htmlList[0].id);
115+
mutations[types.SET_ID_DROP](state, hardA.htmlList[2].id);
116+
mutations[types.DRAG_DROP_SORT_HTML_ELEMENTS](state);
117+
expect(state.componentMap[hardA.componentName].htmlList[0].text).toBe('img');
118+
expect(state.componentMap[hardA.componentName].htmlList[1].text).toBe('paragraph');
119+
expect(state.componentMap[hardA.componentName].htmlList[2].text).toBe('div');
120+
})
121+
122+
it("idDrag and idDrop is reset to '' ", () => {
123+
mutations[types.SET_ID_DRAG](state, hardA.htmlList[0].id);
124+
mutations[types.SET_ID_DROP](state, hardA.htmlList[2].id);
125+
mutations[types.DRAG_DROP_SORT_HTML_ELEMENTS](state);
126+
expect(state.componentMap[hardA.componentName].idDrag).toBe('');
127+
expect(state.componentMap[hardA.componentName].idDrop).toBe('');
128+
})
129+
130+
});
131+
132+
describe("Test drag and drop functionality in the CreateMenu", () => {
133+
let state;
134+
beforeEach(() => {
135+
state = newState;
136+
state.selectedElementList = [
137+
{
138+
text: 'div',
139+
children:[],
140+
id:Date.now() + 1
141+
},
142+
{
143+
children:[],
144+
text:'img',
145+
id:Date.now() + 2
146+
},
147+
{
148+
children:[],
149+
text: 'paragraph',
150+
id:Date.now() + 3
151+
}];
152+
});
153+
154+
afterEach(() => {
155+
state = newState;
156+
state.selectedElementList = [
157+
{
158+
text: 'div',
159+
children:[],
160+
id:Date.now() + 1
161+
},
162+
{
163+
children:[],
164+
text:'img',
165+
id:Date.now() + 2
166+
},
167+
{
168+
children:[],
169+
text: 'paragraph',
170+
id:Date.now() + 3
171+
}];
172+
});
173+
it("identify the id of the html element being dragged", () => {
174+
mutations[types.SET_SELECTED_ID_DRAG](state, state.selectedElementList[0].id);
175+
expect(state.selectedIdDrag).toBe(state.selectedElementList[0].id);
176+
177+
});
178+
179+
it("identify the id of the html element the dragged html element is dropped over", () => {
180+
mutations[types.SET_SELECTED_ID_DROP](state, state.selectedElementList[2].id);
181+
expect(state.selectedIdDrop).toBe(state.selectedElementList[2].id);
182+
});
183+
184+
it("dropped html element is moved to location it was dropped", () => {
185+
mutations[types.SET_SELECTED_ID_DRAG](state, state.selectedElementList[0].id);
186+
mutations[types.SET_SELECTED_ID_DROP](state, state.selectedElementList[2].id);
187+
mutations[types.DRAG_DROP_SORT_SELECTED_HTML_ELEMENTS](state);
188+
expect(state.selectedElementList[2].text).toBe('div');
189+
})
190+
191+
it("remainder html elements are still in order", () => {
192+
mutations[types.SET_SELECTED_ID_DRAG](state, state.selectedElementList[0].id);
193+
mutations[types.SET_SELECTED_ID_DROP](state, state.selectedElementList[2].id);
194+
mutations[types.DRAG_DROP_SORT_SELECTED_HTML_ELEMENTS](state);
195+
expect(state.selectedElementList[0].text).toBe('img');
196+
expect(state.selectedElementList[1].text).toBe('paragraph');
197+
expect(state.selectedElementList[2].text).toBe('div');
198+
})
199+
200+
it("selectedIdDDrag and selectedIdDrop is reset to '' ", () => {
201+
mutations[types.SET_SELECTED_ID_DRAG](state, state.selectedElementList[0].id);
202+
mutations[types.SET_SELECTED_ID_DROP](state, state.selectedElementList[2].id);
203+
mutations[types.DRAG_DROP_SORT_SELECTED_HTML_ELEMENTS](state);
204+
expect(state.selectedIdDrag).toBe('');
205+
expect(state.selectedIdDrop).toBe('');
206+
})
207+
});
208+
209+
})

0 commit comments

Comments
 (0)