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