Skip to content

Commit 4575203

Browse files
committed
add e2e test for tree example
1 parent 611486c commit 4575203

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

examples/tree/index.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
<title>Vue.js tree-view demo</title>
66
<style>
77
body {
8-
font-family: monospace;
8+
font-family: Menlo, Consolas, monospace;
9+
color: #444;
910
}
1011
.item {
1112
cursor: pointer;
1213
}
14+
.bold {
15+
font-weight: bold;
16+
}
1317
ul {
1418
padding-left: 1em;
19+
line-height: 1.5em;
1520
list-style-type: dot;
1621
}
1722
</style>
@@ -21,7 +26,7 @@
2126

2227
<!-- item template -->
2328
<script type="text/x-template" id="item-template">
24-
<div v-style="color: isFolder ? '#333' : '#999'"
29+
<div v-class="bold: isFolder"
2530
v-on="click: toggle, dblclick: changeType">
2631
{{model.name}}
2732
<span v-if="isFolder">[{{open ? '-' : '+'}}]</span>

test/e2e/tree.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
casper.test.begin('tree', 22, function (test) {
2+
3+
casper
4+
.start('../../examples/tree/index.html')
5+
.then(function () {
6+
test.assertElementCount('.item', 12)
7+
test.assertElementCount('.item > ul', 4)
8+
test.assertNotVisible('#demo li ul')
9+
test.assertSelectorHasText('#demo li div span', '[+]')
10+
})
11+
.thenClick('.bold', function () {
12+
test.assertVisible('#demo ul')
13+
test.assertSelectorHasText('#demo li div span', '[-]')
14+
test.assertSelectorHasText('#demo ul > .item:nth-child(1)', 'hello')
15+
test.assertSelectorHasText('#demo ul > .item:nth-child(2)', 'wat')
16+
test.assertSelectorHasText('#demo ul > .item:nth-child(3)', 'child folder')
17+
test.assertSelectorHasText('#demo ul > .item:nth-child(3)', '[+]')
18+
test.assertEval(function () {
19+
return document.querySelector('#demo li ul').children.length === 4
20+
})
21+
})
22+
.thenClick('#demo ul .bold', function () {
23+
test.assertVisible('#demo ul ul')
24+
test.assertSelectorHasText('#demo ul > .item:nth-child(3)', '[-]')
25+
test.assertEval(function () {
26+
return document.querySelector('#demo ul ul').children.length === 5
27+
})
28+
})
29+
.thenClick('.bold', function () {
30+
test.assertNotVisible('#demo ul')
31+
test.assertSelectorHasText('#demo li div span', '[+]')
32+
})
33+
.thenClick('.bold', function () {
34+
test.assertVisible('#demo ul')
35+
test.assertSelectorHasText('#demo li div span', '[-]')
36+
})
37+
.then(function () {
38+
casper.mouseEvent('dblclick', '#demo ul > .item div')
39+
})
40+
.then(function () {
41+
test.assertElementCount('.item', 13)
42+
test.assertElementCount('.item > ul', 5)
43+
test.assertSelectorHasText('#demo ul > .item:nth-child(1)', '[-]')
44+
test.assertEval(function () {
45+
var firstItem = document.querySelector('#demo ul > .item:nth-child(1)')
46+
var ul = firstItem.querySelector('ul')
47+
return ul.children.length === 2
48+
})
49+
})
50+
// run
51+
.run(function () {
52+
test.done()
53+
})
54+
55+
})

0 commit comments

Comments
 (0)