Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS
GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/test/externalTests/title.js
2155 views
1
const { once } = require('../../lib/promise_utils')
2
3
module.exports = () => async (bot) => {
4
// Test title
5
bot.chat('/title @a title {"text":"Test Title"}')
6
const [title, type] = await once(bot, 'title', 2000)
7
if (title !== 'Test Title' || type !== 'title') {
8
throw new Error(`Title test failed: expected "Test Title" but got "${title}" with type "${type}"`)
9
}
10
11
// Test subtitle
12
bot.chat('/title @a subtitle {"text":"Test Subtitle"}')
13
const [subtitle, subtitleType] = await once(bot, 'title', 20000)
14
if (subtitle !== 'Test Subtitle' || subtitleType !== 'subtitle') {
15
throw new Error(`Subtitle test failed: expected "Test Subtitle" but got "${subtitle}" with type "${subtitleType}"`)
16
}
17
18
// Test title_times event
19
bot.chat('/title @a times 10 20 30')
20
const [fadeIn, stay, fadeOut] = await once(bot, 'title_times', 20000)
21
if (fadeIn !== 10 || stay !== 20 || fadeOut !== 30) {
22
throw new Error(`title_times event failed: expected (10,20,30) but got (${fadeIn},${stay},${fadeOut})`)
23
}
24
25
// Test combined title and subtitle
26
bot.chat('/title @a title {"text":"Test Title"}')
27
const [combinedTitle, combinedTitleType] = await once(bot, 'title', 20000)
28
if (combinedTitle !== 'Test Title' || combinedTitleType !== 'title') {
29
throw new Error(`Combined title test failed: expected "Test Title" but got "${combinedTitle}" with type "${combinedTitleType}"`)
30
}
31
32
bot.chat('/title @a subtitle {"text":"Test Subtitle"}')
33
const [combinedSubtitle, combinedSubtitleType] = await once(bot, 'title', 20000)
34
if (combinedSubtitle !== 'Test Subtitle' || combinedSubtitleType !== 'subtitle') {
35
throw new Error(`Combined subtitle test failed: expected "Test Subtitle" but got "${combinedSubtitle}" with type "${combinedSubtitleType}"`)
36
}
37
38
// Test clearing title
39
bot.chat('/title @a clear')
40
await once(bot, 'title_clear', 2000)
41
}
42
43