form.test.js 2.0 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 31 32 33
    await btnSubmit.tap()
    await page.waitFor(200)

    const {
      formData
    } = await page.data()

H
hdx 已提交
34
    expect(formData['nickname']).toBe(CHANGE_NICK_NAME)
H
hdx 已提交
35
    expect(formData['gender']).toBe(CHANGE_GENDER)
H
hdx 已提交
36 37
    expect(formData['loves'][0]).toBe(CHANGE_LOVES[0])
    expect(formData['loves'][1]).toBe(CHANGE_LOVES[1])
H
hdx 已提交
38 39
    expect(formData['age']).toBe(CHANGE_AGE)
    expect(formData['switch']).toBe(CHANGE_SWITCH)
W
wanganxp 已提交
40
    expect(formData['comment']).toBe(CHANGE_COMMENT)
H
hdx 已提交
41 42
  })
  it('reset', async () => {
H
hdx 已提交
43
    await changeData(page)
H
hdx 已提交
44

H
hdx 已提交
45
    const btnReset = await page.$('.btn-reset')
H
hdx 已提交
46 47 48
    await btnReset.tap()
    await page.waitFor(100)

H
hdx 已提交
49 50 51 52
    const btnSubmit = await page.$('.btn-submit')
    await btnSubmit.tap()
    await page.waitFor(100)

H
hdx 已提交
53 54 55 56
    const {
      formData
    } = await page.data()

H
hdx 已提交
57 58 59 60 61
    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 已提交
62
    expect(formData['comment']).toBe(DEFAULT_COMMENT)
H
hdx 已提交
63 64
  })
})
H
hdx 已提交
65 66 67 68 69 70 71

async function changeData(page) {
  await page.setData({
    nickname: CHANGE_NICK_NAME,
    gender: CHANGE_GENDER,
    loves: CHANGE_LOVES,
    age: CHANGE_AGE,
W
wanganxp 已提交
72 73
    switch: CHANGE_SWITCH,
    comment:CHANGE_COMMENT
H
hdx 已提交
74 75 76
  })
  await page.waitFor(100)
}