-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.user.js
109 lines (93 loc) · 3.45 KB
/
test.user.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
// ==UserScript==
// @name Test
// @namespace https://github.com/nexushoratio/userscripts
// @match http://localhost:8000/
// @noframes
// @version 10
// @author Mike Castle
// @description Just for running tests.
// @license GPL-3.0-or-later; https://www.gnu.org/licenses/gpl-3.0-standalone.html
// @require https://greasyfork.org/scripts/478188-nh-xunit/code/NH_xunit.js
// @require https://greasyfork.org/scripts/477290-nh-base/code/NH_base.js
// @require https://greasyfork.org/scripts/478349-nh-userscript/code/NH_userscript.js
// @require https://greasyfork.org/scripts/478440-nh-web/code/NH_web.js
// @require https://greasyfork.org/scripts/478676-nh-widget/code/NH_widget.js
// ==/UserScript==
// eslint-disable-next-line max-lines-per-function
(() => {
'use strict';
const NH = window.NexusHoratio.base.ensure([
{name: 'xunit'},
{name: 'base'},
{name: 'userscript'},
{name: 'widget'},
]);
const logger = new NH.base.Logger('Testing');
NH.base.Logger.config('Testing').enabled = true;
NH.base.Logger.config('Testing')
.group('Failures').mode = 'opened';
NH.base.Logger.config('Testing')
.group('Errors').mode = 'opened';
for (const entry of NH.userscript.environmentData()) {
logger.log(entry);
}
NH.xunit.testing.enabled = true;
NH.xunit.testing.run();
logger.log('finished');
/* eslint-disable max-lines-per-function */
/* eslint-disable require-jsdoc */
function demoGrid() {
function renderInt(record, field) {
return `${record[field]}`;
}
function renderType(record) {
return `${record.stage}, ${record.species}`;
}
function rowClassesFunc(record) {
return [record.species, record.stage];
}
const data = [
{id: 1, name: 'Sally', species: 'human', stage: 'juvenile'},
{name: 'Puff', id: 3, species: 'feline', stage: 'juvenile'},
{name: 'Jane', id: 2, species: 'human', stage: 'juvenile'},
{name: 'Bob', id: 4, species: 'alien', stage: 'adolescent'},
{name: 'Mother', id: 5, species: 'human', stage: 'adult'},
];
const w = new NH.widget.Grid('Characters')
.rowClassesFunc(rowClassesFunc)
.set(data);
w.installStyle(w.id, [
`#${w.container.id} {border-collapse: collapse;}`,
`#${w.container.id} td,th {border: 1px solid black;}`,
`#${w.container.id} tr {background-blend-mode: screen;}`,
`#${w.container.id} tr.feline {background-color: orange;}`,
`#${w.container.id} tr.human {background-color: RebeccaPurple;}`,
`#${w.container.id} tr.alien {background-color: green;}`,
`#${w.container.id} tr.juvenile {background-image: ` +
'linear-gradient(to bottom, white, black);}',
`#${w.container.id} tr.adolescent {background-image: ` +
'linear-gradient(to bottom, white, black, white);}',
`#${w.container.id} tr.adult {background-image: ` +
'linear-gradient(to bottom, white, black, white, black);}',
`#${w.container.id} td.typ {font-weight: bolder;}`,
]);
w.columns.push(
new NH.widget.GridColumn('id')
.renderFunc(renderInt),
new NH.widget.GridColumn('name'),
new NH.widget.GridColumn('typ')
.setTitle('Type')
.renderFunc(renderType),
);
// Act
w.build();
document.body.append(w.container);
}
/* eslint-enable */
const demos = [{enabled: false, demo: demoGrid}];
for (const {enabled, demo} of demos) {
if (enabled) {
demo();
}
}
})();