const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
const isIos = platformInfo.startsWith('ios')
const isHarmony = platformInfo.toLocaleLowerCase().startsWith('harmony')
const isSafari = platformInfo.indexOf('safari') > -1
const isAndroid = platformInfo.startsWith('android')
const isWeb = platformInfo.startsWith('web')
describe('inner-audio', () => {
if (isMP || isIos || isSafari) {
it('not support', () => {
expect(1).toBe(1)
})
return
}
beforeAll(async () => {
page = await program.reLaunch('/pages/API/create-inner-audio-context/create-inner-audio-context')
await page.waitFor('view');
await page.waitFor(1000);
});
if (isWeb) {
it('screenshot', async () => {
const image = await program.screenshot({fullPage: true})
expect(image).toSaveImageSnapshot();
});
}
it('onCanplay',async()=>{
await page.waitFor(1000)
await page.waitFor(async()=>{
return await page.data('isCanplay')
})
const isCanplay = await page.data('isCanplay')
if (!isHarmony) {
expect(await page.data('buffered')).toBeGreaterThan(0)
} else {
expect(isCanplay).toBe(true)
}
})
it('seek-onSeeking-onSeeked', async () => {
if (isAndroid) {
expect(1).toBe(1)
return false
}
await page.callMethod('onchangeValue',20)
const waitTime = isWeb ? 5000:500
await page.waitFor(waitTime)
expect(await page.data('onSeekingTest')).toBeTruthy();
expect(await page.data('currentTime')).toBe(20);
const image = await program.screenshot({fullPage: true})
expect(image).toSaveImageSnapshot();
});
it('play-onPlay-onTimeUpdate', async () => {
await page.callMethod('play')
const waitTime = isWeb ? 5000:3000
await page.waitFor(waitTime)
expect(await page.data('isPlaying')).toBeTruthy()
expect(await page.data('duration')).toBeCloseTo(175.109, 0);
});
it('pause-onPause', async () => {
await page.callMethod('pause')
await page.waitFor(500);
expect(await page.data('isPlaying')).toBeFalsy()
});
it('stop-onStop', async () => {
await page.callMethod('play')
await page.waitFor(2000);
await page.callMethod('stop')
await page.callMethod('stop')
await page.waitFor(1000);
expect(await page.data('isPlaying')).toBeFalsy()
});
it('onEnded', async () => {
await page.callMethod('onchangeValue',173)
await page.waitFor(500);
await page.callMethod('play')
await page.waitFor(3000);
});
it('onEnded-android', async () => {
if (!isAndroid) {
expect(1).toBe(1)
return
}
await page.setData({
isPlayEnd: false
})
await page.callMethod('setSrc','file:///android_asset/uni-autoTest/alert2s.mp3')
await page.callMethod('play')
await page.waitFor(3000);
expect(await page.data('isPlayEnd')).toBeTruthy();
});
});