Skip to content

Commit

Permalink
add e2e tests for svg example
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Sep 25, 2014
1 parent 1b70d4f commit a515230
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
5 changes: 4 additions & 1 deletion examples/svg/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
<span>{{value}}</span>
<button v-on="click:remove(this)">X</button>
</div>
<input v-model="newLabel"> <button v-on="click:add">Add a Stat</button>
<form id="add">
<input name="newlabel" v-model="newLabel">
<button v-on="click:add">Add a Stat</button>
</form>
<pre id="raw">{{stats | json}}</pre>
</div>

Expand Down
5 changes: 4 additions & 1 deletion examples/svg/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ new Vue({
stats: stats
},
methods: {
add: function () {
add: function (e) {
e.preventDefault()
if (!this.newLabel) return
this.stats.push({
label: this.newLabel,
Expand All @@ -77,6 +78,8 @@ new Vue({
remove: function (stat) {
if (this.stats.length > 3) {
this.stats.$remove(stat.$data)
} else {
alert('Can\'t delete more!')
}
}
}
Expand Down
57 changes: 57 additions & 0 deletions test/e2e/svg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
casper.test.begin('svg', 18, function (test) {

casper
.start('../../examples/svg/index.html')
.then(function () {
test.assertElementCount('g', 1)
test.assertElementCount('polygon', 1)
test.assertElementCount('circle', 1)
test.assertElementCount('text', 6)
test.assertElementCount('label', 6)
test.assertElementCount('button', 7)
test.assertElementCount('input[type="range"]', 6)
test.assertEval(function () {
var points = stats.map(function (stat, i) {
var point = valueToPoint(stat.value, i, 6)
return point.x + ',' + point.y
}).join(' ')
return document.querySelector('polygon').attributes[0].value === points
})
})
.thenClick('button', function () {
test.assertElementCount('text', 5)
test.assertElementCount('label', 5)
test.assertElementCount('button', 6)
test.assertElementCount('input[type="range"]', 5)
test.assertEval(function () {
var points = stats.map(function (stat, i) {
var point = valueToPoint(stat.value, i, 5)
return point.x + ',' + point.y
}).join(' ')
return document.querySelector('polygon').attributes[0].value === points
})
})
.then(function () {
this.fill('#add', {
newlabel: 'hi'
})
})
.thenClick('#add > button', function () {
test.assertElementCount('text', 6)
test.assertElementCount('label', 6)
test.assertElementCount('button', 7)
test.assertElementCount('input[type="range"]', 6)
test.assertEval(function () {
var points = stats.map(function (stat, i) {
var point = valueToPoint(stat.value, i, 6)
return point.x + ',' + point.y
}).join(' ')
return document.querySelector('polygon').attributes[0].value === points
})
})
// run
.run(function () {
test.done()
})

})

0 comments on commit a515230

Please sign in to comment.