diff --git a/pages/component/textarea/textarea.test.js b/pages/component/textarea/textarea.test.js new file mode 100644 index 0000000000000000000000000000000000000000..a7b9ba16d62a0fd5148447c105df608522305639 --- /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 8646b28c3e8a774bcfe3ca1d20f896492803d2e4..2114cd467eb679f7821b50542c5cf251a505a144 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 {