mirror of
https://github.com/sky-systems/sky_phone.git
synced 2026-09-01 10:48:55 +00:00
1b453e3456
Play the supplied notification vibration asset for muted push banners and loop the supplied call vibration asset for muted incoming calls. Remove the synthesized vibration tone, add playback coverage, and provide a development preview for the muted notification path.
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { ALARM_SOUND_IDS } from './alarms'
|
|
import { phoneToneDuration, playPhoneVibration } from './tones'
|
|
|
|
describe('phone tones', () => {
|
|
afterEach(() => vi.unstubAllGlobals())
|
|
|
|
it('defines a playable duration for every alarm sound', () => {
|
|
for (const sound of ALARM_SOUND_IDS) {
|
|
expect(phoneToneDuration(sound)).toBeGreaterThan(0)
|
|
expect(phoneToneDuration(sound)).toBeLessThanOrEqual(1500)
|
|
}
|
|
})
|
|
|
|
it.each([
|
|
['notification', 'sounds/vibration-notification.mp3', false],
|
|
['call', 'sounds/vibration-call.mp3', true],
|
|
] as const)(
|
|
'plays the %s vibration asset with the requested loop behavior',
|
|
(kind, path, loop) => {
|
|
const pause = vi.fn()
|
|
const play = vi.fn(async () => undefined)
|
|
const players: Array<{
|
|
currentTime: number
|
|
loop: boolean
|
|
pause: () => void
|
|
play: () => Promise<void>
|
|
preload: string
|
|
src: string
|
|
volume: number
|
|
}> = []
|
|
vi.stubGlobal(
|
|
'Audio',
|
|
class {
|
|
currentTime = 7
|
|
loop = false
|
|
pause = pause
|
|
play = play
|
|
preload = ''
|
|
src: string
|
|
volume = 0
|
|
|
|
constructor(src: string) {
|
|
this.src = src
|
|
players.push(this)
|
|
}
|
|
},
|
|
)
|
|
|
|
const stop = playPhoneVibration(kind, loop)
|
|
|
|
expect(players[0]).toMatchObject({
|
|
loop,
|
|
preload: 'auto',
|
|
src: expect.stringContaining(path),
|
|
volume: 1,
|
|
})
|
|
expect(play).toHaveBeenCalledOnce()
|
|
stop()
|
|
expect(pause).toHaveBeenCalledOnce()
|
|
expect(players[0].currentTime).toBe(0)
|
|
},
|
|
)
|
|
})
|