textarea.test.js 2.7 KB
Newer Older
张磊 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// 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);
  });

  it('focus', async () => {
15
    expect(await textarea.attribute("focus")).toBe("true")
张磊 已提交
16
    await page.setData({
17
      focus_boolean: false,
张磊 已提交
18 19
    })
    await page.waitFor(500)
20
    expect(await textarea.attribute("focus")).toBe("false")
张磊 已提交
21
  });
22
  it("auto-height", async () => {
张磊 已提交
23
    await page.setData({
24
      default_value: "",
张磊 已提交
25 26 27 28 29 30 31
      auto_height_boolean: true
    })
    await page.waitFor(500)
    var {
      width,
      height
    } = await textarea.size()
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
32
    expect(height).toBeLessThanOrEqual(200)
张磊 已提交
33
    await page.setData({
34 35
      default_value: "1\n2\n3\n4\n5\n6",
      auto_height_boolean: false
张磊 已提交
36 37 38 39 40 41
    })
    await page.waitFor(500)
    var {
      width,
      height
    } = await textarea.size()
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
42
    expect(height).toEqual(200)
43
  })
44 45 46 47 48
  it("cursor-color", async () => {
    await page.setData({
      cursor_color: "transparent",
    })
    await page.waitFor(500)
雪洛's avatar
雪洛 已提交
49
    expect(await textarea.attribute("cursor-color")).toBe("transparent")
50
  })
张磊 已提交
51

52 53 54 55 56 57 58 59 60
  it("flex 1 height exception", async () => {
    const bottomTextarea = await page.$('#textarea-height-exception');
    var {
      height
    } = await bottomTextarea.size()
    expect(height).toEqual(150)
  })


张磊 已提交
61 62 63 64 65
  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'])
66 67 68 69 70
      var selected = x['value'] - 1
      if(i == inputmodeEnum.length - 1){
        selected = i
      }
      await page.callMethod("radio_change_inputmode_enum", selected);
张磊 已提交
71
      await page.waitFor(500)
雪洛's avatar
雪洛 已提交
72
      expect(await textarea.attribute("inputmode")).toEqual(x['name'])
张磊 已提交
73 74 75
      await page.waitFor(500)
    }
  })
76

77 78 79 80 81 82 83
  if (!process.env.uniTestPlatformInfo.startsWith('android')) {
    // TODO: 暂时规避 android 端测试
    it('both set modelValue and value', async () => {
      let textarea2 = await page.$('.both-set-textarea');
      expect(await textarea2.value()).toBe("123")
    })
  }
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

  it("maxlength", async () => {
    const input = await page.$('#textarea-instance-maxlength');
    let str = "";
    for(let i = 0;i < 200;i++){
      str += `${i}`
    }
    await page.setData({
      textareaMaxLengthValue: str
    })
    let length = (await input.value()).length
    expect(length).toBe(10)
    await page.setData({
      textareaMaxLengthValue: ""
    })
  })

张磊 已提交
101
});