From 23f469e5c0da1bf16e47f5705cea84e7fdc967e6 Mon Sep 17 00:00:00 2001 From: yurj26 <1816387074@qq.com> Date: Fri, 30 Jun 2023 18:29:46 +0800 Subject: [PATCH] feat(progress): add test --- pages/component/progress/progress.test.js | 84 +++++++++++++++++++++++ pages/component/progress/progress.uvue | 23 +++++-- 2 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 pages/component/progress/progress.test.js diff --git a/pages/component/progress/progress.test.js b/pages/component/progress/progress.test.js new file mode 100644 index 00000000..de652ae7 --- /dev/null +++ b/pages/component/progress/progress.test.js @@ -0,0 +1,84 @@ +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(1000) +}) + +describe('Progress.uvue', () => { + it('percent', async () => { + const p = await page.$('.p') + const p1 = await page.$('.p1') + const p2 = await page.$('.p2') + const p3 = await page.$('.p3') + page.callMethod('setProgress') + await page.waitFor(1000) + expect(await p.property('percent')).toEqual(20) + expect(await p1.property('percent')).toEqual(40) + expect(await p2.property('percent')).toEqual(60) + expect(await p3.property('percent')).toEqual(80) + expect(await getData('curPercent')).toEqual(20) + 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 + }) + await page.waitFor(500) + 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 + }) + await page.waitFor(500) + 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 + }) + await page.waitFor(500) + 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 + }) + await page.waitFor(500) + 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" + }) + await page.waitFor(500) + expect(await el.property('background-color')).toEqual('#007aff') + }) +}) \ No newline at end of file diff --git a/pages/component/progress/progress.uvue b/pages/component/progress/progress.uvue index 3b07c020..54f6ede2 100644 --- a/pages/component/progress/progress.uvue +++ b/pages/component/progress/progress.uvue @@ -3,16 +3,18 @@ - + - + - + - + @@ -26,7 +28,14 @@ data() { return { title: 'progress', - pgList: [0, 0, 0, 0] as number[] + pgList: [0, 0, 0, 0] as number[], + + curPercent: 0, + showInfo: true, + borderRadius: 0, + fontSize: 16, + strokeWidth: 3, + backgroundColor: '#EBEBEB' } }, methods: { @@ -35,6 +44,10 @@ }, clearProgress() { this.pgList = [0, 0, 0, 0] as number[] + }, + activeend(e : ProgressActiveendEvent) { + // TODO e.detail.curPercent + this.curPercent = e.curPercent } } } -- GitLab