@@ -27,6 +27,16 @@ import (
27
27
"github.com/stretchr/testify/mock"
28
28
)
29
29
30
+ const (
31
+ // mocked variable IDs
32
+ switchyID = "switchy-id"
33
+ relayID = "relay-id"
34
+ blinkSpeedID = "blink_speed-id"
35
+
36
+ thingOverriddenID = "thing-overridden-id"
37
+ switchyOverriddenID = "switchy-overridden-id"
38
+ )
39
+
30
40
var (
31
41
dashboardTemplateTest = map [string ]interface {}{
32
42
"id" : "home-security-alarm-dashboard" ,
69
79
Widgets : []iotclient.Widget {
70
80
{Name : "Switch-name" , Height : 1 , HeightMobile : 2 , Width : 3 , WidthMobile : 4 ,
71
81
X : 5 , XMobile : 6 , Y : 7 , YMobile : 8 , Options : map [string ]interface {}{"showLabels" : true }, Type : "Switch" ,
72
- // variable id is set equal to the thing id by mockThingShow, in order to verify the thing override
73
- Variables : []string {"thing" },
82
+ Variables : []string {switchyID },
74
83
},
75
84
},
76
85
}
@@ -80,26 +89,21 @@ var (
80
89
Widgets : []iotclient.Widget {
81
90
{Name : "Switch-name" , Height : 1 , HeightMobile : 2 , Width : 3 , WidthMobile : 4 ,
82
91
X : 5 , XMobile : 6 , Y : 7 , YMobile : 8 , Options : map [string ]interface {}{"showLabels" : true }, Type : "Switch" ,
83
- // variable id is set equal to the thing id by mockThingShow, in order to verify the thing override
84
- Variables : []string {"overridden" },
92
+ Variables : []string {switchyOverriddenID },
85
93
},
86
94
},
87
95
}
88
96
89
97
dashboardTwoWidgets = & iotclient.Dashboardv2 {
90
98
Name : "dashboard-two-widgets" ,
91
- // in this test, the variable id is a concatenation of thing_id and variable_id
92
- // this depends on the mocked function getVariableID
93
99
Widgets : []iotclient.Widget {
94
100
{Name : "blink_speed" , Height : 7 , Width : 8 ,
95
101
X : 7 , Y : 5 , Options : map [string ]interface {}{"min" : float64 (0 ), "max" : float64 (5000 )}, Type : "Slider" ,
96
- // variable id is set equal to the thing id by mockThingShow, in order to verify the thing override
97
- Variables : []string {"remote-controlled-lights" },
102
+ Variables : []string {blinkSpeedID },
98
103
},
99
104
{Name : "relay_2" , Height : 5 , Width : 5 ,
100
105
X : 5 , Y : 0 , Options : map [string ]interface {}{"showLabels" : true }, Type : "Switch" ,
101
- // variable id is set equal to the thing id by mockThingShow, in order to verify the thing override
102
- Variables : []string {"remote-controlled-lights" },
106
+ Variables : []string {relayID },
103
107
},
104
108
},
105
109
}
@@ -143,17 +147,20 @@ func TestLoadTemplate(t *testing.T) {
143
147
func TestLoadDashboard (t * testing.T ) {
144
148
mockClient := & mocks.Client {}
145
149
mockThingShow := func (thingID string ) * iotclient.ArduinoThing {
146
- thing := & iotclient.ArduinoThing {
150
+ if thingID == thingOverriddenID {
151
+ return & iotclient.ArduinoThing {
152
+ Properties : []iotclient.ArduinoProperty {
153
+ {Id : switchyOverriddenID , Name : "switchy" },
154
+ },
155
+ }
156
+ }
157
+ return & iotclient.ArduinoThing {
147
158
Properties : []iotclient.ArduinoProperty {
148
- // variable id is set equal to the thing id in order to verify the thing override
149
- // dashboard-with-variable variable
150
- {Id : thingID , Name : "variable" },
151
- // dashboard-two-widgets variables
152
- {Id : thingID , Name : "relay_2" },
153
- {Id : thingID , Name : "blink_speed" },
159
+ {Id : switchyID , Name : "switchy" },
160
+ {Id : relayID , Name : "relay_2" },
161
+ {Id : blinkSpeedID , Name : "blink_speed" },
154
162
},
155
163
}
156
- return thing
157
164
}
158
165
mockClient .On ("ThingShow" , mock .AnythingOfType ("string" )).Return (mockThingShow , nil )
159
166
@@ -194,7 +201,7 @@ func TestLoadDashboard(t *testing.T) {
194
201
{
195
202
name : "dashboard with variable, thing is overridden" ,
196
203
file : "testdata/dashboard-with-variable.yaml" ,
197
- override : map [string ]string {"thing" : "overridden" },
204
+ override : map [string ]string {"thing" : thingOverriddenID },
198
205
want : dashboardVariableOverride ,
199
206
},
200
207
0 commit comments