-
Notifications
You must be signed in to change notification settings - Fork 106
/
progressboard.html
113 lines (104 loc) · 3.2 KB
/
progressboard.html
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
<html>
<head>
<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.min.css">
<style>
body {margin:20px;}
h1 {text-align:center;}
.team-row { margin-top:0px;}
.testname {padding:5px;line-height: 2em; cursor: pointer}
.failed {background-color: #FDD;}
.passed {background-color: #DFD;}
.unknown {background-color: #EEE;}
.tile {text-align:center}
.table td {padding:0.25rem;}
.table th {
height: 150px;
font-weight: 100;
vertical-align: bottom;
text-align: left;
max-width: 50px;
overflow-x: visible;
font-size: 8pt;
transform: rotate(-45deg);
transform-origin: 25px 125px 0;
}
</style>
</head>
<body>
<!--h1>Bowling Game Kata</h1-->
<div id="container" />
<script>
let getAllTestNames = function(res){
let testNames = {}
for(let name in res){
for(let test of res[name].tests)
testNames[test.TestName] = 1;
}
return Object.keys(testNames).sort();
}
let findStatus = function(tests, testName){
for(let t of tests)
if (t.TestName == testName) return t;
return null;
}
function buildDateKey() {
var now = new Date();
var day = ("0" + now.getDate()).slice(-2);
var month = ("0" + (now.getMonth() + 1)).slice(-2);
var year = now.getFullYear();
return year + month + day;
}
var realm = "exceptions";
var dateKey = buildDateKey();
var fb = new Firebase(
"https://testing-challenge.firebaseio.com/" + realm + "/" + dateKey);
fb.on("value", function(snapshot) {
var res = snapshot.val();
var testNames = getAllTestNames(res);
for(let name in res){
res[name].columns = testNames.map(tn => findStatus(res[name].tests, tn))
}
var html = "<table class='table'>";
html += "<tr><th></th>";
testNames.forEach(function(tn){
html += '<th>' + tn + '</th>';
});
html += "</tr>";
var names = Object.keys(res);
names.sort((a,b) => compareTestsSets(res[a].tests, res[b].tests));
names.forEach(function(name){
html += "<tr><td class='name'>" + htmlEscape(name) + "</td>";
res[name].columns.forEach(t => html += formatTest(t));
html += "</tr>";
});
html += "</table>";
document.getElementById("container").innerHTML = html;
});
function compareTestsSets(set1, set2){
// -1, если количество PASSED у set1 больше, чем set2
// -1, если количество PASSED одинаково, но последний запуск у set1 позже set2
let res = set2.filter(t => t.Succeeded).length - set1.filter(t => t.Succeeded).length;
if (res != 0) return res;
res = set2.length - set1.length;
if (res != 0) return res;
return set2[0].LastRunTime > set1[0].LastRunTime ? 1 : -1;
}
function htmlEscape(str) {
return str
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '')
.replace(/>/g, '');
}
function formatTest(test){
if (test == null) return "<td class='testname unknown'></td>";
let symbol = test.Succeeded ? "+" : "";
return "<td title='" + test.TestName + "' class='testname " +
(test.Succeeded ? "passed" : "failed") +" tile'>"
+ symbol + "</span> ";
}
</script>
</body>
</html>