From bc09763e2e9b7fa319e309236c73d020086e6c75 Mon Sep 17 00:00:00 2001 From: hdx Date: Fri, 3 Nov 2023 20:25:29 +0800 Subject: [PATCH] =?UTF-8?q?form=E7=BB=84=E4=BB=B6:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8C=96=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 | 64 +++++++++++++++++++++++++++++++ pages/component/form/form.uvue | 14 ++++--- 2 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 pages/component/form/form.test.js diff --git a/pages/component/form/form.test.js b/pages/component/form/form.test.js new file mode 100644 index 00000000..4af6858c --- /dev/null +++ b/pages/component/form/form.test.js @@ -0,0 +1,64 @@ +const PAGE_PATH = '/pages/component/form/form' + +const DEFAULT_NICK_NAME = 'hello' +const DEFAULT_GENDER = '0' +const DEFAULT_AGE = 18 +const DEFAULT_SWITCH = true + +const CHANGE_NICK_NAME = 'hello' +const CHANGE_GENDER = '0' +const CHANGE_AGE = 50 +const CHANGE_SWITCH = false + +describe('form', () => { + let page + beforeAll(async () => { + page = await program.reLaunch(PAGE_PATH) + await page.waitFor(500) + }) + it('submit', async () => { + await page.setData({ + nickname: CHANGE_NICK_NAME, + age: CHANGE_AGE, + switch: CHANGE_SWITCH + }) + await page.waitFor(200) + + const btnSubmit = await page.$('.btn-l') + await btnSubmit.tap() + await page.waitFor(200) + + const { + formData + } = await page.data() + + // expect(formData['nickname']).toBe(CHANGE_NICK_NAME) + expect(formData['gender']).toBe(CHANGE_GENDER) + expect(formData['loves'][0]).toBe('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) + + const btnReset = await page.$('.btn-r') + await btnReset.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) + }) +}) diff --git a/pages/component/form/form.uvue b/pages/component/form/form.uvue index 67ee8047..01153cbd 100644 --- a/pages/component/form/form.uvue +++ b/pages/component/form/form.uvue @@ -5,16 +5,16 @@
姓名 - + 性别 - + - + @@ -31,12 +31,12 @@ 年龄 - + 保留选项 - + @@ -55,6 +55,10 @@ export default { data() { return { + nickname: '', + gender: '0', + age: 18, + switch: true, formData: {} as UTSJSONObject } }, -- GitLab