1
1
import { mount , shallowMount } from "@vue/test-utils" ;
2
2
import App from "../App" ;
3
+ import * as configFns from "../../lib/configuration" ;
3
4
import { TITLE_EMOJI_REGEX } from "../../utils/constants.js" ;
4
5
5
6
// Mock dashboard data
@@ -111,9 +112,19 @@ describe("Number card", () => {
111
112
} ) ;
112
113
113
114
test ( "onSaveSettings method" , ( ) => {
114
- const { vm } = shallowMountApp ( ) ;
115
+ jest . spyOn ( configFns , "saveDashboard" ) ;
116
+ const wrapper = shallowMountApp ( ) ;
117
+
118
+ wrapper . vm . dashboard . editMode = "unlocked" ;
119
+
120
+ wrapper . find ( { name : "dashboard-settings" } ) . vm . $emit ( "save-settings" , {
121
+ bgColor : "#fff" ,
122
+ bgImageRepeat : true ,
123
+ bgImageUrl : "" ,
124
+ title : "\u2700 IoT Dashboard"
125
+ } ) ;
115
126
116
- expect ( vm . dashboard ) . toEqual (
127
+ expect ( wrapper . vm . dashboard ) . toEqual (
117
128
expect . objectContaining ( {
118
129
bgColor : expect . any ( String ) ,
119
130
bgImageRepeat : expect . any ( Boolean ) ,
@@ -124,30 +135,7 @@ describe("Number card", () => {
124
135
title : expect . any ( String )
125
136
} )
126
137
) ;
127
-
128
- vm . onSaveSettings ( event => {
129
- event = {
130
- bgColor : "#fff" ,
131
- bgImageRepeat : true ,
132
- bgImageUrl : "" ,
133
- title : "\u2700 IoT Dashboard"
134
- } ;
135
- expect ( vm . saveDashboard ) . toHaveBeenCalled ( ) ;
136
- } ) ;
137
-
138
- Vue . nextTick ( ( ) => {
139
- expect ( vm . dashboard ) . toEqual (
140
- expect . objectContaining ( {
141
- bgColor : expect . any ( String ) ,
142
- bgImageRepeat : expect . any ( Boolean ) ,
143
- bgImageUrl : expect . any ( String ) ,
144
- blockSize : expect . any ( Array ) ,
145
- editMode : expect . any ( String ) ,
146
- tiles : expect . any ( Array ) ,
147
- title : expect . any ( String )
148
- } )
149
- ) ;
150
- } ) ;
138
+ expect ( configFns . saveDashboard ) . toHaveBeenCalled ( ) ;
151
139
} ) ;
152
140
153
141
test ( "onTileChange method" , ( ) => {
@@ -159,7 +147,6 @@ describe("Number card", () => {
159
147
160
148
vm . onTileChange ( event => {
161
149
event . id = mockDashboardData . dashboard . tiles [ 0 ] . id ;
162
- expect ( vm . saveDashboard ) . toHaveBeenCalled ( ) ;
163
150
} ) ;
164
151
165
152
expect ( vm . dashboard . tiles [ 0 ] ) . toEqual ( {
@@ -188,44 +175,42 @@ describe("Number card", () => {
188
175
} ) ;
189
176
190
177
test ( "onTileCreate method" , ( ) => {
191
- const { vm } = shallowMountApp ( ) ;
178
+ jest . spyOn ( configFns , "saveDashboard" ) ;
179
+ const wrapper = shallowMountApp ( ) ;
192
180
193
- vm . onTileCreate ( event => {
194
- event = {
195
- buttonText : "begin" ,
196
- deviceId : "DH7643" ,
197
- deviceMethod : "halt" ,
198
- id : "8071d5ab-0z12-41i3-ba9p-f600124feb6b" ,
199
- position : [ 106 , 266 ] ,
200
- size : [ 0.9 , 0.3 ] ,
201
- title : "MSchip receiving" ,
202
- type : "button"
203
- } ;
181
+ wrapper . find ( { name : "dashboard-settings" } ) . vm . $emit ( "tile-create" , {
182
+ deviceId : "" ,
183
+ id : "2ece272b-a403-46d6-b136-e35906fe1d0d" ,
184
+ lineColor : "#FF6384" ,
185
+ position : [ 0 , 0 ] ,
186
+ property : "" ,
187
+ size : [ 2 , 1.5 ] ,
188
+ title : "Line Chart" ,
189
+ type : "line-chart"
204
190
} ) ;
205
191
206
- expect ( vm . dashboard . tiles . length ) . toBe ( 3 ) ;
192
+ expect ( configFns . saveDashboard ) . toHaveBeenCalled ( ) ;
193
+ expect ( wrapper . vm . dashboard . tiles . length ) . toBe ( 3 ) ;
207
194
} ) ;
208
195
209
- test ( "onDeviceListRecieved method" , ( ) => {
196
+ test ( "onDeviceListReceived method" , ( ) => {
210
197
const { vm } = shallowMountApp ( ) ;
211
- const io = jest . fn ( ) ;
212
- const socket = io ( ) ;
198
+ let deviceList ;
213
199
214
- vm . onDeviceListReceived ( ( ) => {
215
- expect ( socket ) . toHaveBeenCalled ( ) ;
216
- } ) ;
200
+ vm . onDeviceListReceived ( deviceList ) ;
201
+
202
+ expect ( deviceList ) . toEqual ( vm . deviceList ) ;
203
+
204
+ // TODO: test socket.on callback function
217
205
} ) ;
218
206
219
- test ( "the getDashboard and getDeviceList functions in the created lifecycle hook" , ( ) => {
220
- const { vm } = mount ( App , {
221
- methods : {
222
- getDashboard : ( ) => mockDashboardData . dashboard ,
223
- getDeviceList : ( ) => mockDeviceList
224
- }
225
- } ) ;
207
+ test ( "the getDashboard and getDeviceList are invoked in the created lifecycle hook" , ( ) => {
208
+ jest . spyOn ( configFns , "getDashboard" ) ;
209
+ jest . spyOn ( configFns , "getDeviceList" ) ;
210
+ mount ( App ) ;
226
211
227
- expect ( vm . getDashboard ( ) ) . toEqual ( mockDashboardData . dashboard ) ;
228
- expect ( vm . getDeviceList ( ) ) . toEqual ( mockDeviceList ) ;
212
+ expect ( configFns . getDashboard ) . toHaveBeenCalled ( ) ;
213
+ expect ( configFns . getDeviceList ) . toHaveBeenCalled ( ) ;
229
214
} ) ;
230
215
} ) ;
231
216
0 commit comments