textarea.test.js 3.1 KB
Newer Older
张磊 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/

describe('component-native-textarea', () => {

  let page;
  let textarea;
  beforeAll(async () => {
    page = await program.reLaunch("/pages/component/textarea/textarea");
    await page.waitFor(3000);
    textarea = await page.$('.uni-textarea');
    await page.waitFor(1000);
  });

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  beforeEach(async () => {
    await page.setData({
      jest_result: false,
    })
  });

  if(process.env.uniTestPlatformInfo.startsWith('android')){
    it("input event triggered when the default value is", async () => {
        await program.adbCommand("input text 1")
        await page.waitFor(2000)
        let res = await page.data('jest_result');
        expect(res).toBe(true)
    })
    it("reset status", async () => {
      await program.adbCommand("input keyevent KEYCODE_DEL")
      await page.waitFor(2000)
    })
  }

张磊 已提交
33
  it('focus', async () => {
34
    expect(await textarea.attribute("focus")).toBe("true")
张磊 已提交
35
    await page.setData({
36
      focus_boolean: false,
张磊 已提交
37 38
    })
    await page.waitFor(500)
39
    expect(await textarea.attribute("focus")).toBe("false")
张磊 已提交
40
  });
41
  it("auto-height", async () => {
张磊 已提交
42
    await page.setData({
43
      default_value: "",
张磊 已提交
44 45 46 47 48 49 50
      auto_height_boolean: true
    })
    await page.waitFor(500)
    var {
      width,
      height
    } = await textarea.size()
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
51
    expect(height).toBeLessThanOrEqual(200)
张磊 已提交
52
    await page.setData({
53 54
      default_value: "1\n2\n3\n4\n5\n6",
      auto_height_boolean: false
张磊 已提交
55 56 57 58 59 60
    })
    await page.waitFor(500)
    var {
      width,
      height
    } = await textarea.size()
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
61
    expect(height).toEqual(200)
62
  })
63 64 65 66 67
  it("cursor-color", async () => {
    await page.setData({
      cursor_color: "transparent",
    })
    await page.waitFor(500)
雪洛's avatar
雪洛 已提交
68
    expect(await textarea.attribute("cursor-color")).toBe("transparent")
69
  })
张磊 已提交
70

71 72 73 74 75 76 77 78 79
  it("flex 1 height exception", async () => {
    const bottomTextarea = await page.$('#textarea-height-exception');
    var {
      height
    } = await bottomTextarea.size()
    expect(height).toEqual(150)
  })


张磊 已提交
80 81 82 83 84
  it("inputmode", async () => {
    const inputmodeEnum = await page.data("inputmode_enum")
    for (var i = 0; i < inputmodeEnum.length; i++) {
      var x = inputmodeEnum[i]
      console.log(x['value'], x['name'])
85
      var selected = x['value'] - 1
86
      if (i == inputmodeEnum.length - 1) {
87 88 89
        selected = i
      }
      await page.callMethod("radio_change_inputmode_enum", selected);
张磊 已提交
90
      await page.waitFor(500)
雪洛's avatar
雪洛 已提交
91
      expect(await textarea.attribute("inputmode")).toEqual(x['name'])
张磊 已提交
92 93 94
      await page.waitFor(500)
    }
  })
95

96 97 98
  it("maxlength", async () => {
    const input = await page.$('#textarea-instance-maxlength');
    let str = "";
99
    for (let i = 0; i < 200; i++) {
100 101 102 103 104 105 106 107 108 109 110 111
      str += `${i}`
    }
    await page.setData({
      textareaMaxLengthValue: str
    })
    let length = (await input.value()).length
    expect(length).toBe(10)
    await page.setData({
      textareaMaxLengthValue: ""
    })
  })

112 113 114 115 116
  it('both set modelValue and value', async () => {
    const textarea2 = await page.$('#both-model-value');
    expect(await textarea2.value()).toEqual("123")
  })

张磊 已提交
117
});