chore: initial commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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('../utils/audio-feedback.js')
|
||||
assert.equal(audio.playSuccessSound(), true)
|
||||
assert.equal(audio.playErrorSound(), true)
|
||||
assert.equal(created, 1)
|
||||
assert.deepEqual(calls, [
|
||||
'stop', '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('../utils/audio-feedback.js')
|
||||
assert.equal(audio.playFeedbackSound('unknown'), false)
|
||||
assert.equal(audio.playSuccessSound(), false)
|
||||
})
|
||||
Reference in New Issue
Block a user