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

  it('seek-onSeeking-onSeeked', async () => {
    await page.callMethod('onchange',20)
35 36
    const waitTime = process.env.uniTestPlatformInfo.includes('chrome') ? 1500:500
    await page.waitFor(waitTime)
37 38 39
    console.log("seek-onSeeking-onSeeked:",await page.data())
    expect(await page.data('onSeekingTest')).toBeTruthy();
    // expect(await page.data('onWaitingTest')).toBeTruthy();
40 41
    // expect(await page.data('onSeekedTest')).toBeTruthy();
    expect(await program.screenshot()).toSaveImageSnapshot();
42 43 44 45 46
  });

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

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

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

});