-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestGroup.js
More file actions
70 lines (60 loc) · 2.17 KB
/
TestGroup.js
File metadata and controls
70 lines (60 loc) · 2.17 KB
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
class TestGroup {
constructor(title, id, tests) {
this.title = title;
this.id = id;
this.tests = tests;
};
init(options) {
// Initialize the html for this TestGroup
this.createHtml(options.$container);
let groupOptions = this.getGroupOptions(options);
// Initialize all tests within this TestGroup
for (let test of this.tests) {
test.init(groupOptions);
}
};
update(options) {
let groupOptions = this.getGroupOptions(options);
// Update all tests within this TestGroup
for (let test of this.tests) {
test.update(groupOptions);
}
this.updateProgressBar(options.$container.find(`#${this.id}`));
};
/**
* Copies the given options object and updates it for this specific TestGroup.
* @param {Object} options
*/
getGroupOptions(options) {
let groupOptions = deepCopy(options);
groupOptions.$container = options.$container.find(`#${this.id} .test-cases`);
return groupOptions;
};
/**
* This is used by the progress bar, must be overridden and return an inclusive number between 0 and 100.
*/
percentageDone() {
throw "The function percentageDone must be overridden and return an inclusive number between 0 and 100";
};
/**
* Updates the progress bar found in $container based on the percentage calculated by percentageDone.
* @param {jQuery-object} $container
*/
updateProgressBar($container) {
let $percentage = $container.find(`.progress-bar .percentage`);
$percentage.css("width", `${this.percentageDone()}%`);
}
/**
* Appends the html for this TestGroup to the given $container.
* @param {jQuery-object} $container
*/
createHtml($container) {
$container.append($(`
<div class='container' id='${this.id}'>
<div class='center'><div class='progress-bar'><div class='percentage'><h2>${this.title}</h2></div></div></div>
<div class='test-cases'></div>
<div class='results'><h4>Results:</h4></div>
</div>
`));
};
};