From 56ec9a7b27bae5df8994e7e08926bfe11da976af Mon Sep 17 00:00:00 2001 From: hdx Date: Thu, 9 Nov 2023 14:35:08 +0800 Subject: [PATCH] =?UTF-8?q?form=E7=BB=84=E4=BB=B6=EF=BC=9A=E8=A1=A5?= =?UTF-8?q?=E5=85=85=E8=AF=A6=E7=BB=86=E7=9A=84=E8=87=AA=E5=8A=A8=E5=8C=96?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/component/form/form.test.js | 53 +++++++++++++++++-------------- pages/component/form/form.uvue | 19 +++++------ 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/pages/component/form/form.test.js b/pages/component/form/form.test.js index a40f67a5..e2f70e96 100644 --- a/pages/component/form/form.test.js +++ b/pages/component/form/form.test.js @@ -1,12 +1,14 @@ const PAGE_PATH = '/pages/component/form/form' -const DEFAULT_NICK_NAME = 'hello' +const DEFAULT_NICK_NAME = '' const DEFAULT_GENDER = '0' +const DEFAULT_LOVES = ['0'] const DEFAULT_AGE = 18 const DEFAULT_SWITCH = true const CHANGE_NICK_NAME = 'hello' -const CHANGE_GENDER = '0' +const CHANGE_GENDER = '1' +const CHANGE_LOVES = ['0', '1'] const CHANGE_AGE = 50 const CHANGE_SWITCH = false @@ -17,14 +19,9 @@ describe('form', () => { await page.waitFor(500) }) it('submit', async () => { - await page.setData({ - nickname: CHANGE_NICK_NAME, - age: CHANGE_AGE, - switch: CHANGE_SWITCH - }) - await page.waitFor(200) + await changeData(page) - const btnSubmit = await page.$('.btn-l') + const btnSubmit = await page.$('.btn-submit') await btnSubmit.tap() await page.waitFor(200) @@ -34,31 +31,41 @@ describe('form', () => { expect(formData['nickname']).toBe(CHANGE_NICK_NAME) expect(formData['gender']).toBe(CHANGE_GENDER) - expect(formData['loves'][0]).toBe('1') + expect(formData['loves'][0]).toBe(CHANGE_LOVES[0]) + expect(formData['loves'][1]).toBe(CHANGE_LOVES[1]) expect(formData['age']).toBe(CHANGE_AGE) expect(formData['switch']).toBe(CHANGE_SWITCH) }) it('reset', async () => { - await page.setData({ - nickname: CHANGE_NICK_NAME, - age: CHANGE_AGE, - switch: CHANGE_SWITCH - }) - await page.waitFor(100) + await changeData(page) - const btnReset = await page.$('.btn-r') + const btnReset = await page.$('.btn-reset') await btnReset.tap() await page.waitFor(100) + const btnSubmit = await page.$('.btn-submit') + await btnSubmit.tap() + await page.waitFor(100) + const { formData } = await page.data() - // TODO - // expect(formData['nickname']).toBe(DEFAULT_NICK_NAME) - // expect(formData['gender']).toBe(undefined) - // expect(formData['loves'][0]).toBe(undefined) - // expect(formData['age']).toBe(undefined) - // expect(formData['switch']).toBe(undefined) + expect(formData['nickname']).toBe(DEFAULT_NICK_NAME) + expect(formData['gender']).toBe(DEFAULT_GENDER) + expect(formData['loves'][0]).toBe(DEFAULT_LOVES[0]) + expect(formData['age']).toBe(DEFAULT_AGE) + expect(formData['switch']).toBe(DEFAULT_SWITCH) }) }) + +async function changeData(page) { + await page.setData({ + nickname: CHANGE_NICK_NAME, + gender: CHANGE_GENDER, + loves: CHANGE_LOVES, + age: CHANGE_AGE, + switch: CHANGE_SWITCH + }) + await page.waitFor(100) +} diff --git a/pages/component/form/form.uvue b/pages/component/form/form.uvue index 6a550779..13b8b43b 100644 --- a/pages/component/form/form.uvue +++ b/pages/component/form/form.uvue @@ -11,10 +11,10 @@ 性别 - + - + @@ -22,10 +22,10 @@ 爱好 - 读书 + 读书 - 写字 + 写字 @@ -40,8 +40,8 @@ - - + + 提交的表单数据 @@ -56,8 +56,9 @@ data() { return { nickname: '', - gender: '0', + gender: 0, age: 18, + loves: ['0'], switch: true, formData: {} as UTSJSONObject } @@ -105,11 +106,11 @@ flex: 1; } - .btn-l { + .btn-submit { margin-right: 5px; } - .btn-r { + .btn-reset { margin-left: 5px; } -- GitLab