From b1f2168904499f6d93cbd2546fe837664f95d996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=A3=8A?= <1633537611@qq.com> Date: Fri, 22 Sep 2023 12:00:30 +0800 Subject: [PATCH] add textarea.test.js --- pages/component/textarea/textarea.test.js | 88 +++++++++++++++++++++++ pages/component/textarea/textarea.uvue | 27 ++++--- 2 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 pages/component/textarea/textarea.test.js diff --git a/pages/component/textarea/textarea.test.js b/pages/component/textarea/textarea.test.js new file mode 100644 index 00000000..a7b9ba16 --- /dev/null +++ b/pages/component/textarea/textarea.test.js @@ -0,0 +1,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) + } + }) +}); diff --git a/pages/component/textarea/textarea.uvue b/pages/component/textarea/textarea.uvue index 8646b28c..2114cd46 100644 --- a/pages/component/textarea/textarea.uvue +++ b/pages/component/textarea/textarea.uvue @@ -9,13 +9,16 @@ export default { auto_height_boolean: false, confirm_hold_boolean: false, focus_boolean: false, - auto_focus_boolean: false, + auto_focus_boolean: false, + default_value:"", + maxlength:-1, confirm_type_enum: [{"value":0,"name":"send"},{"value":1,"name":"search"},{"value":2,"name":"next"},{"value":3,"name":"go"},{"value":4,"name":"done"}] as ItemType[], confirm_type_enum_current: 0, inputmode_enum: [{"value":0,"name":"none"},{"value":1,"name":"text"},{"value":2,"name":"decimal"},{"value":3,"name":"numeric"},{"value":4,"name":"tel"},{"value":5,"name":"search"},{"value":6,"name":"email"},{"value":7,"name":"url"}] as ItemType[], inputmode_enum_current: 0 } - }, + }, + methods: { textarea_click() { console.log("组件被点击时触发") }, textarea_touchstart() { console.log("手指触摸动作开始") }, @@ -45,7 +48,8 @@ export default {