Path: blob/master/test/externalTests/bossBar.js
2155 views
const assert = require('assert')1const { once } = require('../../lib/promise_utils')23module.exports = (version) => async (bot) => {4// Skip test for versions older than 1.13 (bossbar command not available)5if (bot.registry.isOlderThan('1.13')) return67console.log('[bossBar test] Starting boss bar tests')89// Test boss bar creation10const createBossBar = async () => {11const uuid = 'test:bar1'12const title = 'Test Boss Bar'13const colorName = 'red'14const styleName = 'notched_6'15const health = 0.51617bot.test.sayEverywhere(`/bossbar add ${uuid} "${title}"`)18bot.test.sayEverywhere(`/bossbar set ${uuid} players ${bot.username}`)19bot.test.sayEverywhere(`/bossbar set ${uuid} color ${colorName}`)20bot.test.sayEverywhere(`/bossbar set ${uuid} style ${styleName}`)21bot.test.sayEverywhere(`/bossbar set ${uuid} value ${health * 100}`)22bot.test.sayEverywhere(`/bossbar set ${uuid} visible true`)2324// Wait for the boss bar to be created25const [bossBar] = await once(bot, 'bossBarCreated')26console.log('DEBUG bossBar:', bossBar)27console.log('DEBUG bossBar own properties:', Object.getOwnPropertyNames(bossBar))28console.log('DEBUG bossBar prototype:', Object.getPrototypeOf(bossBar))29console.log('DEBUG bossBar.title:', bossBar.title, 'type:', typeof bossBar.title)30assert.strictEqual(bossBar.title.toString(), title)31// Do not check dividers or color here; they will be updated in the next step32}3334// Test boss bar update35const updateBossBar = async () => {36const uuid = 'test:bar1'37const newHealth = 0.7538const newColor = 'blue'39const newStyle = 'notched_10'4041bot.test.sayEverywhere(`/bossbar set ${uuid} color ${newColor}`)42bot.test.sayEverywhere(`/bossbar set ${uuid} style ${newStyle}`)43bot.test.sayEverywhere(`/bossbar set ${uuid} value ${newHealth * 100}`)4445// Wait for the boss bar to have the expected state46let bossBar47while (true) {48[bossBar] = await once(bot, 'bossBarUpdated')49if (50bossBar.health === newHealth &&51bossBar.color === newColor &&52bossBar.dividers === 1053) break54}55assert.strictEqual(bossBar.health, newHealth)56assert.strictEqual(bossBar.color, newColor)57assert.strictEqual(bossBar.dividers, 10)58}5960// Test boss bar deletion61const deleteBossBar = async () => {62const uuid = 'test:bar1'63bot.test.sayEverywhere(`/bossbar remove ${uuid}`)64await once(bot, 'bossBarDeleted')65assert.strictEqual(bot.bossBars.length, 0)66}6768try {69await createBossBar()70await updateBossBar()71await deleteBossBar()72console.log('[bossBar test] All tests passed!')73} catch (err) {74console.error('[bossBar test] Test failed:', err)75throw err76}77}787980