Skip to content

Commit a515230

Browse files
committed
add e2e tests for svg example
1 parent 1b70d4f commit a515230

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

examples/svg/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
<span>{{value}}</span>
3131
<button v-on="click:remove(this)">X</button>
3232
</div>
33-
<input v-model="newLabel"> <button v-on="click:add">Add a Stat</button>
33+
<form id="add">
34+
<input name="newlabel" v-model="newLabel">
35+
<button v-on="click:add">Add a Stat</button>
36+
</form>
3437
<pre id="raw">{{stats | json}}</pre>
3538
</div>
3639

examples/svg/svg.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ new Vue({
6666
stats: stats
6767
},
6868
methods: {
69-
add: function () {
69+
add: function (e) {
70+
e.preventDefault()
7071
if (!this.newLabel) return
7172
this.stats.push({
7273
label: this.newLabel,
@@ -77,6 +78,8 @@ new Vue({
7778
remove: function (stat) {
7879
if (this.stats.length > 3) {
7980
this.stats.$remove(stat.$data)
81+
} else {
82+
alert('Can\'t delete more!')
8083
}
8184
}
8285
}

test/e2e/svg.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
casper.test.begin('svg', 18, function (test) {
2+
3+
casper
4+
.start('../../examples/svg/index.html')
5+
.then(function () {
6+
test.assertElementCount('g', 1)
7+
test.assertElementCount('polygon', 1)
8+
test.assertElementCount('circle', 1)
9+
test.assertElementCount('text', 6)
10+
test.assertElementCount('label', 6)
11+
test.assertElementCount('button', 7)
12+
test.assertElementCount('input[type="range"]', 6)
13+
test.assertEval(function () {
14+
var points = stats.map(function (stat, i) {
15+
var point = valueToPoint(stat.value, i, 6)
16+
return point.x + ',' + point.y
17+
}).join(' ')
18+
return document.querySelector('polygon').attributes[0].value === points
19+
})
20+
})
21+
.thenClick('button', function () {
22+
test.assertElementCount('text', 5)
23+
test.assertElementCount('label', 5)
24+
test.assertElementCount('button', 6)
25+
test.assertElementCount('input[type="range"]', 5)
26+
test.assertEval(function () {
27+
var points = stats.map(function (stat, i) {
28+
var point = valueToPoint(stat.value, i, 5)
29+
return point.x + ',' + point.y
30+
}).join(' ')
31+
return document.querySelector('polygon').attributes[0].value === points
32+
})
33+
})
34+
.then(function () {
35+
this.fill('#add', {
36+
newlabel: 'hi'
37+
})
38+
})
39+
.thenClick('#add > button', function () {
40+
test.assertElementCount('text', 6)
41+
test.assertElementCount('label', 6)
42+
test.assertElementCount('button', 7)
43+
test.assertElementCount('input[type="range"]', 6)
44+
test.assertEval(function () {
45+
var points = stats.map(function (stat, i) {
46+
var point = valueToPoint(stat.value, i, 6)
47+
return point.x + ',' + point.y
48+
}).join(' ')
49+
return document.querySelector('polygon').attributes[0].value === points
50+
})
51+
})
52+
// run
53+
.run(function () {
54+
test.done()
55+
})
56+
57+
})

0 commit comments

Comments
 (0)