form.test.js 1.8 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 8 9
const DEFAULT_AGE = 18
const DEFAULT_SWITCH = true

const CHANGE_NICK_NAME = 'hello'
H
hdx 已提交
10 11
const CHANGE_GENDER = '1'
const CHANGE_LOVES = ['0', '1']
H
hdx 已提交
12 13 14 15 16 17 18 19 20 21
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 () => {
H
hdx 已提交
22
    await changeData(page)
H
hdx 已提交
23

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

    const {
      formData
    } = await page.data()

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

H
hdx 已提交
42
    const btnReset = await page.$('.btn-reset')
H
hdx 已提交
43 44 45
    await btnReset.tap()
    await page.waitFor(100)

H
hdx 已提交
46 47 48 49
    const btnSubmit = await page.$('.btn-submit')
    await btnSubmit.tap()
    await page.waitFor(100)

H
hdx 已提交
50 51 52 53
    const {
      formData
    } = await page.data()

H
hdx 已提交
54 55 56 57 58
    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)
H
hdx 已提交
59 60
  })
})
H
hdx 已提交
61 62 63 64 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,
    switch: CHANGE_SWITCH
  })
  await page.waitFor(100)
}