setup.test.js 3.8 KB
Newer Older
雪洛's avatar
雪洛 已提交
1 2
// TODO web端

雪洛's avatar
雪洛 已提交
3 4
const PAGE_PATH = '/pages/composition/setup/setup'
describe('options setup', () => {
雪洛's avatar
雪洛 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
  let page
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor('view')
  })
  it('basic', async () => {
    const str = await page.$('#str')
    expect(await str.text()).toBe('str: default str')
    const num = await page.$('#num')
    expect(await num.text()).toBe('num: 0')
    const bool = await page.$('#bool')
    expect(await bool.text()).toBe('bool: false')

    const count = await page.$('#count')
    expect(await count.text()).toBe('count: 0')
雪洛's avatar
雪洛 已提交
20

雪洛's avatar
雪洛 已提交
21 22 23 24 25 26
    const objStr = await page.$('#obj-str')
    expect(await objStr.text()).toBe('obj.str: obj default str')
    const objNum = await page.$('#obj-num')
    expect(await objNum.text()).toBe('obj.num: 0')
    const objBool = await page.$('#obj-bool')
    expect(await objBool.text()).toBe('obj.bool: false')
雪洛's avatar
雪洛 已提交
27

雪洛's avatar
雪洛 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
    if (!process.env.uniTestPlatformInfo.startsWith('web')) {
      const propsStr = await page.$('#props-str')
      expect(await propsStr.text()).toBe('props.str: default str')
      const propsCount = await page.$('#props-count')
      expect(await propsCount.text()).toBe('props.count: 0')
      const propsObjStr = await page.$('#props-obj-str')
      expect(await propsObjStr.text()).toBe(`props.obj['str']: obj default str`)
      const propsObjNum = await page.$('#props-obj-num')
      expect(await propsObjNum.text()).toBe(`props.obj['num']: 0`)
      const propsObjBool = await page.$('#props-obj-bool')
      expect(await propsObjBool.text()).toBe(`props.obj['bool']: false`)
    }
  })
  it('props', async () => {
    const incrementBtn = await page.$('#increment-btn')
    await incrementBtn.tap()
雪洛's avatar
雪洛 已提交
44

雪洛's avatar
雪洛 已提交
45 46 47 48
    const count = await page.$('#count')
    expect(await count.text()).toBe('count: 1')
    const propsCount = await page.$('#props-count')
    expect(await propsCount.text()).toBe('props.count: 1')
雪洛's avatar
雪洛 已提交
49

雪洛's avatar
雪洛 已提交
50 51
    const updateObjBtn = await page.$('#update-obj-btn')
    await updateObjBtn.tap()
雪洛's avatar
雪洛 已提交
52

雪洛's avatar
雪洛 已提交
53 54 55 56 57 58
    const objStr = await page.$('#obj-str')
    expect(await objStr.text()).toBe('obj.str: obj new str')
    const objNum = await page.$('#obj-num')
    expect(await objNum.text()).toBe('obj.num: 100')
    const objBool = await page.$('#obj-bool')
    expect(await objBool.text()).toBe('obj.bool: true')
雪洛's avatar
雪洛 已提交
59

雪洛's avatar
雪洛 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73
    if (!process.env.uniTestPlatformInfo.startsWith('web')) {
      const propsObjStr = await page.$('#props-obj-str')
      expect(await propsObjStr.text()).toBe(`props.obj['str']: obj new str`)
      const propsObjNum = await page.$('#props-obj-num')
      expect(await propsObjNum.text()).toBe(`props.obj['num']: 100`)
      const propsObjBool = await page.$('#props-obj-bool')
      expect(await propsObjBool.text()).toBe(`props.obj['bool']: true`)
    }
  })
  it('context', async () => {
    if (!process.env.uniTestPlatformInfo.startsWith('web')) {
      // attrs
      const contextAttrsIsShow = await page.$('#context-attrs-is-show')
      expect(await contextAttrsIsShow.text()).toBe('context.attrs.isShow: true')
雪洛's avatar
雪洛 已提交
74

雪洛's avatar
雪洛 已提交
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
      // emits
      const compUpdateObjBtn = await page.$('#comp-update-obj-btn')
      await compUpdateObjBtn.tap()
      const propsObjStr = await page.$('#props-obj-str')
      expect(await propsObjStr.text()).toBe(`props.obj['str']: obj new str by comp update`)
      const propsObjNum = await page.$('#props-obj-num')
      expect(await propsObjNum.text()).toBe(`props.obj['num']: 200`)
      const propsObjBool = await page.$('#props-obj-bool')
      expect(await propsObjBool.text()).toBe(`props.obj['bool']: true`)
    }
    // slots
    const defaultSlotInFoo = await page.$('#default-slot-in-foo')
    expect(await defaultSlotInFoo.text()).toBe('default slot in Foo')
    const hasDefaultSlot = await page.$('#has-default-slot')
    expect(await hasDefaultSlot.text()).toBe('hasDefaultSlot: true')
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
91
})