create-inner-audio-context.test.js 2.2 KB
Newer Older
1 2 3 4 5 6 7 8
describe('inner-audio', () => {
  if (!process.env.uniTestPlatformInfo.startsWith('web')) {
    it('app', () => {
      expect(1).toBe(1)
    })
    return
  }
  beforeAll(async () => {
9
    page = await program.reLaunch('/pages/API/create-inner-audio-context/create-inner-audio-context')
10 11 12 13 14 15
    await page.waitFor('view');
  });

  it('onCanplay',async()=>{
    await page.waitFor(1000)
    await page.waitFor(async()=>{
16
      return await page.data('isCanplay')
17
    })
18
    expect(await page.data('buffered')).toBeGreaterThan(0)
19 20 21 22 23
  })

  it('play-onPlay-onTimeUpdate', async () => {
    await page.callMethod('play')
    await page.waitFor(3000);
24 25 26 27 28 29
    expect(await page.data('isPlaying')).toBeTruthy()
    console.log("duration:",await page.data('duration'),"currentTime:",await page.data('currentTime'))
    expect(await page.data('duration')).toBeCloseTo(175.109, 0);
    // console.log("isPaused",await page.data('isPaused'))
    // expect(await page.data('currentTime')).toBeGreaterThan(0);
    // expect(await page.data('isPaused')).toBeFalsy();
30 31 32 33 34
  });

  it('seek-onSeeking-onSeeked', async () => {
    await page.callMethod('onchange',20)
    await page.waitFor(500);
35 36 37 38
    console.log("seek-onSeeking-onSeeked:",await page.data())
    expect(await page.data('onSeekingTest')).toBeTruthy();
    // expect(await page.data('onWaitingTest')).toBeTruthy();
    expect(await page.data('onSeekedTest')).toBeTruthy();
39 40 41 42 43
  });

  it('pause-onPause', async () => {
    await page.callMethod('pause')
    await page.waitFor(500);
44 45
    expect(await page.data('isPlaying')).toBeFalsy()
    // expect(await page.data('isPaused')).toBeTruthy();
46 47 48 49 50 51 52 53 54
  });

  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);
55 56
    expect(await page.data('isPlaying')).toBeFalsy()
    // expect(await page.data('isPaused')).toBeTruthy();
57 58 59 60 61 62 63
  });

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

});