Skip to content

Commit fb2aaf5

Browse files
committed
Merge branch 'feature/test_coverage' into develop
2 parents f4d8612 + a8c8530 commit fb2aaf5

File tree

6 files changed

+138
-75
lines changed

6 files changed

+138
-75
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"paper-toggle-button": "PolymerElements/paper-toggle-button#~1.0.13",
3333
"paper-tooltip": "PolymerElements/paper-tooltip#~1.1.1",
3434
"test-fixture": "PolymerElements/test-fixture#^1.1.0",
35-
"web-component-tester": "~4.0.3"
35+
"web-component-tester": "~4.0.3",
36+
"stacky": "PolymerLabs/stacky#~1.3.1"
3637
}
3738
}

demo/elements/demo-element.html

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
<link rel="import" href="../../../paper-tooltip/paper-tooltip.html">
1010
<link rel="import" href="../../mqtt-elements.html">
1111

12+
<link rel="import" href="mqtt-subscription-view.html">
13+
14+
1215
<dom-module id="demo-element">
1316

1417
<link rel="import" type="css" href="demo.css">
@@ -28,6 +31,7 @@
2831
<!--create a mqtt subscription for every item in topics-->
2932
<template is="dom-repeat" items="{{topics}}" as="t">
3033
<mqtt-subscription topic="[[t.topic]]"
34+
messages="{{t.messages}}"
3135
number-of-messages="10"
3236
qos="[[t.qos]]"></mqtt-subscription>
3337
</template>
@@ -113,40 +117,8 @@ <h3>Publish on <span>[[topic]]</span></h3>
113117
</div>
114118

115119
<!--output every subscription-->
116-
<template id="subscriptionList" is="dom-repeat" items="[[subscriptions]]" as="sub" observe="messages.*">
117-
<div class="vertical-section">
118-
<div>
119-
<div class="sub-header">
120-
<h2 class="title">Subscribed to - <span>[[sub.topic]]</span></h2>
121-
<h3 class="qos">QoS: <span>[[sub.qos]]</span></h3>
122-
<paper-icon-button on-tap="_removeSubscription"
123-
icon="icons:delete"
124-
alt="remove"
125-
title="remove subscription"></paper-icon-button>
126-
</div>
127-
<table>
128-
<thead>
129-
<tr>
130-
<th colspan="3">Messages</th>
131-
</tr>
132-
<tr>
133-
<th>Topic</th>
134-
<th>QoS</th>
135-
<th class="full">Payload</th>
136-
</tr>
137-
</thead>
138-
<tbody>
139-
<template is="dom-repeat" items="{{sub.messages}}" as="message">
140-
<tr>
141-
<td>{{message.topic}}</td>
142-
<td>{{message.message.qos}}</td>
143-
<td class="full">{{message.parsedPayload}}</td>
144-
</tr>
145-
</template>
146-
</tbody>
147-
</table>
148-
</div>
149-
</div>
120+
<template id="subscriptionList" is="dom-repeat" items="[[topics]]" as="sub">
121+
<mqtt-subscription-view model="[[sub]]"></mqtt-subscription-view>
150122
</template>
151123
</div>
152124
</template>
@@ -166,12 +138,9 @@ <h3 class="qos">QoS: <span>[[sub.qos]]</span></h3>
166138
type: Object,
167139
},
168140

169-
subscriptions: {
170-
type: Array,
171-
},
172-
173141
newSubTopic: {
174142
type: String,
143+
value: ""
175144
},
176145

177146
subQos: {
@@ -194,7 +163,7 @@ <h3 class="qos">QoS: <span>[[sub.qos]]</span></h3>
194163

195164
topic: {
196165
type: String,
197-
value: "foo/bar",
166+
value: "",
198167
},
199168

200169
messages: {
@@ -224,7 +193,17 @@ <h3 class="qos">QoS: <span>[[sub.qos]]</span></h3>
224193

225194
clientId: {
226195
type: String,
196+
},
197+
198+
value: {
199+
type: String,
200+
value: "foo/bar"
227201
}
202+
203+
},
204+
205+
listeners: {
206+
"mqtt-subscription-remove-view": "_removeSubscription"
228207
},
229208

230209
observers: [],
@@ -261,7 +240,7 @@ <h3 class="qos">QoS: <span>[[sub.qos]]</span></h3>
261240

262241
_addSub: function () {
263242
if(this.newSubTopic.length > 0) {
264-
this.push("topics", {topic: this.newSubTopic, qos: this.subQos});
243+
this.push("topics", {topic: this.newSubTopic, qos: this.subQos, messages: []});
265244
}
266245
},
267246

@@ -291,11 +270,8 @@ <h3 class="qos">QoS: <span>[[sub.qos]]</span></h3>
291270
},
292271

293272
_removeSubscription: function (event) {
294-
// using the index of the subscriptions array only works because we have not changed the order of the
295-
// subscriptions. Otherwise it would be nessesary to have some sort of ID for each subscription to easily map
296-
// the subscription to the model.
297-
var index = this.subscriptions.indexOf(event.model.sub)
298-
this.splice("topics", index, 1);
273+
var key = Polymer.Collection.get(this.topics).getKey(event.detail);
274+
this.splice("topics", key, 1);
299275
},
300276

301277
});

demo/elements/demo.css

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
:root {
2-
--status-icon: {
3-
width: 20px;
4-
height: 20px;
5-
border-radius: 50%;
6-
overflow: hidden;
7-
};
2+
--status-icon: {
3+
width: 20px;
4+
height: 20px;
5+
border-radius: 50%;
6+
overflow: hidden;
7+
};
88

9-
--paper-icon-button: {
10-
margin-right: -8px;
11-
};
9+
--paper-icon-button: {
10+
margin-right: -8px;
11+
};
1212
}
1313

