textarea.test.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. describe('component-native-textarea', () => {
  2. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  3. const isAndroid = platformInfo.startsWith('android')
  4. const isIOS = platformInfo.startsWith('ios')
  5. const isMP = platformInfo.startsWith('mp')
  6. const isHarmony = platformInfo.startsWith('harmony')
  7. const isWeb = platformInfo.startsWith('web')
  8. let page;
  9. let textarea;
  10. beforeAll(async () => {
  11. page = await program.reLaunch("/pages/component/textarea/textarea");
  12. await page.waitFor(3000);
  13. textarea = await page.$('.uni-textarea');
  14. await page.waitFor(1000);
  15. });
  16. beforeEach(async () => {
  17. await page.setData({
  18. jest_result: false,
  19. })
  20. });
  21. if(!isMP){
  22. it("input event should triggered", async () => {
  23. const options = {text: '1'}
  24. if (isHarmony) {
  25. const textareaRect = await page.data('textareaRect');
  26. options.x = textareaRect.x + textareaRect.width / 2.0;
  27. options.y = textareaRect.y + textareaRect.height - 5;
  28. }
  29. await program.keyboardInput(options)
  30. await page.waitFor(2000)
  31. expect(await page.data('jest_result')).toBe(true)
  32. })
  33. // TODO 微信小程序自动化测试textarea focus属性取到的是数字
  34. it('focus', async () => {
  35. expect(await textarea.attribute("focus")).toBe("true")
  36. await page.setData({
  37. focus_boolean: false,
  38. })
  39. await page.waitFor(500)
  40. expect(await textarea.attribute("focus")).toBe("false")
  41. });
  42. if (!isWeb) {
  43. it('trigger change event', async () => {
  44. const changeValue = await page.data('changeValue');
  45. expect(changeValue).not.toBe("")
  46. if (isAndroid) {
  47. await program.adbCommand("input keyevent KEYCODE_DEL")
  48. await page.waitFor(2000)
  49. }
  50. })
  51. if (isAndroid) {
  52. it('focus-keyboard-height', async () => {
  53. await page.setData({
  54. focus_boolean: true,
  55. })
  56. await page.waitFor(500)
  57. let res = await page.data('jest_result');
  58. expect(res).toBe(true)
  59. await page.setData({
  60. focus_boolean: false,
  61. })
  62. await page.waitFor(500)
  63. })
  64. }
  65. }
  66. // 微信小程序text-area不支持cursor-color属性
  67. it("cursor-color", async () => {
  68. await page.setData({
  69. cursor_color: "transparent",
  70. })
  71. await page.waitFor(500)
  72. expect(await textarea.attribute("cursor-color")).toBe("transparent")
  73. })
  74. // 微信小程序自动化测试无法获取inputmode属性
  75. it("inputmode", async () => {
  76. const inputmodeEnum = await page.data("inputmode_enum")
  77. for (var i = 0; i < inputmodeEnum.length; i++) {
  78. var x = inputmodeEnum[i]
  79. var selected = x['value'] - 1
  80. if (i == inputmodeEnum.length - 1) {
  81. selected = i
  82. }
  83. await page.callMethod("radio_change_inputmode_enum", selected);
  84. await page.waitFor(500)
  85. expect(await textarea.attribute("inputmode")).toEqual(x['name'])
  86. await page.waitFor(500)
  87. }
  88. })
  89. }
  90. it("auto-height", async () => {
  91. await page.setData({
  92. default_value: "",
  93. })
  94. await page.waitFor(500)
  95. await page.setData({
  96. auto_height_boolean: true
  97. })
  98. await page.waitFor(500)
  99. let textareaSize = await textarea.size()
  100. let textareaHeight = textareaSize.height
  101. expect(textareaHeight).toBeLessThanOrEqual(150)
  102. if(!isMP) {
  103. // TODO 微信小程序auto-height由true切换成false时不会影响text-area高度
  104. await page.setData({
  105. default_value: "1\n2\n3\n4\n5\n6",
  106. auto_height_boolean: false
  107. })
  108. await page.waitFor(500)
  109. textareaSize = await textarea.size()
  110. textareaHeight = textareaSize.height
  111. expect(textareaHeight).toEqual(200)
  112. }
  113. })
  114. it("flex 1 height exception", async () => {
  115. const bottomTextarea = await page.$('#textarea-height-exception');
  116. var {
  117. height
  118. } = await bottomTextarea.size()
  119. expect(height).toEqual(150)
  120. })
  121. it("maxlength", async () => {
  122. const input = await page.$('#textarea-instance-maxlength');
  123. let str = "";
  124. for (let i = 0; i < 200; i++) {
  125. str += `${i}`
  126. }
  127. await page.setData({
  128. textareaMaxLengthValue: str
  129. })
  130. let length = (await input.value()).length
  131. expect(length).toBe(10)
  132. await page.setData({
  133. textareaMaxLengthValue: ""
  134. })
  135. })
  136. it('both set modelValue and value', async () => {
  137. const textarea2 = await page.$('#both-model-value');
  138. expect(await textarea2.value()).toEqual("123")
  139. })
  140. if (isIOS) {
  141. it('test-iOS-width', async () => {
  142. await page.setData({
  143. isAutoTest: true
  144. })
  145. await page.waitFor(500)
  146. const rect = await page.callMethod("getBoundingClientRectForTest")
  147. expect(rect.width).toBe(100)
  148. })
  149. }
  150. });