Path: blob/master/test/externalTests/bossBar.js
3738 views
const assert = require('assert')1const { once, onceWithCleanup } = 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 state46const [bossBar] = await onceWithCleanup(bot, 'bossBarUpdated', {47timeout: 5000,48checkCondition: (bossBar) =>49bossBar.health === newHealth &&50bossBar.color === newColor &&51bossBar.dividers === 1052})53assert.strictEqual(bossBar.health, newHealth)54assert.strictEqual(bossBar.color, newColor)55assert.strictEqual(bossBar.dividers, 10)56}5758// Test boss bar deletion59const deleteBossBar = async () => {60const uuid = 'test:bar1'61bot.test.sayEverywhere(`/bossbar remove ${uuid}`)62await once(bot, 'bossBarDeleted')63assert.strictEqual(bot.bossBars.length, 0)64}6566try {67await createBossBar()68await updateBossBar()69await deleteBossBar()70console.log('[bossBar test] All tests passed!')71} catch (err) {72console.error('[bossBar test] Test failed:', err)73throw err74}75}767778