1414
body {
@@ -19,20 +19,19 @@ body {
1919
background-color: var(--paper-grey-50);
2020
}
2121

22-
2322
.horizontal-section {
2423
background-color: white;
2524
padding: 24px;
2625
margin-right: 24px;
2726
min-width: 200px;
28-
@apply(--shadow-elevation-2dp);
27+
@apply(--shadow-elevation-2dp);
2928
}
3029

3130
.vertical-section {
3231
background-color: white;
3332
padding: 24px;
3433
margin: 0 24px 24px 24px;
35-
@apply(--shadow-elevation-2dp);
34+
@apply(--shadow-elevation-2dp);
3635
}
3736

3837
.vertical-section table {
@@ -48,17 +47,17 @@ body {
4847
}
4948

5049
paper-slider {
51-
width:100px;
50+
width: 100px;
5251
}
5352

5453
.sub-header {
55-
@apply(--layout);
56-
@apply(--layout-center);
57-
@apply(--layout-wrap);
54+
@apply(--layout);
55+
@apply(--layout-center);
56+
@apply(--layout-wrap);
5857
}
5958

6059
.sub-header .title {
61-
@apply(--layout-flex);
60+
@apply(--layout-flex);
6261
min-width: 248px;
6362
}
6463

@@ -72,10 +71,10 @@ paper-slider {
7271

7372
.horizontal-section-container-end {
7473
margin-top: 16px;
75-
@apply(--layout-horizontal);
76-
@apply(--layout-center);
77-
@apply(--layout-end-justified);
78-
@apply(--layout-wrap);
74+
@apply(--layout-horizontal);
75+
@apply(--layout-center);
76+
@apply(--layout-end-justified);
77+
@apply(--layout-wrap);
7978
}
8079

8180
td, th {
@@ -88,31 +87,30 @@ tbody tr:nth-child(odd) {
8887
}
8988

9089
.connected {
91-
@apply(--status-icon);
90+
@apply(--status-icon);
9291
background: darkseagreen;
9392
}
9493

9594
.disconnected {
96-
@apply(--status-icon);
95+
@apply(--status-icon);
9796
background: indianred;
9897
}
9998

10099
.status {
101-
@apply(--layout);
102-
@apply(--layout-center);
100+
@apply(--layout);
101+
@apply(--layout-center);
103102
margin-left: 1rem;
104103
}
105104

106105
.status h3 {
107-
@apply(--layout-flex);
106+
@apply(--layout-flex);
108107
margin-right: 0.25rem;
109108
}
110109

111110
.layout.wrap.center-center {
112111
max-width: 800px;
113112
}
114113

115-
116114
.settings > h3 {
117115
margin-bottom: 0;
118116
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<link rel="import" href="../../../polymer/polymer.html">
2+
3+
<link rel="import" href="../../../paper-styles/demo-pages.html">
4+
5+
<dom-module id="mqtt-subscription-view">
6+
7+
<link rel="import" type="css" href="demo.css">
8+
9+
<template>
10+
<style>
11+
:host {
12+
box-sizing: border-box;
13+
}
14+
</style>
15+
16+
<div>lastMessage: <span>[[model.lastMessage]]</span></div>
17+
<div class="vertical-section">
18+
<div>
19+
<div class="sub-header">
20+
<h2 class="title">Subscribed to - <span>[[model.topic]]</span></h2>
21+
<h3 class="qos">QoS: <span>[[model.qos]]</span></h3>
22+
<paper-icon-button on-tap="_removeSubscription"
23+
icon="icons:delete"
24+
alt="remove"
25+
title="remove subscription"></paper-icon-button>
26+
</div>
27+
<table>
28+
<thead>
29+
<tr>
30+
<th colspan="3">Messages</th>
31+
</tr>
32+
<tr>
33+
<th>Topic</th>
34+
<th>QoS</th>
35+
<th class="full">Payload</th>
36+
</tr>
37+
</thead>
38+
<tbody>
39+
<template is="dom-repeat" items="[[model.messages]]" as="message">
40+
<tr>
41+
<td>[[message.topic]]</td>
42+
<td>[[message.message.qos]]</td>
43+
<td class="full">[[message.parsedPayload]]</td>
44+
</tr>
45+
</template>
46+
</tbody>
47+
</table>
48+
</div>
49+
</div>
50+
51+
</template>
52+
53+
<script>
54+
Polymer({
55+
is: 'mqtt-subscription-view',
56+
57+
properties: {
58+
model: {
59+
type: Object
60+
}
61+
},
62+
63+
_removeSubscription: function (event) {
64+
this.fire("mqtt-subscription-remove-view", this.model);
65+
},
66+
67+
68+
});
69+
</script>
70+
</dom-module>

mqtt-subscription.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@
209209
// don't do anything user has to supply a payloadParseFunction
210210
break;
211211
case "Unknown":
212-
this.payloadParseFunction = function () {
213-
};
212+
this.payloadParseFunction = function () {};
214213
break;
215214
case "String":
216215
this.payloadParseFunction = String.fromCharCode;

wct.conf.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"verbose": true,
3+
"plugins": {
4+
"istanbul": {
5+
"dir": "./coverage",
6+
"reporters": ["text-summary", "lcov", "html"],
7+
"include": [
8+
"**/*.js"
9+
],
10+
"exclude": [
11+
"/polymer/polymer.js",
12+
"/platform/platform.js",
13+
"/bower_components/**/*.js",
14+
"/bower_components/**/*.html",
15+
"/demo/**/*.html"
16+
]
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)