diff --git a/pages/component/form/form.test.js b/pages/component/form/form.test.js new file mode 100644 index 0000000000000000000000000000000000000000..4af6858c58680436807374d9a2cc818a3df65243 --- /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 67ee804785a4eec6bb81a8238e66a715ff35075c..01153cbde0ad16a2c5a6d3a64795f3a7b8b7f4a2 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 } },