|
| 1 | +const assert = require('assert') |
| 2 | +const { once } = require('../../lib/promise_utils') |
| 3 | + |
| 4 | +module.exports = (version) => async (bot) => { |
| 5 | + // Skip test for versions older than 1.13 (bossbar command not available) |
| 6 | + if (bot.registry.isOlderThan('1.13')) return |
| 7 | + |
| 8 | + console.log('[bossBar test] Starting boss bar tests') |
| 9 | + |
| 10 | + // Test boss bar creation |
| 11 | + const createBossBar = async () => { |
| 12 | + const uuid = 'test:bar1' |
| 13 | + const title = 'Test Boss Bar' |
| 14 | + const colorName = 'red' |
| 15 | + const styleName = 'notched_6' |
| 16 | + const health = 0.5 |
| 17 | + |
| 18 | + bot.test.sayEverywhere(`/bossbar add ${uuid} "${title}"`) |
| 19 | + bot.test.sayEverywhere(`/bossbar set ${uuid} players ${bot.username}`) |
| 20 | + bot.test.sayEverywhere(`/bossbar set ${uuid} color ${colorName}`) |
| 21 | + bot.test.sayEverywhere(`/bossbar set ${uuid} style ${styleName}`) |
| 22 | + bot.test.sayEverywhere(`/bossbar set ${uuid} value ${health * 100}`) |
| 23 | + bot.test.sayEverywhere(`/bossbar set ${uuid} visible true`) |
| 24 | + |
| 25 | + // Wait for the boss bar to be created |
| 26 | + const [bossBar] = await once(bot, 'bossBarCreated') |
| 27 | + console.log('DEBUG bossBar:', bossBar) |
| 28 | + console.log('DEBUG bossBar own properties:', Object.getOwnPropertyNames(bossBar)) |
| 29 | + console.log('DEBUG bossBar prototype:', Object.getPrototypeOf(bossBar)) |
| 30 | + console.log('DEBUG bossBar.title:', bossBar.title, 'type:', typeof bossBar.title) |
| 31 | + assert.strictEqual(bossBar.title.toString(), title) |
| 32 | + // Do not check dividers or color here; they will be updated in the next step |
| 33 | + } |
| 34 | + |
| 35 | + // Test boss bar update |
| 36 | + const updateBossBar = async () => { |
| 37 | + const uuid = 'test:bar1' |
| 38 | + const newHealth = 0.75 |
| 39 | + const newColor = 'blue' |
| 40 | + const newStyle = 'notched_10' |
| 41 | + |
| 42 | + bot.test.sayEverywhere(`/bossbar set ${uuid} color ${newColor}`) |
| 43 | + bot.test.sayEverywhere(`/bossbar set ${uuid} style ${newStyle}`) |
| 44 | + bot.test.sayEverywhere(`/bossbar set ${uuid} value ${newHealth * 100}`) |
| 45 | + |
| 46 | + // Wait for the boss bar to have the expected state |
| 47 | + let bossBar |
| 48 | + while (true) { |
| 49 | + [bossBar] = await once(bot, 'bossBarUpdated') |
| 50 | + if ( |
| 51 | + bossBar.health === newHealth && |
| 52 | + bossBar.color === newColor && |
| 53 | + bossBar.dividers === 10 |
| 54 | + ) break |
| 55 | + } |
| 56 | + assert.strictEqual(bossBar.health, newHealth) |
| 57 | + assert.strictEqual(bossBar.color, newColor) |
| 58 | + assert.strictEqual(bossBar.dividers, 10) |
| 59 | + } |
| 60 | + |
| 61 | + // Test boss bar deletion |
| 62 | + const deleteBossBar = async () => { |
| 63 | + const uuid = 'test:bar1' |
| 64 | + bot.test.sayEverywhere(`/bossbar remove ${uuid}`) |
| 65 | + await once(bot, 'bossBarDeleted') |
| 66 | + assert.strictEqual(bot.bossBars.length, 0) |
| 67 | + } |
| 68 | + |
| 69 | + try { |
| 70 | + await createBossBar() |
| 71 | + await updateBossBar() |
| 72 | + await deleteBossBar() |
| 73 | + console.log('[bossBar test] All tests passed!') |
| 74 | + } catch (err) { |
| 75 | + console.error('[bossBar test] Test failed:', err) |
| 76 | + throw err |
| 77 | + } |
| 78 | +} |
0 commit comments