From d8dd1a17b4faf95fff97be50e452211824e6582b Mon Sep 17 00:00:00 2001 From: Anne_LXM Date: Fri, 24 May 2024 21:22:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4inner-audio=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?/=E6=96=B0=E5=A2=9Emovable-view=E6=B5=8B=E8=AF=95=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/inner-audio/inner-audio.test.js | 74 ++++ pages/API/inner-audio/inner-audio.uvue | 319 ++++++++++-------- .../movable-view/movable-view.test.js | 30 ++ 3 files changed, 286 insertions(+), 137 deletions(-) create mode 100644 pages/API/inner-audio/inner-audio.test.js create mode 100644 pages/component/movable-view/movable-view.test.js diff --git a/pages/API/inner-audio/inner-audio.test.js b/pages/API/inner-audio/inner-audio.test.js new file mode 100644 index 00000000..8538001b --- /dev/null +++ b/pages/API/inner-audio/inner-audio.test.js @@ -0,0 +1,74 @@ +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') + }) + console.log("获取缓冲信息",await getData('buffered')) + 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')) + expect(await getData('duration')).toBe(175.109) + // 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(); + }); + +}); diff --git a/pages/API/inner-audio/inner-audio.uvue b/pages/API/inner-audio/inner-audio.uvue index 093c831e..bf4991c4 100644 --- a/pages/API/inner-audio/inner-audio.uvue +++ b/pages/API/inner-audio/inner-audio.uvue @@ -1,22 +1,34 @@ diff --git a/pages/component/movable-view/movable-view.test.js b/pages/component/movable-view/movable-view.test.js new file mode 100644 index 00000000..eb25b97b --- /dev/null +++ b/pages/component/movable-view/movable-view.test.js @@ -0,0 +1,30 @@ +let page; +describe('movable-view.uvue', () => { + console.log(process.env.uniTestPlatformInfo,process.env.uniTestPlatformInfo.startsWith('web')) + if (!process.env.uniTestPlatformInfo.startsWith('web')) { + it('app', () => { + expect(1).toBe(1) + }) + return + } + beforeAll(async () => { + page = await program.reLaunch('/pages/component/movable-view/movable-view') + await page.waitFor('view'); + }); + + it('移动至 (30px, 30px)', async () => { + expect(await page.data('x')).toBe(0) + expect(await page.data('y')).toBe(0) + await page.callMethod('tap') + await page.waitFor(500); + expect(await page.data('x')).toBe(30) + expect(await page.data('y')).toBe(30) + }) + it('放大3倍', async () => { + expect(await page.data('scale')).toBe(2) + await page.callMethod('tap2') + await page.waitFor(500); + expect(await page.data('scale')).toBe(3) + }) + +}) -- GitLab