From 2055b54e012ba27e9ba1158eb333ca5e04f00cde Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Sat, 9 Dec 2023 23:01:22 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=86=B2=E7=AA=81=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/nodes-info/nodes-info.test.js | 113 +++++------ pages/component/progress/progress.test.js | 232 ++++++++-------------- 2 files changed, 130 insertions(+), 215 deletions(-) diff --git a/pages/API/nodes-info/nodes-info.test.js b/pages/API/nodes-info/nodes-info.test.js index 8b8e3297..0a3b04b5 100644 --- a/pages/API/nodes-info/nodes-info.test.js +++ b/pages/API/nodes-info/nodes-info.test.js @@ -1,66 +1,47 @@ -const PAGE_PATH = '/pages/API/nodes-info/nodes-info' - -const RECT_LEFT = 15; -const RECT_WIDTH = 150; -const RECT_HEIGHT = 100; - -describe('nodes-info', () => { - let page - beforeAll(async () => { - page = await program.reLaunch(PAGE_PATH) - await page.waitFor(500) - }) - it('get-node-info', async () => { - const btnGetNodeInfo = await page.$('.btn-get-node-info') - - await btnGetNodeInfo.tap() - await page.waitFor(50) - - const data = await page.data() - - // TODO 和浏览器的计算存在差异 - const nodeInfo = data.nodeInfoList[0] - expect(Math.round(nodeInfo.left)).toBe(RECT_LEFT) - expect(Math.round(nodeInfo.width)).toBe(RECT_WIDTH) - expect(Math.round(nodeInfo.height)).toBe(RECT_HEIGHT) - // android 6 分辨率为 720*1280,需要调整期望数值 - if (!process.env.uniTestPlatformInfo.startsWith('android 6')) { - const nodeInfo = data.nodeInfoList[0] - expect(nodeInfo.left > 15).toBe(true) - expect(nodeInfo.width == 150).toBe(true) - expect(nodeInfo.height == 100).toBe(true) - } - }) - it('get-all-node-info', async () => { - const btnGetAllNodeInfo = await page.$('.btn-get-all-node-info') - - await btnGetAllNodeInfo.tap() - await page.waitFor(50) - - const data = await page.data() - - const nodeInfo1 = data.nodeInfoList[0] - expect(Math.round(nodeInfo1.left)).toBe(RECT_LEFT) - expect(nodeInfo1.top > 220).toBe(true) - expect(Math.round(nodeInfo1.width)).toBe(RECT_WIDTH) - expect(Math.round(nodeInfo1.height)).toBe(RECT_HEIGHT) - if (!process.env.uniTestPlatformInfo.startsWith('android 6')) { - const nodeInfo1 = data.nodeInfoList[0] - expect(nodeInfo1.left > 15).toBe(true) - expect(nodeInfo1.top > 220).toBe(true) - expect(nodeInfo1.width == 150).toBe(true) - expect(nodeInfo1.height == 100).toBe(true) - - const nodeInfo2 = data.nodeInfoList[1] - expect(nodeInfo2.left > 200).toBe(true) - expect(nodeInfo2.top > 220).toBe(true) - expect(Math.round(nodeInfo2.width)).toBe(RECT_WIDTH) - expect(Math.round(nodeInfo2.height)).toBe(RECT_HEIGHT) - const nodeInfo2 = data.nodeInfoList[1] - expect(nodeInfo2.left > 200).toBe(true) - expect(nodeInfo2.top > 220).toBe(true) - expect(nodeInfo2.width == 150).toBe(true) - expect(nodeInfo2.height == 100).toBe(true) - } - }) -}) +const PAGE_PATH = '/pages/API/nodes-info/nodes-info' + +const RECT_LEFT = 15; +const RECT_WIDTH = 150; +const RECT_HEIGHT = 100; + +describe('nodes-info', () => { + let page + beforeAll(async () => { + page = await program.reLaunch(PAGE_PATH) + await page.waitFor(500) + }) + it('get-node-info', async () => { + const btnGetNodeInfo = await page.$('.btn-get-node-info') + + await btnGetNodeInfo.tap() + await page.waitFor(50) + + const data = await page.data() + + // TODO 和浏览器的计算存在差异 + const nodeInfo = data.nodeInfoList[0] + expect(Math.round(nodeInfo.left)).toBe(RECT_LEFT) + expect(Math.round(nodeInfo.width)).toBe(RECT_WIDTH) + expect(Math.round(nodeInfo.height)).toBe(RECT_HEIGHT) + }) + it('get-all-node-info', async () => { + const btnGetAllNodeInfo = await page.$('.btn-get-all-node-info') + + await btnGetAllNodeInfo.tap() + await page.waitFor(50) + + const data = await page.data() + + const nodeInfo1 = data.nodeInfoList[0] + expect(Math.round(nodeInfo1.left)).toBe(RECT_LEFT) + expect(nodeInfo1.top > 220).toBe(true) + expect(Math.round(nodeInfo1.width)).toBe(RECT_WIDTH) + expect(Math.round(nodeInfo1.height)).toBe(RECT_HEIGHT) + + const nodeInfo2 = data.nodeInfoList[1] + expect(nodeInfo2.left > 200).toBe(true) + expect(nodeInfo2.top > 220).toBe(true) + expect(Math.round(nodeInfo2.width)).toBe(RECT_WIDTH) + expect(Math.round(nodeInfo2.height)).toBe(RECT_HEIGHT) + }) +}) diff --git a/pages/component/progress/progress.test.js b/pages/component/progress/progress.test.js index f61e4c7a..61f8aad6 100644 --- a/pages/component/progress/progress.test.js +++ b/pages/component/progress/progress.test.js @@ -1,149 +1,83 @@ -function getData(key = '') { - return new Promise(async (resolve, reject) => { - const data = await page.data() - resolve(key ? data[key] : data) - }) -} - -let page -beforeAll(async () => { - page = await program.reLaunch('/pages/component/progress/progress') - await page.waitFor(2000); - page = await program.reLaunch('/pages/component/progress/progress') - await page.waitFor(2000); -}) - -describe('Progress.uvue', () => { - it('percent', async () => { - await page.callMethod('setProgress') - await page.waitFor(1000); - const p = await page.$('.p') - expect(await p.property('percent')).toEqual(20) - const p1 = await page.$('.p1') - expect(await p1.property('percent')).toEqual(40) - const p2 = await page.$('.p2') - expect(await p2.property('percent')).toEqual(60) - const p3 = await page.$('.p3') - expect(await p3.property('percent')).toEqual(80) - if (process.env.UNI_PLATFORM === 'app-android') { - expect(await getData('curPercent')).toEqual(20) - } - await page.callMethod('clearProgress') - await page.waitFor(1000) - expect(await p.property('percent')).toEqual(0) - expect(await p1.property('percent')).toEqual(0) - expect(await p2.property('percent')).toEqual(0) - expect(await p3.property('percent')).toEqual(0) - if (process.env.UNI_PLATFORM === 'app-android') { - expect(await getData('curPercent')).toEqual(0) - } - }) - it('length', async () => { - const elements = await page.$$('.progress') - expect(elements.length).toBe(4) - }) - it('show-info', async () => { - const el = await page.$('.p') - expect(await el.property('show-info')).toEqual(true) - await page.setData({ - showInfo: false - }) - expect(await el.property('show-info')).toEqual(false) - }) - it('border-radius', async () => { - const el = await page.$('.p') - expect(await el.property('border-radius')).toEqual(0) - await page.setData({ - borderRadius: 5 - }) - expect(await el.property('border-radius')).toEqual(5) - }) - it('font-size', async () => { - const el = await page.$('.p') - expect(await el.property('font-size')).toEqual(16) - await page.setData({ - fontSize: 18 - }) - expect(await el.property('font-size')).toEqual(18) - }) - it('stroke-width', async () => { - const el = await page.$('.p') - expect(await el.property('stroke-width')).toEqual(3) - await page.setData({ - strokeWidth: 6 - }) - expect(await el.property('stroke-width')).toEqual(6) - }) - it('backgroundColor', async () => { - const el = await page.$('.p') - expect(await el.property('background-color')).toEqual('#EBEBEB') - await page.setData({ - backgroundColor: "#007aff" - }) - expect(await el.property('background-color')).toEqual('#007aff') - }) - it('percent', async () => { - await page.callMethod('setProgress') - await page.waitFor(1000); - const p = await page.$('.p') - expect(await p.property('percent')).toEqual(20) - const p1 = await page.$('.p1') - expect(await p1.property('percent')).toEqual(40) - const p2 = await page.$('.p2') - expect(await p2.property('percent')).toEqual(60) - const p3 = await page.$('.p3') - expect(await p3.property('percent')).toEqual(80) - expect(await getData('curPercent')).toEqual(20) - await page.callMethod('clearProgress') - await page.waitFor(1000) - expect(await p.property('percent')).toEqual(0) - expect(await p1.property('percent')).toEqual(0) - expect(await p2.property('percent')).toEqual(0) - expect(await p3.property('percent')).toEqual(0) - expect(await getData('curPercent')).toEqual(0) - }) - it('length', async () => { - const elements = await page.$$('.progress') - expect(elements.length).toBe(4) - }) - it('show-info', async () => { - const el = await page.$('.p') - expect(await el.property('show-info')).toEqual(true) - await page.setData({ - showInfo: false - }) - expect(await el.property('show-info')).toEqual(false) - }) - it('border-radius', async () => { - const el = await page.$('.p') - expect(await el.property('border-radius')).toEqual(0) - await page.setData({ - borderRadius: 5 - }) - expect(await el.property('border-radius')).toEqual(5) - }) - it('font-size', async () => { - const el = await page.$('.p') - expect(await el.property('font-size')).toEqual(16) - await page.setData({ - fontSize: 18 - }) - expect(await el.property('font-size')).toEqual(18) - }) - it('stroke-width', async () => { - const el = await page.$('.p') - expect(await el.property('stroke-width')).toEqual(3) - await page.setData({ - strokeWidth: 6 - }) - expect(await el.property('stroke-width')).toEqual(6) - }) - it('backgroundColor', async () => { - const el = await page.$('.p') - expect(await el.property('background-color')).toEqual('#EBEBEB') - await page.setData({ - backgroundColor: "#007aff" - }) - expect(await el.property('background-color')).toEqual('#007aff') - }) -}) \ No newline at end of file +function getData(key = '') { + return new Promise(async (resolve, reject) => { + const data = await page.data() + resolve(key ? data[key] : data) + }) +} + +let page +beforeAll(async () => { + page = await program.reLaunch('/pages/component/progress/progress') + await page.waitFor(2000); +}) + +describe('Progress.uvue', () => { + it('percent', async () => { + await page.callMethod('setProgress') + await page.waitFor(1000); + const p = await page.$('.p') + expect(await p.property('percent')).toEqual(20) + const p1 = await page.$('.p1') + expect(await p1.property('percent')).toEqual(40) + const p2 = await page.$('.p2') + expect(await p2.property('percent')).toEqual(60) + const p3 = await page.$('.p3') + expect(await p3.property('percent')).toEqual(80) + if (process.env.UNI_PLATFORM === 'app-android') { + expect(await getData('curPercent')).toEqual(20) + } + await page.callMethod('clearProgress') + await page.waitFor(1000) + expect(await p.property('percent')).toEqual(0) + expect(await p1.property('percent')).toEqual(0) + expect(await p2.property('percent')).toEqual(0) + expect(await p3.property('percent')).toEqual(0) + if (process.env.UNI_PLATFORM === 'app-android') { + expect(await getData('curPercent')).toEqual(0) + } + }) + it('length', async () => { + const elements = await page.$$('.progress') + expect(elements.length).toBe(4) + }) + it('show-info', async () => { + const el = await page.$('.p') + expect(await el.property('show-info')).toEqual(true) + await page.setData({ + showInfo: false + }) + expect(await el.property('show-info')).toEqual(false) + }) + it('border-radius', async () => { + const el = await page.$('.p') + expect(await el.property('border-radius')).toEqual(0) + await page.setData({ + borderRadius: 5 + }) + expect(await el.property('border-radius')).toEqual(5) + }) + it('font-size', async () => { + const el = await page.$('.p') + expect(await el.property('font-size')).toEqual(16) + await page.setData({ + fontSize: 18 + }) + expect(await el.property('font-size')).toEqual(18) + }) + it('stroke-width', async () => { + const el = await page.$('.p') + expect(await el.property('stroke-width')).toEqual(3) + await page.setData({ + strokeWidth: 6 + }) + expect(await el.property('stroke-width')).toEqual(6) + }) + it('backgroundColor', async () => { + const el = await page.$('.p') + expect(await el.property('background-color')).toEqual('#EBEBEB') + await page.setData({ + backgroundColor: "#007aff" + }) + expect(await el.property('background-color')).toEqual('#007aff') + }) +}) -- GitLab