From 551ee7c6ffcf5e4519588537c5656ff3c3a8b880 Mon Sep 17 00:00:00 2001
From: yurj26 <1816387074@qq.com>
Date: Fri, 30 Jun 2023 15:29:58 +0800
Subject: [PATCH] feat(checkbox): add test
---
pages/component/checkbox/checkbox.test.js | 68 +++++++++++++++++++++++
pages/component/checkbox/checkbox.uvue | 31 +++++++----
2 files changed, 89 insertions(+), 10 deletions(-)
create mode 100644 pages/component/checkbox/checkbox.test.js
diff --git a/pages/component/checkbox/checkbox.test.js b/pages/component/checkbox/checkbox.test.js
new file mode 100644
index 00000000..39ebb22b
--- /dev/null
+++ b/pages/component/checkbox/checkbox.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/checkbox/checkbox')
+ await page.waitFor(1000)
+})
+
+describe('Checkbox.uvue', () => {
+ it('change', async () => {
+ const cb = await page.$('.cb')
+ const cb1 = await page.$('.cb1')
+ const cb2 = await page.$('.cb2')
+ expect(await getData('value')).toEqual([])
+ await cb1.tap()
+ expect(await getData('value')).toEqual(["cb", "cb1"])
+ await cb.tap()
+ expect(await getData('value')).toEqual(["cb1"])
+ await cb2.tap()
+ expect(await getData('value')).toEqual(["cb1"])
+ })
+ it('length', async () => {
+ const checkboxGroupElements = await page.$$('.checkbox-group')
+ expect(checkboxGroupElements.length).toBe(3)
+ const checkboxElements = await page.$$('.checkbox')
+ expect(checkboxElements.length).toBe(11)
+ })
+ it('text', async () => {
+ const cb = await page.$('.cb')
+ expect(await cb.text()).toEqual('选中')
+ await page.setData({
+ text: 'checked'
+ })
+ expect(await cb.text()).toEqual('checked')
+ })
+ it('checked', async () => {
+ const cb = await page.$('.cb')
+ expect(await cb.property('checked')).toBe(true)
+ await page.setData({
+ checked: false
+ })
+ await page.waitFor(500)
+ expect(await cb.property('checked')).toBe(false)
+ })
+ it('color', async () => {
+ const cb = await page.$('.cb')
+ expect(await cb.property('color')).toBe('#007aff')
+ await page.setData({
+ color: '#63acfc'
+ })
+ await page.waitFor(500)
+ expect(await cb.property('color')).toBe('#63acfc')
+ })
+ it('disabled', async () => {
+ const cb = await page.$('.cb2')
+ expect(await cb.property('disabled')).toBe(true)
+ await page.setData({
+ disabled: false
+ })
+ await page.waitFor(500)
+ expect(await cb.property('disabled')).toBe(false)
+ })
+})
\ No newline at end of file
diff --git a/pages/component/checkbox/checkbox.uvue b/pages/component/checkbox/checkbox.uvue
index 2d05ee1b..fab82ad2 100644
--- a/pages/component/checkbox/checkbox.uvue
+++ b/pages/component/checkbox/checkbox.uvue
@@ -8,9 +8,11 @@
-
- 选中
- 未选中
+
+ {{text}}
+ 未选中
+ 禁用
@@ -19,11 +21,11 @@
-
+
选中
+ style="transform:scale(0.7); margin-right: 30rpx;" class="checkbox">选中
- 未选中
+ 未选中
@@ -39,9 +41,9 @@
-
-
+
{{item.name}}
@@ -89,7 +91,13 @@
name: '法国',
checked: false
}
- ] as ItemType[]
+ ] as ItemType[],
+
+ text: '选中',
+ value: [] as string[],
+ disabled: true,
+ checked: true,
+ color: '#007aff'
}
},
methods: {
@@ -104,6 +112,9 @@
item.checked = false
}
}
+ },
+ testChange: function (e : CheckboxGroupChangeEvent) {
+ this.value = e.detail.value
}
}
}
--
GitLab