-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-utils.js
122 lines (117 loc) · 3.2 KB
/
test-utils.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
115
116
117
118
119
120
121
122
class Control {
addEventListener() {}
dispatchEvent() {}
hide() {}
notify() {}
removeEventListener() {}
show() {}
toString() {}
valueOf() {}
}
class ListControl extends Control {
items = []
add(type, text) {
if (type === 'item') {
const item = new ListItem
this.items.push([text, item])
return item
}
return null
}
find(text) {
return this.items.find(([id]) => id === text)?.[1]
}
remove() {}
removeAll() {}
revealItem() {}
}
class Container extends Control {
children = []
add(type, ...options) {
let id
switch (type) {
case 'group':
id = options[1]?.name
break
case 'progressbar':
case 'slider':
id = options[4]?.name
break
case 'scrollbar':
id = options[7]?.name
break
default:
id = options[2]?.name
break
}
id = id ?? this.children.length - 1
const objectClass = {
'button': Button,
'checkbox': Checkbox,
'dropdownlist': DropDownList,
'edittext': EditText,
'flashplayer': FlashPlayer,
'group': Group,
'iconbutton': IconButton,
'image': Image,
'item': ListItem,
'listbox': ListBox,
'panel': Panel,
'progressbar': Progressbar,
'radiobutton': RadioButton,
'scrollbar': Scrollbar,
'slider': Slider,
'statictext': StaticText,
'tab': Tab,
'tabbedpanel': TabbedPanel,
'treeview': TreeView,
}[type]
if (objectClass) {
const object = new objectClass(options)
this.children.push([id, object])
return object
}
return null
}
addEventListener() {}
center() {}
close() {}
dispatchEvent() {}
findElement(name) {
return this.children.find(([id]) => id === name)?.[1]
}
hide() {}
notify() {}
remove() {}
removeEventListener() {}
show() {}
update() {}
}
class Button extends Control {}
class Checkbox extends Control {}
class DropDownList extends ListControl {}
class EditText extends Control {}
class FlashPlayer extends Control {}
class Group extends Container {}
class IconButton extends Control {}
class Image extends Control {}
class ListItem extends Control {}
class ListBox extends ListControl {}
class Panel extends Container {}
class Progressbar extends Control {}
class RadioButton extends Control {}
class Scrollbar extends Control {}
class Slider extends Control {}
class StaticText extends Control {}
class Tab extends Container {}
class TabbedPanel extends Container {}
class TreeView extends ListControl {}
globalThis.Window = class Window extends Container {
constructor(type, title, bounds, props) {
super(type, title, bounds, props)
Window.instances.push(this)
}
}
Window.instances = []
globalThis.localize = ({ en }, ...args) =>
args.reduce((localized, arg, index) => localized.replaceAll(`%${index + 1}`, arg), en)