forked from vuejs/vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.js
114 lines (110 loc) · 3.59 KB
/
grid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
casper.test.begin('grid', 73, function (test) {
casper
.start('../../examples/grid/index.html')
.then(function () {
// headers
test.assertElementCount('th', 2)
test.assertElementCount('th.active', 0)
test.assertSelectorHasText('th:nth-child(1)', 'Name')
test.assertSelectorHasText('th:nth-child(2)', 'Power')
assertTable(test, ['name', 'power'], [
{ name: 'Chuck Norris', power: Infinity },
{ name: 'Bruce Lee', power: 9000 },
{ name: 'Jacky Chang', power: 7000 },
{ name: 'Jet Li', power: 8000 }
])
})
// test sorting
.thenClick('th:nth-child(1)', function () {
test.assertElementCount('th.active:nth-child(1)', 1)
test.assertElementCount('th.active:nth-child(2)', 0)
test.assertElementCount('th:nth-child(1) .arrow.dsc', 1)
test.assertElementCount('th:nth-child(2) .arrow.dsc', 0)
assertTable(test, ['name', 'power'], [
{ name: 'Jet Li', power: 8000 },
{ name: 'Jacky Chang', power: 7000 },
{ name: 'Chuck Norris', power: Infinity },
{ name: 'Bruce Lee', power: 9000 }
])
})
.thenClick('th:nth-child(2)', function () {
test.assertElementCount('th.active:nth-child(1)', 0)
test.assertElementCount('th.active:nth-child(2)', 1)
test.assertElementCount('th:nth-child(1) .arrow.dsc', 1)
test.assertElementCount('th:nth-child(2) .arrow.dsc', 1)
assertTable(test, ['name', 'power'], [
{ name: 'Chuck Norris', power: Infinity },
{ name: 'Bruce Lee', power: 9000 },
{ name: 'Jet Li', power: 8000 },
{ name: 'Jacky Chang', power: 7000 }
])
})
.thenClick('th:nth-child(2)', function () {
test.assertElementCount('th.active:nth-child(1)', 0)
test.assertElementCount('th.active:nth-child(2)', 1)
test.assertElementCount('th:nth-child(1) .arrow.dsc', 1)
test.assertElementCount('th:nth-child(2) .arrow.asc', 1)
assertTable(test, ['name', 'power'], [
{ name: 'Jacky Chang', power: 7000 },
{ name: 'Jet Li', power: 8000 },
{ name: 'Bruce Lee', power: 9000 },
{ name: 'Chuck Norris', power: Infinity }
])
})
.thenClick('th:nth-child(1)', function () {
test.assertElementCount('th.active:nth-child(1)', 1)
test.assertElementCount('th.active:nth-child(2)', 0)
test.assertElementCount('th:nth-child(1) .arrow.asc', 1)
test.assertElementCount('th:nth-child(2) .arrow.asc', 1)
assertTable(test, ['name', 'power'], [
{ name: 'Bruce Lee', power: 9000 },
{ name: 'Chuck Norris', power: Infinity },
{ name: 'Jacky Chang', power: 7000 },
{ name: 'Jet Li', power: 8000 }
])
})
// test search
.then(function () {
this.fill('#search', {
query: 'j'
})
})
.then(function () {
assertTable(test, ['name', 'power'], [
{ name: 'Jacky Chang', power: 7000 },
{ name: 'Jet Li', power: 8000 }
])
})
.then(function () {
this.fill('#search', {
query: 'infinity'
})
})
.then(function () {
assertTable(test, ['name', 'power'], [
{ name: 'Chuck Norris', power: Infinity }
])
})
// run
.run(function () {
test.done()
})
/**
* Helper to assert the table data is rendered correctly.
*
* @param {CasperTester} test
* @param {Array} columns
* @param {Array} data
*/
function assertTable (test, columns, data) {
test.assertElementCount('td', data.length * columns.length)
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < columns.length; j++) {
test.assertSelectorHasText(
'tr:nth-child(' + (i + 1) + ') td:nth-child(' + (j + 1) + ')',
data[i][columns[j]]
)
}
}
}
})