form.test.js 2.1 KB
Newer Older
H
hdx 已提交
1 2
const PAGE_PATH = '/pages/component/form/form'

H
hdx 已提交
3
const DEFAULT_NICK_NAME = ''
H
hdx 已提交
4
const DEFAULT_GENDER = '0'
H
hdx 已提交
5
const DEFAULT_LOVES = ['0']
H
hdx 已提交
6 7
const DEFAULT_AGE = 18
const DEFAULT_SWITCH = true
W
wanganxp 已提交
8
const DEFAULT_COMMENT = ''
H
hdx 已提交
9 10

const CHANGE_NICK_NAME = 'hello'
H
hdx 已提交
11 12
const CHANGE_GENDER = '1'
const CHANGE_LOVES = ['0', '1']
H
hdx 已提交
13 14
const CHANGE_AGE = 50
const CHANGE_SWITCH = false
W
wanganxp 已提交
15
const CHANGE_COMMENT = '备注'
H
hdx 已提交
16 17 18 19 20 21 22 23

describe('form', () => {
  let page
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor(500)
  })
  it('submit', async () => {
H
hdx 已提交
24
    await changeData(page)
H
hdx 已提交
25

H
hdx 已提交
26
    const btnSubmit = await page.$('.btn-submit')
H
hdx 已提交
27 28 29 30
    await btnSubmit.tap()
    await page.waitFor(200)

    const {
31 32
      formData,
      testVerifySubmit
H
hdx 已提交
33 34
    } = await page.data()

H
hdx 已提交
35
    expect(formData['nickname']).toBe(CHANGE_NICK_NAME)
H
hdx 已提交
36
    expect(formData['gender']).toBe(CHANGE_GENDER)
H
hdx 已提交
37 38
    expect(formData['loves'][0]).toBe(CHANGE_LOVES[0])
    expect(formData['loves'][1]).toBe(CHANGE_LOVES[1])
H
hdx 已提交
39 40
    expect(formData['age']).toBe(CHANGE_AGE)
    expect(formData['switch']).toBe(CHANGE_SWITCH)
W
wanganxp 已提交
41
    expect(formData['comment']).toBe(CHANGE_COMMENT)
42 43

    expect(testVerifySubmit).toBe(true)
H
hdx 已提交
44 45
  })
  it('reset', async () => {
H
hdx 已提交
46
    await changeData(page)
H
hdx 已提交
47

H
hdx 已提交
48
    const btnReset = await page.$('.btn-reset')
H
hdx 已提交
49 50 51
    await btnReset.tap()
    await page.waitFor(100)

H
hdx 已提交
52 53 54 55
    const btnSubmit = await page.$('.btn-submit')
    await btnSubmit.tap()
    await page.waitFor(100)

H
hdx 已提交
56
    const {
57 58
      formData,
      testVerifyReset
H
hdx 已提交
59 60
    } = await page.data()

H
hdx 已提交
61 62 63 64 65
    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)
W
wanganxp 已提交
66
    expect(formData['comment']).toBe(DEFAULT_COMMENT)
67 68

    expect(testVerifyReset).toBe(true)
H
hdx 已提交
69 70
  })
})
H
hdx 已提交
71 72 73 74 75 76 77

async function changeData(page) {
  await page.setData({
    nickname: CHANGE_NICK_NAME,
    gender: CHANGE_GENDER,
    loves: CHANGE_LOVES,
    age: CHANGE_AGE,
W
wanganxp 已提交
78 79
    switch: CHANGE_SWITCH,
    comment:CHANGE_COMMENT
H
hdx 已提交
80 81 82
  })
  await page.waitFor(100)
}