未验证 提交 d5fca1d6 编写于 作者: O openharmony_ci 提交者: Gitee

!9214 支持开发者自定义快捷键能力用例修改

Merge pull request !9214 from limeng/xts_0705
...@@ -12,16 +12,27 @@ ...@@ -12,16 +12,27 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
//@ts-nocheck
import events_emitter from '@ohos.events.emitter'; import events_emitter from '@ohos.events.emitter';
@Entry @Entry
@Component @Component
struct ShortcutKey { struct ShortcutKey {
private arr: string[] = ['0', '1','2', '3', '4', '5', '6', '7', '8', '9', private functionKey: FunctionKey[] = [
'-', '=', '`', '[', ']', ';', '\'', ',', '.', '/', ' ', '*', '+', FunctionKey.ESC,
'B','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','W'] FunctionKey.F1,
private functionKey: string[] = Object.keys(FunctionKey) FunctionKey.F2,
.filter(key => typeof FunctionKey[key] === 'number') FunctionKey.F3,
FunctionKey.F4,
FunctionKey.F5,
FunctionKey.F6,
FunctionKey.F7,
FunctionKey.F8,
FunctionKey.F9,
FunctionKey.F10,
FunctionKey.F11,
FunctionKey.F12,
]
sendEvent(message, eventId) { sendEvent(message, eventId) {
var eventData = { var eventData = {
...@@ -42,20 +53,18 @@ struct ShortcutKey { ...@@ -42,20 +53,18 @@ struct ShortcutKey {
build() { build() {
Scroll() { Scroll() {
Column({ space: 10 }) { Column({ space: 10 }) {
ForEach(this.arr, (item, index) => { Button("Ctrl + B")
Button("Ctrl" + "+" + item) .keyboardShortcut('B', [ModifierKey.CTRL])
.keyboardShortcut(item, [ModifierKey.CTRL])
.onClick(() => { .onClick(() => {
this.sendEvent('Ctrl_' + item, this.baseEvent + index) this.sendEvent('Ctrl_B', this.baseEvent)
}) })
.key('ShortcutKey_Button_' + index) .key('ShortcutKey_Button_0')
}, item => item)
ForEach(this.functionKey, (item, index) => { ForEach(this.functionKey, (item, index) => {
Button("CTRL + " + item) Button("CTRL + " + item)
.keyboardShortcut(<FunctionKey><unknown>FunctionKey[item], [ModifierKey.CTRL]) .keyboardShortcut(item, [ModifierKey.CTRL])
.onClick(() => { .onClick(() => {
this.sendEvent('Ctrl_' + item, this.baseEvent2 + index) this.sendEvent('Ctrl_' + FunctionKey[item], this.baseEvent2 + index)
}) })
.width("80%") .width("80%")
.key('ShortcutKey2_Ctrl_' + item) .key('ShortcutKey2_Ctrl_' + item)
...@@ -71,7 +80,6 @@ struct ShortcutKey { ...@@ -71,7 +80,6 @@ struct ShortcutKey {
.onClick(() => { .onClick(() => {
this.sendEvent('Alt_Q', 72003) this.sendEvent('Alt_Q', 72003)
}) })
}.width("100%") }.width("100%")
} }
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
//@ts-nocheck
import { describe, beforeEach, afterEach, it, expect } from '@ohos/hypium' import { describe, beforeEach, afterEach, it, expect } from '@ohos/hypium'
import router from '@ohos.router' import router from '@ohos.router'
import {UiDriver, UiComponent, BY, Driver, Component, ON} from '@ohos.UiTest' import {UiDriver, UiComponent, BY, Driver, Component, ON} from '@ohos.UiTest'
...@@ -31,56 +32,22 @@ export default function ShortcutKeyTest() { ...@@ -31,56 +32,22 @@ export default function ShortcutKeyTest() {
} }
} }
const arr = ['0', '1','2', '3', '4', '5', '6', '7', '8', '9', const functionKey: FunctionKey[] = [
'-', '=', '`', '[', ']', ';', '\'', ',', '.', '/', ' ', '*', '+', FunctionKey.ESC,
'B','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','W'] FunctionKey.F1,
const arr_keyCode = [ FunctionKey.F2,
input.KeyCode.KEYCODE_0 FunctionKey.F3,
,input.KeyCode.KEYCODE_1 FunctionKey.F4,
,input.KeyCode.KEYCODE_2 FunctionKey.F5,
,input.KeyCode.KEYCODE_3 FunctionKey.F6,
,input.KeyCode.KEYCODE_4 FunctionKey.F7,
,input.KeyCode.KEYCODE_5 FunctionKey.F8,
,input.KeyCode.KEYCODE_6 FunctionKey.F9,
,input.KeyCode.KEYCODE_7 FunctionKey.F10,
,input.KeyCode.KEYCODE_8 FunctionKey.F11,
,input.KeyCode.KEYCODE_9 FunctionKey.F12,
,input.KeyCode.KEYCODE_MINUS
,input.KeyCode.KEYCODE_EQUALS
,input.KeyCode.KEYCODE_GRAVE
,input.KeyCode.KEYCODE_LEFT_BRACKET
,input.KeyCode.KEYCODE_RIGHT_BRACKET
,input.KeyCode.KEYCODE_SEMICOLON
,input.KeyCode.KEYCODE_APOSTROPHE
,input.KeyCode.KEYCODE_COMMA
,input.KeyCode.KEYCODE_PERIOD
,input.KeyCode.KEYCODE_SLASH
,input.KeyCode.KEYCODE_SPACE
,input.KeyCode.KEYCODE_STAR
,input.KeyCode.KEYCODE_PLUS
,input.KeyCode.KEYCODE_B
,input.KeyCode.KEYCODE_D
,input.KeyCode.KEYCODE_E
,input.KeyCode.KEYCODE_F
,input.KeyCode.KEYCODE_G
,input.KeyCode.KEYCODE_H
,input.KeyCode.KEYCODE_I
,input.KeyCode.KEYCODE_J
,input.KeyCode.KEYCODE_K
,input.KeyCode.KEYCODE_L
,input.KeyCode.KEYCODE_M
,input.KeyCode.KEYCODE_N
,input.KeyCode.KEYCODE_O
,input.KeyCode.KEYCODE_P
,input.KeyCode.KEYCODE_Q
,input.KeyCode.KEYCODE_R
,input.KeyCode.KEYCODE_S
,input.KeyCode.KEYCODE_T
,input.KeyCode.KEYCODE_U
,input.KeyCode.KEYCODE_W
] ]
const functionKey = Object.keys(FunctionKey).filter(key => typeof FunctionKey[key] === 'number') const arr_keyCode = [
const arr_keyCode2 = [
input.KeyCode.KEYCODE_ESCAPE input.KeyCode.KEYCODE_ESCAPE
,input.KeyCode.KEYCODE_F1 ,input.KeyCode.KEYCODE_F1
,input.KeyCode.KEYCODE_F2 ,input.KeyCode.KEYCODE_F2
...@@ -106,7 +73,6 @@ export default function ShortcutKeyTest() { ...@@ -106,7 +73,6 @@ export default function ShortcutKeyTest() {
url: "TestAbility/pages/ShortcutKey", url: "TestAbility/pages/ShortcutKey",
} }
try { try {
router.clear();
let pages = router.getState(); let pages = router.getState();
if (pages == null || !("ShortcutKey" == pages.name)) { if (pages == null || !("ShortcutKey" == pages.name)) {
await router.pushUrl(options).then(()=>{ await router.pushUrl(options).then(()=>{
...@@ -121,6 +87,11 @@ export default function ShortcutKeyTest() { ...@@ -121,6 +87,11 @@ export default function ShortcutKeyTest() {
done() done()
}); });
afterEach(async function (done) {
sleep(2)
done()
});
/* /*
*tc.number ArkUI_Shortcut_Key_0100 *tc.number ArkUI_Shortcut_Key_0100
*tc.name Custom keyboard shortcuts *tc.name Custom keyboard shortcuts
...@@ -130,27 +101,18 @@ export default function ShortcutKeyTest() { ...@@ -130,27 +101,18 @@ export default function ShortcutKeyTest() {
let CASE = 'ArkUI_Shortcut_Key_0100' let CASE = 'ArkUI_Shortcut_Key_0100'
console.info(`${SUITE} ${CASE} START`); console.info(`${SUITE} ${CASE} START`);
let start = 0 let callback = (event) => {
let end = arr.length expect(event.data.msg).assertEqual('Ctrl_B');
let driver = Driver.create() console.info(`${SUITE} ${CASE} event.data.msg:` + event.data.msg);
for (let i = start; i < end; i++ ) { done()
let item = arr[i]
let callback = (event) => {
expect(event.data.msg).assertEqual('Ctrl_' + item);
console.info(`${SUITE} ${CASE} event.data.msg:` + i + ',' + event.data.msg);
if ( i == end - 1 ) {
done()
}
}
let event = {
eventId: baseEvent + i,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(event, callback);
await driver.triggerCombineKeys(input.KeyCode.KEYCODE_CTRL_LEFT, arr_keyCode[i])
} }
sleep(2) let event = {
eventId: baseEvent,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(event, callback);
let driver = Driver.create()
await driver.triggerCombineKeys(input.KeyCode.KEYCODE_CTRL_LEFT, input.KeyCode.KEYCODE_B)
console.info(`${SUITE} ${CASE} END`); console.info(`${SUITE} ${CASE} END`);
}); });
...@@ -174,7 +136,6 @@ export default function ShortcutKeyTest() { ...@@ -174,7 +136,6 @@ export default function ShortcutKeyTest() {
priority: events_emitter.EventPriority.LOW priority: events_emitter.EventPriority.LOW
} }
events_emitter.on(event, callback); events_emitter.on(event, callback);
sleep(2)
let driver = Driver.create() let driver = Driver.create()
await driver.triggerCombineKeys(input.KeyCode.KEYCODE_SHIFT_LEFT, input.KeyCode.KEYCODE_1); await driver.triggerCombineKeys(input.KeyCode.KEYCODE_SHIFT_LEFT, input.KeyCode.KEYCODE_1);
...@@ -200,7 +161,6 @@ export default function ShortcutKeyTest() { ...@@ -200,7 +161,6 @@ export default function ShortcutKeyTest() {
priority: events_emitter.EventPriority.LOW priority: events_emitter.EventPriority.LOW
} }
events_emitter.on(event, callback); events_emitter.on(event, callback);
sleep(2)
let driver = Driver.create() let driver = Driver.create()
await driver.triggerCombineKeys(input.KeyCode.KEYCODE_ALT_LEFT, input.KeyCode.KEYCODE_Q); await driver.triggerCombineKeys(input.KeyCode.KEYCODE_ALT_LEFT, input.KeyCode.KEYCODE_Q);
...@@ -218,13 +178,12 @@ export default function ShortcutKeyTest() { ...@@ -218,13 +178,12 @@ export default function ShortcutKeyTest() {
let start = 0 let start = 0
let end = functionKey.length let end = functionKey.length
sleep(2)
let driver = Driver.create() let driver = Driver.create()
for (let i = start; i < end; i++ ) { for (let i = start; i < end; i++ ) {
let item = functionKey[i] let item = functionKey[i]
let callback = (event) => { let callback = (event) => {
expect(event.data.msg).assertEqual('Ctrl_' + item); expect(event.data.msg).assertEqual('Ctrl_' + FunctionKey[item]);
console.info(`${SUITE} ${CASE} event.data.msg:` + i + ',' + event.data.msg); console.info(`${SUITE} ${CASE} event.data.msg:` + i + ',' + event.data.msg);
if ( i == end - 1 ) { if ( i == end - 1 ) {
done() done()
...@@ -235,7 +194,7 @@ export default function ShortcutKeyTest() { ...@@ -235,7 +194,7 @@ export default function ShortcutKeyTest() {
priority: events_emitter.EventPriority.LOW priority: events_emitter.EventPriority.LOW
} }
events_emitter.on(event, callback); events_emitter.on(event, callback);
await driver.triggerCombineKeys(input.KeyCode.KEYCODE_CTRL_LEFT, arr_keyCode2[i]) await driver.triggerCombineKeys(input.KeyCode.KEYCODE_CTRL_LEFT, arr_keyCode[i])
} }
console.info(`${SUITE} ${CASE} END`); console.info(`${SUITE} ${CASE} END`);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册