forked from MathMan05/JankClient
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
210 lines (162 loc) · 6.12 KB
/
test.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
const test = require("node:test")
const assert = require("node:assert")
const crypto = require("node:crypto")
const fs = require("node:fs").promises
const expectEqual = async (t, name = "", input = "", expected = "") => {
await t.test(name, () => {
assert.strictEqual(input, expected)
})
}
/* eslint-disable no-unused-vars */
// https://docs.taiko.dev/api/reference/
const {
openBrowser,
closeBrowser,
goto,
write,
fileField,
timeField,
clear,
$,
click,
rightClick,
textBox,
button,
press,
checkBox,
accept,
closeTab,
currentURL,
waitFor,
dropDown
} = require("taiko")
/* eslint-enable no-unused-vars */
const taiko = require("taiko")
const baseUrl = "https://spacebar.vanillaminigames.net/"
const suffix = "@vanillaminigames.net"
const main = async () => {
let prevAccount = {}
try {
prevAccount = require("./testAccount.json")
} catch {}
const username = prevAccount.username || "automated-user-" + Date.now()
try {
await openBrowser()
if (prevAccount.username) {
await goto(baseUrl + "login")
await test("Login", async t => {
await write(prevAccount.email, textBox("Email"))
await write(prevAccount.password, textBox("Password"))
await click(button("Login"))
await waitFor(3000)
await expectEqual(t, "Username", await $("#username").text(), username)
})
} else {
await goto(baseUrl + "register")
await test("Registration", async t => {
await write("no-reply+" + username + suffix, textBox("Email"))
await write(username, textBox("Username"))
const password = crypto.randomBytes(32).toString("base64url")
await write(password, textBox("Password"))
await write("not-the-same", textBox("Enter password again"))
await timeField("Date of birth").select(new Date("1970-01-01"))
await click(button("Create account"))
await expectEqual(t, "Password equal", await $("#wrong").text(), "Passwords don't match")
await clear(textBox("Enter password again"))
await write(password, textBox("Enter password again"))
await click(button("Create account"))
await expectEqual(t, "ToS check", await $("#wrong").text(),
"Du musst den Nutzungsbedingungen und der Datenschutzerklärung zustimmen.")
await click($("#tos-check"))
await click(button("Create account"))
await waitFor(3000)
await expectEqual(t, "Username", await $("#username").text(), username)
fs.writeFile("./testAccount.json", JSON.stringify({
username,
email: "no-reply+" + username + "@vanillaminigames.net",
password
}, null, "\t"))
})
}
await test("Usage: User profile", {skip: true}, async t => {
await click($("#settings"))
await clear(textBox("Pronouns"))
await write("it", textBox("Pronouns"))
await expectEqual(t, "Pronouns preview", await $("p.pronouns").text(), "it")
await clear(textBox("Bio"))
await write("Hello *world*!", textBox("Bio"))
await expectEqual(t, "Bio preview", await $(".hypoprofile > .infosection > span").text(), "Hello world!")
//await dropDown("Theme").select("Light")
await click($(".savediv button"))
await click($("dialog.settings > .exitsettings"))
})
await test("Usage: Connections", {skip: true}, async t => {
await click($("#settings"))
await click($(".SettingsButton:nth-child(4)"))
await waitFor(2000)
await expectEqual(t, "YouTube connection list", await $("#connection-container div").text(), "Youtube")
await click($("#connection-container div"))
await waitFor(2000)
await expectEqual(t, "YouTube connection OAuth2 URI",
new URL(await currentURL()).origin, "https://accounts.google.com")
await closeTab()
await click($("dialog.settings > .exitsettings"))
})
await test("Usage: Developer Portal", {skip: true}, async t => {
await click($("#settings"))
await click($(".SettingsButton:nth-child(5)"))
await waitFor(2000)
if (await $("#app-list-container div h2").exists()) {
await click($("#app-list-container div h2"))
await expectEqual(t, "Bot is not public",
await checkBox("Make bot publicly inviteable").isChecked(), false)
const appName = await textBox("Application name").value()
await click(button("Manage bot"))
await waitFor(2000)
await expectEqual(t, "Bot name",
await $("dialog > table > tr > h2").text(), "Editing bot: " + appName)
taiko.confirm(/.+/, async () => await accept())
taiko.alert(/.+/, async () => await accept())
await click(button("Reset token"))
await t.test("Bot token reset")
} else {
await write("automated-bot-" + Date.now(), textBox("Name"))
await click(button("Create application"))
await waitFor(2000)
await click(checkBox("Make bot publicly inviteable"))
await click(button("Save changes"))
await t.test("Create new application")
}
await click($("dialog.settings > .exitsettings"))
})
await test("Usage: Chatting", {skip: true}, async t => {
await click($("#servers div:nth-child(4)"))
await click($("#ch-1260645563867721629"))
const message = "Test message " + Date.now()
await write(message, $("#typebox"))
await press("Enter")
await waitFor(2000)
await expectEqual(t, "Send message", await $(".messagecontainer > .flexttb > " +
".messagediv:last-child > .message > .flexttb > .commentrow > .flexttb").text(), message)
})
await test("Usage: Discovery join & leave", async t => {
await click($("#servers > div.servericon"))
await waitFor(2000)
const name = await $(".discovery-guild:nth-child(1) h3").text()
await click($(".discovery-guild:nth-child(1)"))
await waitFor(2000)
await click($("#servers div:nth-child(5)"))
await waitFor(2000)
expectEqual(t, "Joined discovery server", await $("#servername").text(), name)
await rightClick($("#servers div:nth-child(5)"))
await click($(".contextmenu tr:nth-child(5) button"))
await click(button("Yes, I'm sure"))
t.test("Left discovery server")
})
} catch (error) {
console.error(error)
} finally {
await closeBrowser()
}
}
main()