create-inner-audio-context.test.js 3.1 KB
Newer Older
1
describe('inner-audio', () => {
M
mahaifeng 已提交
2
  if (!(process.env.uniTestPlatformInfo.startsWith('web')||process.env.uniTestPlatformInfo.startsWith('android'))) {
3 4 5 6 7
    it('app', () => {
      expect(1).toBe(1)
    })
    return
  }
M
mahaifeng 已提交
8

9
  beforeAll(async () => {
10
    page = await program.reLaunch('/pages/API/create-inner-audio-context/create-inner-audio-context')
11 12 13 14 15 16
    await page.waitFor('view');
  });

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

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

  it('seek-onSeeking-onSeeked', async () => {
M
mahaifeng 已提交
35 36 37 38 39 40
    if (process.env.uniTestPlatformInfo.indexOf('android') > -1 ) {
    	expect(1).toBe(1)
    	return false
    }

    await page.callMethod('onchangeValue',20)
41 42
    const waitTime = process.env.uniTestPlatformInfo.includes('chrome') ? 1500:500
    await page.waitFor(waitTime)
43
    console.log("seek-onSeeking-onSeeked:",await page.data())
M
mahaifeng 已提交
44 45 46
    let isDone = await page.waitFor(async () => {
    	return await page.data('onSeekingTest')
    })
47 48
    expect(await page.data('onSeekingTest')).toBeTruthy();
    // expect(await page.data('onWaitingTest')).toBeTruthy();
49 50
    // expect(await page.data('onSeekedTest')).toBeTruthy();
    expect(await program.screenshot()).toSaveImageSnapshot();
51 52 53 54 55
  });

  it('pause-onPause', async () => {
    await page.callMethod('pause')
    await page.waitFor(500);
56 57
    expect(await page.data('isPlaying')).toBeFalsy()
    // expect(await page.data('isPaused')).toBeTruthy();
58 59 60 61 62 63 64 65 66
  });

  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);
67 68
    expect(await page.data('isPlaying')).toBeFalsy()
    // expect(await page.data('isPaused')).toBeTruthy();
69 70 71
  });

  it('onEnded', async () => {
M
mahaifeng 已提交
72
    await page.callMethod('onchangeValue',173)
73 74 75
    await page.waitFor(500);
    await page.callMethod('play')
    await page.waitFor(3000);
76
    // expect(await page.data('isPlayEnd')).toBeTruthy();
77
  });
78 79 80 81 82 83 84 85 86 87 88 89
  it('onEnded-android', async () => {
    if (!process.env.uniTestPlatformInfo.startsWith('android')) {
      expect(1).toBe(1)
      return
    }
    await page.setData({
    	isPlayEnd: false
    })
    await page.callMethod('setSrc','/static/uni-autoTest/alert2s.mp3')
    await page.waitFor(3000);
    expect(await page.data('isPlayEnd')).toBeTruthy();
  });
90
});