35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
|
|
test('shared audio feedback reuses one player and switches success and error sounds', async () => {
|
|
const calls = []
|
|
const player = {
|
|
src: '',
|
|
stop() { calls.push('stop') },
|
|
play() { calls.push(`play:${this.src}`) },
|
|
destroy() { calls.push('destroy') }
|
|
}
|
|
let created = 0
|
|
globalThis.uni = {
|
|
createInnerAudioContext() { created += 1; return player }
|
|
}
|
|
|
|
const audio = await import('../src/utils/audio-feedback.js')
|
|
assert.equal(audio.playSuccessSound(), true)
|
|
assert.equal(audio.playErrorSound(), true)
|
|
assert.equal(created, 1)
|
|
assert.deepEqual(calls, [
|
|
'play:/static/mp3/success.mp3',
|
|
'stop', 'play:/static/mp3/fail.mp3'
|
|
])
|
|
audio.destroyFeedbackSound()
|
|
assert.equal(calls.at(-1), 'destroy')
|
|
delete globalThis.uni
|
|
})
|
|
|
|
test('shared audio feedback is a safe no-op outside uni-app', async () => {
|
|
const audio = await import('../src/utils/audio-feedback.js')
|
|
assert.equal(audio.playFeedbackSound('unknown'), false)
|
|
assert.equal(audio.playSuccessSound(), false)
|
|
})
|