form.test.js 2.3 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

describe('form', () => {
18
  const isMP = process.env.uniTestPlatformInfo.startsWith('mp')
H
hdx 已提交
19 20 21 22 23 24
  let page
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor(500)
  })
  it('submit', async () => {
H
hdx 已提交
25
    await changeData(page)
H
hdx 已提交
26

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

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

H
hdx 已提交
36
    expect(formData['nickname']).toBe(CHANGE_NICK_NAME)
H
hdx 已提交
37
    expect(formData['gender']).toBe(CHANGE_GENDER)
H
hdx 已提交
38 39
    expect(formData['loves'][0]).toBe(CHANGE_LOVES[0])
    expect(formData['loves'][1]).toBe(CHANGE_LOVES[1])
H
hdx 已提交
40 41
    expect(formData['age']).toBe(CHANGE_AGE)
    expect(formData['switch']).toBe(CHANGE_SWITCH)
W
wanganxp 已提交
42
    expect(formData['comment']).toBe(CHANGE_COMMENT)
43 44 45
    if(!isMP) {
      expect(testVerifySubmit).toBe(true)
    }
H
hdx 已提交
46
  })
47 48 49 50
  if(isMP) {
    // 微信小程序reset和app、web表现不一致。暂时屏蔽reset测试例,后续如果拉齐再放开
    return
  }
H
hdx 已提交
51
  it('reset', async () => {
H
hdx 已提交
52
    await changeData(page)
H
hdx 已提交
53

H
hdx 已提交
54
    const btnReset = await page.$('.btn-reset')
H
hdx 已提交
55 56 57
    await btnReset.tap()
    await page.waitFor(100)

H
hdx 已提交
58 59 60 61
    const btnSubmit = await page.$('.btn-submit')
    await btnSubmit.tap()
    await page.waitFor(100)

H
hdx 已提交
62
    const {
63 64
      formData,
      testVerifyReset
H
hdx 已提交
65 66
    } = await page.data()

H
hdx 已提交
67 68 69 70 71
    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 已提交
72
    expect(formData['comment']).toBe(DEFAULT_COMMENT)
73 74

    expect(testVerifyReset).toBe(true)
H
hdx 已提交
75 76
  })
})
H
hdx 已提交
77 78 79 80 81 82 83

async function changeData(page) {
  await page.setData({
    nickname: CHANGE_NICK_NAME,
    gender: CHANGE_GENDER,
    loves: CHANGE_LOVES,
    age: CHANGE_AGE,
W
wanganxp 已提交
84 85
    switch: CHANGE_SWITCH,
    comment:CHANGE_COMMENT
H
hdx 已提交
86 87 88
  })
  await page.waitFor(100)
}