switch.test.js 2.1 KB
Newer Older
H
hdx 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
const PAGE_PATH = '/pages/component/switch/switch'

describe('switch', () => {
  let page
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor(500)
  })
  it('checked', async () => {
    const switch_element = await page.$('.switch-checked')

    await page.setData({
      checked: false,
    })
    await page.waitFor(100)
H
hdx 已提交
16 17 18
    // TODO
    const newValue1 = await switch_element.property('checked')
    expect(newValue1.toString()).toBe(false + '')
H
hdx 已提交
19 20 21 22 23

    await page.setData({
      checked: true,
    })
    await page.waitFor(100)
H
hdx 已提交
24 25 26
    // TODO
    const newValue2 = await switch_element.property('checked')
    expect(newValue2.toString()).toBe(true + '')
H
hdx 已提交
27 28 29
  })
  it('color', async () => {
    const switch_element = await page.$('.switch-color')
雪洛's avatar
雪洛 已提交
30
    expect(await switch_element.attribute('color')).toBe('#FFCC33')
H
hdx 已提交
31 32 33 34 35 36 37

    const color = '#00ff00'

    await page.setData({
      color: color
    })
    await page.waitFor(100)
雪洛's avatar
雪洛 已提交
38
    expect(await switch_element.attribute('color')).toBe(color)
H
hdx 已提交
39
  })
H
hdx 已提交
40 41 42 43 44 45 46 47 48 49
  it('dark', async () => {
    const dark = await page.$('#dark')
    const darkChecked = await page.$('#darkChecked')

    expect(await dark.attribute('background-color')).toBe('#1f1f1f')
    expect(await dark.attribute('fore-color')).toBe('#f0f0f0')

    expect(await darkChecked.attribute('active-background-color')).toBe('#007aff')
    expect(await darkChecked.attribute('active-fore-color')).toBe('#ffffff')
  })
50
  it('click', async () => {
51
    let switchElement
52
    // TODO 暂时通过获取组件内部的 class 触发模拟点击
53 54 55 56
    if (process.env.uniTestPlatformInfo.startsWith('android')) {
      switchElement = await page.$('.uni-switch-input')
      await switchElement.tap()
      await page.waitFor(200)
57

58 59 60
      const {
        testVerifyEvent
      } = await page.data()
61

62 63 64 65 66 67 68 69 70 71 72 73 74
      expect(testVerifyEvent).toBe(true)
    } else {
      // switchElement = await page.$('#testTap')
    }

    // await switchElement.tap()
    // await page.waitFor(200)

    // const {
    //   testVerifyEvent
    // } = await page.data()

    // expect(testVerifyEvent).toBe(true)
75
  })
76
})