From 7b3c6175c9997097a4a9bac844b7c96b4d866e64 Mon Sep 17 00:00:00 2001 From: yurj26 <1816387074@qq.com> Date: Fri, 30 Jun 2023 16:04:32 +0800 Subject: [PATCH] feat(radio): add test --- pages/component/radio/radio.test.js | 68 +++++++++++++++++++++++++++++ pages/component/radio/radio.uvue | 34 ++++++++++----- 2 files changed, 91 insertions(+), 11 deletions(-) create mode 100644 pages/component/radio/radio.test.js diff --git a/pages/component/radio/radio.test.js b/pages/component/radio/radio.test.js new file mode 100644 index 00000000..5a3c3b8f --- /dev/null +++ b/pages/component/radio/radio.test.js @@ -0,0 +1,68 @@ +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/radio/radio') + await page.waitFor(1000) +}) + +describe('Radio.uvue', () => { + it('change', async () => { + const radio = await page.$('.r') + const radio1 = await page.$('.r1') + const radio2 = await page.$('.r2') + expect(await getData('value')).toEqual("") + await radio1.tap() + expect(await getData('value')).toEqual("r1") + await radio.tap() + expect(await getData('value')).toEqual("r") + await radio2.tap() + expect(await getData('value')).toEqual("r") + }) + it('length', async () => { + const radioGroupElements = await page.$$('.radio-group') + expect(radioGroupElements.length).toBe(3) + const radioElements = await page.$$('.radio') + expect(radioElements.length).toBe(11) + }) + it('text', async () => { + const radio = await page.$('.r') + expect(await radio.text()).toEqual('选中') + await page.setData({ + text: 'checked' + }) + expect(await radio.text()).toEqual('checked') + }) + it('checked', async () => { + const radio = await page.$('.r') + expect(await radio.property('checked')).toBe(true) + await page.setData({ + checked: false + }) + await page.waitFor(500) + expect(await radio.property('checked')).toBe(false) + }) + it('color', async () => { + const radio = await page.$('.r') + expect(await radio.property('color')).toBe('#007aff') + await page.setData({ + color: '#63acfc' + }) + await page.waitFor(500) + expect(await radio.property('color')).toBe('#63acfc') + }) + it('disabled', async () => { + const radio = await page.$('.r2') + expect(await radio.property('disabled')).toBe(true) + await page.setData({ + disabled: false + }) + await page.waitFor(500) + expect(await radio.property('disabled')).toBe(false) + }) +}) \ No newline at end of file diff --git a/pages/component/radio/radio.uvue b/pages/component/radio/radio.uvue index eddac277..69764f85 100644 --- a/pages/component/radio/radio.uvue +++ b/pages/component/radio/radio.uvue @@ -7,10 +7,12 @@ 默认样式 - - 选中 - 未选中 - + + {{text}} + + 未选中 + 禁用 + @@ -18,11 +20,12 @@ 不同颜色和尺寸的radio - - 选中 + + 选中 - 未选中 - + 未选中 + @@ -32,8 +35,8 @@ - - + {{item.name}} @@ -76,7 +79,13 @@ name: '法国' }, ] as ItemType[], - current: 0 + current: 0, + + value: '', + text: '选中', + disabled: true, + checked: true, + color: '#007aff' } }, methods: { @@ -87,6 +96,9 @@ break; } } + }, + testChange(e : RadioGroupChangeEvent) { + this.value = e.detail.value } } } -- GitLab