textarea.test.js 2.4 KB
Newer Older
张磊 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
// 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 () => {
    expect(await textarea.property("focus")).toBe(false)
    await page.setData({
      focus_boolean: true,
    })
    await page.waitFor(500)
    expect(await textarea.property("focus")).toBe(true)
  });
  it("auto-height", async () => {
    await page.setData({
      auto_height_boolean: true
    })
    await page.waitFor(500)
    // 原始高度
    var {
      width,
      height
    } = await textarea.size()
    expect(height).toBeGreaterThanOrEqual(150)
    await page.waitFor(500)
    // 只有一行的高度
    await page.setData({
      maxlength: 3,
    })
    await page.waitFor(500)
    await page.setData({
      default_value: "第一行\n第二行\n第三行",
    })
    await page.waitFor(500)
    var {
      width,
      height
    } = await textarea.size()
    expect(height).toBeLessThanOrEqual(50)

    // 四行的高度
    await page.setData({
      maxlength: -1,
    })
    await page.waitFor(500)
    await page.setData({
      default_value: "第一行\n第二行\n第三行\n第四行",
    })
    await page.waitFor(500)
    var {
      width,
      height
    } = await textarea.size()
    expect(height).toBeLessThanOrEqual(150)
  })

  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'])
      await page.callMethod("radio_change_inputmode_enum", x['value']);
      await page.waitFor(500)
      expect(await textarea.property("inputmode")).toEqual(x['name'])
      await page.waitFor(500)
    }
  })

  it("confirm-type", async () => {
    const inputmodeEnum = await page.data("confirm_type_enum")
    for (var i = 0; i < inputmodeEnum.length; i++) {
      var x = inputmodeEnum[i]
      console.log(x['value'], x['name'])
      await page.callMethod("radio_change_confirm_type_enum", x['value']);
      await page.waitFor(500)
      expect(await textarea.property("confirm-type")).toEqual(x['name'])
      await page.waitFor(500)
    }
  })
});