提交 ab56e4e2 编写于 作者: 张磊

add input.test.js

上级 0e1fe442
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('component-native-input', () => {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/component/input/input')
await page.waitFor(3000);
});
// 测试焦点及键盘弹起
it('focus', async () => {
const input = await page.$('.uni-input-focus');
expect(await input.property('focus')).toBe(true)
await page.setData({
focus: false,
})
expect(await input.property('focus')).toBe(false)
await page.waitFor(1000)
await page.setData({
focus: true,
})
expect(await input.property('focus')).toBe(true)
await page.waitFor(1000)
await page.setData({
focus: false,
})
expect(await input.property('focus')).toBe(false)
await page.waitFor(3000)
});
// 测试修改value属性
it("value", async () => {
const input = await page.$('.uni-input-default');
expect(await input.property('value')).toEqual("hello uni-app x")
})
//测试input的类型
it("type", async () => {
const text = await page.$('.uni-input-type-text');
const number = await page.$('.uni-input-type-number');
const digit = await page.$('.uni-input-type-digit');
const tel = await page.$('.uni-input-type-tel');
expect(await text.property('type')).toEqual("text")
expect(await number.property('type')).toEqual("number")
expect(await digit.property('type')).toEqual("digit")
expect(await tel.property('type')).toEqual("tel")
})
// 测试密码属性
it("password", async () => {
const input = await page.$('.uni-input-password');
expect(await input.property('password')).toBe(true)
await page.setData({
inputPassword: false,
})
expect(await input.property('password')).toBe(false)
})
// 测试placeholder
it("placeholder", async () => {
const placeholder1 = await page.$('.uni-input-placeholder1');
expect(await placeholder1.property("placeholder-style")).toMatchObject({
"color": "red"
})
expect(await placeholder1.property("placeholder")).toEqual("占位符文字颜色为红色")
await page.setData({
inputPlaceHolderStyle: "color:#CC00CC",
})
expect(await placeholder1.property("placeholder-style")).toMatchObject({
"color": "#CC00CC"
})
await page.setData({
inputPlaceHolderStyle: "color:#CC19CC;background-color:#00b1c0",
})
expect(await placeholder1.property("placeholder-style")).toMatchObject({
"color": "#CC19CC",
"backgroundColor": "#00b1c0"
})
await page.setData({
inputPlaceHolderStyle: "color:#CC19CC;background-color:#00b1c0;text-align:center;font-size:100px;font-weight:900",
})
expect(await placeholder1.property("placeholder-style")).toEqual({
"backgroundColor": "#00b1c0",
"color": "#CC19CC",
"fontSize": "100px",
"fontWeight": "900",
"textAlign": "center"
})
const placeholder2 = await page.$('.uni-input-placeholder2');
expect(await placeholder2.property("placeholder-class")).toMatchObject({
"backgroundColor": "#008000"
})
await page.setData({
inputPlaceHolderClass: "uni-input-placeholder-class-ts",
})
expect(await placeholder2.property("placeholder-class")).toMatchObject({
"backgroundColor": "#FFA500"
})
expect(await placeholder2.property("placeholder")).toEqual("占位符背景色为绿色")
})
it("disable", async () => {
const input = await page.$('.uni-input-disable');
expect(await input.property("disabled")).toBe(true)
})
it("confirm-type", async () => {
expect(await (await page.$('.uni-input-confirm-send')).property("confirmType")).toEqual("send")
expect(await (await page.$('.uni-input-confirm-search')).property("confirmType")).toEqual("search")
expect(await (await page.$('.uni-input-confirm-next')).property("confirmType")).toEqual("next")
expect(await (await page.$('.uni-input-confirm-go')).property("confirmType")).toEqual("go")
expect(await (await page.$('.uni-input-confirm-done')).property("confirmType")).toEqual("done")
})
});
\ No newline at end of file
......@@ -9,7 +9,7 @@
<text class="uni-title-text">设置输入框的初始内容</text>
</view>
<view class="uni-input-wrapper">
<input class="uni-input" value="hello uni-app x" />
<input class="uni-input uni-input-default" value="hello uni-app x" />
</view>
</view>
......@@ -18,16 +18,16 @@
<text class="uni-title-text">type取值(不同输入法表现可能不一致)</text>
</view>
<view class="uni-input-wrapper">
<input class="uni-input" type="text" placeholder="文本输入键盘" />
<input class="uni-input uni-input-type-text" type="text" placeholder="文本输入键盘" />
</view>
<view class="uni-input-wrapper">
<input class="uni-input" type="number" placeholder="数字输入键盘" />
<input class="uni-input uni-input-type-number" type="number" placeholder="数字输入键盘" />
</view>
<view class="uni-input-wrapper">
<input class="uni-input" type="digit" placeholder="带小数点的数字输入键盘" />
<input class="uni-input uni-input-type-digit" type="digit" placeholder="带小数点的数字输入键盘" />
</view>
<view class="uni-input-wrapper">
<input class="uni-input" type="tel" placeholder="电话输入键盘" />
<input class="uni-input uni-input-type-tel" :type="inputTypeTel" placeholder="电话输入键盘" />
</view>
</view>
......@@ -36,7 +36,7 @@
<text class="uni-title-text">密码输入框</text>
</view>
<view class="uni-input-wrapper">
<input class="uni-input" :password="true" />
<input class="uni-input uni-input-password" :password="inputPassword" />
</view>
</view>
......@@ -45,10 +45,10 @@
<text class="uni-title-text">占位符样式</text>
</view>
<view class="uni-input-wrapper">
<input class="uni-input" placeholder-style="color:red" placeholder="占位符文字颜色为红色" />
<input class="uni-input uni-input-placeholder1" :placeholder-style="inputPlaceHolderStyle" placeholder="占位符文字颜色为红色" />
</view>
<view class="uni-input-wrapper">
<input class="uni-input" placeholder-class="uni-input-placeholder-class" placeholder="占位符背景色为绿色" />
<input class="uni-input uni-input-placeholder2" :placeholder-class="inputPlaceHolderClass" placeholder="占位符背景色为绿色" />
</view>
</view>
......@@ -57,7 +57,7 @@
<text class="uni-title-text">设置禁用输入框</text>
</view>
<view class="uni-input-wrapper">
<input class="uni-input" :disabled="true" />
<input class="uni-input uni-input-disable" :disabled="true" />
</view>
</view>
......@@ -66,7 +66,7 @@
<text class="uni-title-text">设置最大输入长度</text>
</view>
<view class="uni-input-wrapper">
<input class="uni-input" :maxlength="10" placeholder="最大输入长度为10" />
<input class="uni-input uni-input-maxlength" :maxlength="10" placeholder="最大输入长度为10" :value="inputMaxLengthValue" @input="onMaxLengthInput" :focus="inputMaxLengthFocus" />
</view>
</view>
......@@ -84,7 +84,7 @@
<text class="uni-title-text">自动获取焦点</text>
</view>
<view class="uni-input-wrapper">
<input class="uni-input" :focus="true" />
<input class="uni-input uni-input-focus" :focus="focus"/>
</view>
</view>
......@@ -93,19 +93,19 @@
<text class="uni-title-text">confirm-type取值(不同输入法表现可能不一致)</text>
</view>
<view class="uni-input-wrapper">
<input class="uni-input" confirmType="send" placeholder="键盘右下角按钮显示为发送" />
<input class="uni-input uni-input-confirm-send" confirmType="send" placeholder="键盘右下角按钮显示为发送" />
</view>
<view class="uni-input-wrapper">
<input class="uni-input" confirmType="search" placeholder="键盘右下角按钮显示为搜索" />
<input class="uni-input uni-input-confirm-search" confirmType="search" placeholder="键盘右下角按钮显示为搜索" />
</view>
<view class="uni-input-wrapper">
<input class="uni-input" confirmType="next" placeholder="键盘右下角按钮显示为下一个" />
<input class="uni-input uni-input-confirm-next" confirmType="next" placeholder="键盘右下角按钮显示为下一个" />
</view>
<view class="uni-input-wrapper">
<input class="uni-input" confirmType="go" placeholder="键盘右下角按钮显示为前往" />
<input class="uni-input uni-input-confirm-go" confirmType="go" placeholder="键盘右下角按钮显示为前往" />
</view>
<view class="uni-input-wrapper">
<input class="uni-input" confirmType="done" placeholder="键盘右下角按钮显示为完成" />
<input class="uni-input uni-input-confirm-done" confirmType="done" placeholder="键盘右下角按钮显示为完成" />
</view>
</view>
......@@ -132,8 +132,7 @@
<text class="uni-title-text">设置输入框聚焦时光标的起始位置和结束位置(点击生效)</text>
</view>
<view class="uni-input-wrapper">
<input ref="input2" class="uni-input" value="0123456789" :selection-start="selectionStart"
:selection-end="selectionEnd" />
<input ref="input2" class="uni-input" value="0123456789" :selection-start="selectionStart" :selection-end="selectionEnd" />
</view>
</view>
......@@ -179,8 +178,7 @@
<view>
<view class="uni-title">
<text class="uni-title-text">keyboardheightchange事件</text>
<text class="uni-subtitle-text"
v-if="keyboardHeightChangeEventDetail">{{keyboardHeightChangeEventDetail}}</text>
<text class="uni-subtitle-text" v-if="keyboardHeightChangeEventDetail">{{keyboardHeightChangeEventDetail}}</text>
</view>
<view class="uni-input-wrapper">
<input class="uni-input" @keyboardheightchange="onKeyborardHeightChange" />
......@@ -204,9 +202,7 @@
</view>
<view class="uni-input-wrapper">
<input class="uni-input" placeholder="请输入密码" :password="showPassword" />
<image class="uni-icon"
:src="!showPassword ? '/static/icons/eye-active.png' : '/static/icons/eye.png'"
@click="changePassword"></image>
<image class="uni-icon" :src="!showPassword ? '/static/icons/eye-active.png' : '/static/icons/eye.png'" @click="changePassword"></image>
</view>
</view>
</view>
......@@ -228,10 +224,21 @@
inputEventDetail: '',
focusAndBlurEventDetail: '',
confirmEventDetail: '',
keyboardHeightChangeEventDetail: ''
keyboardHeightChangeEventDetail: '',
focus: true,
inputPassword: true,
inputTypeTel: "tel",
inputPlaceHolderStyle: "color:red",
inputPlaceHolderClass: "uni-input-placeholder-class",
inputMaxLengthValue:"",
onMaxLengthInputValue:"",
inputMaxLengthFocus:false
}
},
methods: {
onMaxLengthInput(event:InputEvent) {
this.onMaxLengthInputValue = event.detail.value
},
setCursor: function (cursor : number) {
(this.$refs['input'] as Element).focus();
this.cursor = cursor;
......@@ -275,6 +282,9 @@
onKeyborardHeightChange: function (event : InputKeyboardHeightChangeEvent) {
console.log("键盘高度发生变化", JSON.stringify(event.detail));
this.keyboardHeightChangeEventDetail = JSON.stringify(event.detail);
},
test_check_input_value():number {
return this.onMaxLengthInputValue.length
}
}
}
......@@ -307,4 +317,7 @@
.uni-input-placeholder-class {
background-color: green;
}
.uni-input-placeholder-class-ts {
background-color: orange;
}
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册