OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright 2014 The Chromium Authors. All rights reserved. | |
3 Use of this source code is governed by a BSD-style license that can be | |
4 found in the LICENSE file. | |
5 --> | |
6 | |
7 <link rel="import" href="../build-table.html"> | |
8 | |
9 <script> | |
10 (function() { | |
11 | |
12 var assert = chai.assert; | |
13 | |
14 describe('build-table', function() { | |
15 var buildTable; | |
16 var builds = []; | |
17 | |
18 function getCellByRC(row, column) { | |
19 return buildTable.shadowRoot.querySelectorAll('tr')[row]. | |
20 querySelector('td:nth-child(' + column + ')'); | |
21 } | |
22 | |
23 beforeEach(function(done) { | |
24 buildTable = document.createElement('build-table'); | |
25 buildTable.builds = builds; | |
26 buildTable.auto = false; | |
27 setTimeout(done); | |
28 }); | |
29 | |
30 describe('build table: result', function() { | |
31 before(function() { | |
32 builds = [{ | |
33 master: 'test', builder: 'test', buildnumber: 1, | |
34 buildtime: 60, result: 0, revision: 1}]; | |
35 }); | |
36 | |
37 it('should show success if result is 0', function() { | |
38 assert.equal(getCellByRC(1, 5).textContent, 'success'); | |
39 }); | |
40 | |
41 it('should show failure if result is 2', function(done) { | |
42 buildTable.builds[0].result = 2; | |
43 setTimeout(function() { | |
44 assert.equal(getCellByRC(1, 5).textContent, 'failure'); | |
45 done(); | |
46 }); | |
47 }); | |
48 }); | |
49 | |
50 describe('build table: core-ajax', function() { | |
51 before(function() { | |
52 builds = [{ | |
53 master: 'aMaster', builder: 'aBuilder', buildnumber: 42, | |
54 buildTime: 321, result: 1, revision: 33}]; | |
55 }); | |
56 | |
57 it('should fetch the appropriate build info', function() { | |
58 assert.equal(buildTable.shadowRoot.querySelector('core-ajax').url, | |
59 'http://build.chromium.org/p/aMaster/json/builders/aBuilder/builds/42'
); | |
60 }); | |
61 }); | |
62 | |
63 describe('build table: build time', function() { | |
64 before(function() { | |
65 builds = [ | |
66 {master: 'test', builder: 'test', buildnumber: 100, buildtime: 1, resu
lt: 1, revision: 33}, | |
67 {master: 'test', builder: 'test', buildnumber: 100, buildtime: 59, res
ult: 1, revision: 33}, | |
68 {master: 'test', builder: 'test', buildnumber: 100, buildtime: 60, res
ult: 1, revision: 33}, | |
69 {master: 'test', builder: 'test', buildnumber: 100, buildtime: 61, res
ult: 1, revision: 33}, | |
70 {master: 'test', builder: 'test', buildnumber: 100, buildtime: 599, re
sult: 1, revision: 33}, | |
71 {master: 'test', builder: 'test', buildnumber: 100, buildtime: 601, re
sult: 1, revision: 33}, | |
72 {master: 'test', builder: 'test', buildnumber: 100, buildtime: 3599, r
esult: 1, revision: 33}, | |
73 {master: 'test', builder: 'test', buildnumber: 100, buildtime: 3601, r
esult: 1, revision: 33}]; | |
74 }); | |
75 | |
76 it('should format a duration of 1 second as 0:00:01', function() { | |
77 assert.equal(getCellByRC(1, 4).textContent, '0:00:01'); | |
78 }); | |
79 | |
80 it('should format a duration of 59 seconds as 0:00:59', function() { | |
81 assert.equal(getCellByRC(2, 4).textContent, '0:00:59'); | |
82 }); | |
83 | |
84 it('should format a duration of 60 seconds as 0:01:00', function() { | |
85 assert.equal(getCellByRC(3, 4).textContent, '0:01:00'); | |
86 }); | |
87 | |
88 it('should format a duration of 61 seconds as 0:01:01', function() { | |
89 assert.equal(getCellByRC(4, 4).textContent, '0:01:01'); | |
90 }); | |
91 | |
92 it('should format a duration of 599 seconds as 0:09:59', function() { | |
93 assert.equal(getCellByRC(5, 4).textContent, '0:09:59'); | |
94 }); | |
95 | |
96 it('should format a duration of 601 seconds as 0:10:01', function() { | |
97 assert.equal(getCellByRC(6, 4).textContent, '0:10:01'); | |
98 }); | |
99 | |
100 it('should format a duration of 3599 seconds as 0:59:59', function() { | |
101 assert.equal(getCellByRC(7, 4).textContent, '0:59:59'); | |
102 }); | |
103 | |
104 it('should format a duration of 3601 seconds as 1:00:01', function() { | |
105 assert.equal(getCellByRC(8, 4).textContent, '1:00:01'); | |
106 }); | |
107 }); | |
108 | |
109 describe('build table: sorting', function() { | |
110 before(function() { | |
111 builds = [ | |
112 {master: 'a', builder: 'p', buildnumber: 3, buildtime: 1, result: 1, r
evision: 33}, | |
113 {master: 'c', builder: 'j', buildnumber: 36, buildtime: 59, result: 1,
revision: 33}, | |
114 {master: 'h', builder: 'k', buildnumber: 8, buildtime: 60, result: 1,
revision: 33}, | |
115 {master: 'b', builder: 'i', buildnumber: 5, buildtime: 61, result: 1,
revision: 33}, | |
116 {master: 'e', builder: 'm', buildnumber: 32, buildtime: 599, result: 1
, revision: 33}, | |
117 {master: 'g', builder: 'l', buildnumber: 31, buildtime: 601, result: 1
, revision: 33}, | |
118 {master: 'd', builder: 'o', buildnumber: 11, buildtime: 3599, result:
1, revision: 33}, | |
119 {master: 'f', builder: 'n', buildnumber: 37, buildtime: 3601, result:
1, revision: 33}]; | |
120 }); | |
121 | |
122 function getColumnContents(num_rows, column) { | |
123 var contents = []; | |
124 for (var i = 0; i < num_rows; i++) | |
125 contents.push(getCellByRC(i + 1, column).textContent); | |
126 return contents; | |
127 } | |
128 | |
129 it('should sort master alphabetically', function(done) { | |
130 buildTable.shadowRoot.querySelector('th[data-type="master"]').click(); | |
131 setTimeout(function() { | |
132 assert.deepEqual(getColumnContents(8, 1), ['a', 'b', 'c', 'd', 'e', 'f',
'g', 'h']); | |
133 assert.deepEqual(getColumnContents(8, 2), ['p', 'i', 'j', 'o', 'm', 'n',
'l', 'k']); | |
134 done(); | |
135 }); | |
136 }); | |
137 | |
138 it('should sort builder alphabetically', function(done) { | |
139 buildTable.shadowRoot.querySelector('th[data-type="builder"]').click(); | |
140 setTimeout(function() { | |
141 assert.deepEqual(getColumnContents(8, 1), ['b', 'c', 'h', 'g', 'e', 'f',
'd', 'a']); | |
142 assert.deepEqual(getColumnContents(8, 2), ['i', 'j', 'k', 'l', 'm', 'n',
'o', 'p']); | |
143 done(); | |
144 }); | |
145 }); | |
146 | |
147 it('should sort buildnumber numerically', function(done) { | |
148 buildTable.shadowRoot.querySelector('th[data-type="buildnumber"]').click()
; | |
149 setTimeout(function() { | |
150 assert.deepEqual(getColumnContents(8, 3).map(Number), [3, 5, 8, 11, 31,
32, 36, 37]); | |
151 assert.deepEqual(getColumnContents(8, 1), ['a', 'b', 'h', 'd', 'g', 'e',
'c', 'f']); | |
152 done(); | |
153 }); | |
154 }); | |
155 | |
156 it('should sort buildtime numerically', function(done) { | |
157 buildTable.shadowRoot.querySelector('th[data-type="buildtime"]').click(); | |
158 setTimeout(function() { | |
159 assert.deepEqual(getColumnContents(8, 4), ["0:00:01", "0:00:59", "0:01:0
0", "0:01:01", "0:09:59", "0:10:01", "0:59:59", "1:00:01"]); | |
160 assert.deepEqual(getColumnContents(8, 1), ['a', 'c', 'h', 'b', 'e', 'g',
'd', 'f']); | |
161 done(); | |
162 }); | |
163 }); | |
164 | |
165 it('should reverse sort order after clicking twice', function(done) { | |
166 buildTable.shadowRoot.querySelector('th[data-type="master"]').click(); | |
167 buildTable.shadowRoot.querySelector('th[data-type="master"]').click(); | |
168 setTimeout(function() { | |
169 assert.deepEqual(getColumnContents(8, 1), ['a', 'b', 'c', 'd', 'e', 'f',
'g', 'h'].reverse()); | |
170 assert.deepEqual(getColumnContents(8, 2), ['p', 'i', 'j', 'o', 'm', 'n',
'l', 'k'].reverse()); | |
171 done(); | |
172 }); | |
173 }); | |
174 }); | |
175 }); | |
176 | |
177 })(); | |
178 </script> | |
179 | |
OLD | NEW |