inner-audio.test.js 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
describe('inner-audio', () => {
  if (!process.env.uniTestPlatformInfo.startsWith('web')) {
    it('app', () => {
      expect(1).toBe(1)
    })
    return
  }
  beforeAll(async () => {
    page = await program.reLaunch('/pages/API/inner-audio/inner-audio')
    await page.waitFor('view');
  });

  function getData(key = '') {
    return new Promise(async (resolve, reject) => {
      const data = await page.data()
      resolve(key ? data[key] : data)
    })
  }

  it('onCanplay',async()=>{
    await page.waitFor(1000)
    await page.waitFor(async()=>{
      return await getData('isCanplay')
    })
    expect(await getData('buffered')).toBeGreaterThan(0)
  })

  it('play-onPlay-onTimeUpdate', async () => {
    await page.callMethod('play')
    await page.waitFor(3000);
    expect(await getData('isPlaying')).toBeTruthy()
    console.log("duration:",await getData('duration'),"currentTime:",await getData('currentTime'))
33
    expect(await getData('duration')).toBeCloseTo(175.109, 0);
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    // console.log("isPaused",await getData('isPaused'))
    // expect(await getData('currentTime')).toBeGreaterThan(0);
    // expect(await getData('isPaused')).toBeFalsy();
  });

  it('seek-onSeeking-onSeeked', async () => {
    await page.callMethod('onchange',20)
    await page.waitFor(500);
    expect(await getData('onSeekingTest')).toBeTruthy();
    // expect(await getData('onWaitingTest')).toBeTruthy();
    expect(await getData('onSeekedTest')).toBeTruthy();
  });

  it('pause-onPause', async () => {
    await page.callMethod('pause')
    await page.waitFor(500);
    expect(await getData('isPlaying')).toBeFalsy()
    // expect(await getData('isPaused')).toBeTruthy();
  });

  it('stop-onStop', async () => {
    await page.callMethod('play')
    await page.waitFor(2000);
    // 第一次点停止时,不触发onStop事件
    await page.callMethod('stop')
    await page.callMethod('stop')
    await page.waitFor(1000);
    expect(await getData('isPlaying')).toBeFalsy()
    // expect(await getData('isPaused')).toBeTruthy();
  });

  it('onEnded', async () => {
    await page.callMethod('onchange',173)
    await page.waitFor(500);
    await page.callMethod('play')
    await page.waitFor(3000);
    // expect(await getData('isPlayEnd')).toBeTruthy();
  });

});