create-inner-audio-context.test.js 2.5 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
  })

  it('play-onPlay-onTimeUpdate', async () => {
    await page.callMethod('play')
23 24
    const waitTime = process.env.uniTestPlatformInfo.includes('chrome') ? 5000:3000
    await page.waitFor(waitTime)
25 26 27 28 29 30
    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();
31 32
  });

33 34 35 36
  it('screenshot', async () => {
    expect(await program.screenshot()).toSaveImageSnapshot();
  });

37 38
  it('seek-onSeeking-onSeeked', async () => {
    await page.callMethod('onchange',20)
39 40
    const waitTime = process.env.uniTestPlatformInfo.includes('chrome') ? 1500:500
    await page.waitFor(waitTime)
41 42 43 44
    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();
45 46 47 48 49
  });

  it('pause-onPause', async () => {
    await page.callMethod('pause')
    await page.waitFor(500);
50 51
    expect(await page.data('isPlaying')).toBeFalsy()
    // expect(await page.data('isPaused')).toBeTruthy();
52 53 54 55 56 57 58 59 60
  });

  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);
61 62
    expect(await page.data('isPlaying')).toBeFalsy()
    // expect(await page.data('isPaused')).toBeTruthy();
63 64 65 66 67 68 69
  });

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

});