Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
81d75d03
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
81d75d03
编写于
4月 26, 2023
作者:
H
hekun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
submit the test code
Signed-off-by:
N
hekun
<
hekun18@huawei.com
>
上级
131c42e2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
164 addition
and
46 deletion
+164
-46
arkui/ace_ets_component/entry/src/main/ets/MainAbility/pages/stepper.ets
...omponent/entry/src/main/ets/MainAbility/pages/stepper.ets
+17
-3
arkui/ace_ets_component/entry/src/main/ets/MainAbility/utils/Common.ets
...component/entry/src/main/ets/MainAbility/utils/Common.ets
+51
-0
arkui/ace_ets_component/entry/src/main/ets/MainAbility/utils/MessageManager.ets
...t/entry/src/main/ets/MainAbility/utils/MessageManager.ets
+54
-0
arkui/ace_ets_component/entry/src/main/ets/test/StepperJsunit.test.ets
..._component/entry/src/main/ets/test/StepperJsunit.test.ets
+42
-43
未找到文件。
arkui/ace_ets_component/entry/src/main/ets/MainAbility/pages/stepper.ets
浏览文件 @
81d75d03
...
...
@@ -15,7 +15,7 @@
*/
import events_emitter from '@ohos.events.emitter'
import {MessageManager,Callback} from '../utils/MessageManager';
@Entry
@Component
struct StepperExample {
...
...
@@ -24,6 +24,8 @@ struct StepperExample {
@State secondState: ItemState = ItemState.Normal
@State disabled: ItemState = ItemState.Normal
messageManager:MessageManager = new MessageManager()
build() {
Stepper({
index: this.currentIndex
...
...
@@ -100,6 +102,18 @@ struct StepperExample {
}
onPageShow() {
globalThis.value = {
name:'messageManager',message:this.messageManager
}
let callback:Callback = (message:any) => {
console.error('message = ' + message.name + "--" + message.value)
if (message.name == 'index') {
this.currentIndex = message.value
}
}
this.messageManager.registerCallback(callback)
console.info('stepper page show called');
var stateChangeEvent = {
eventId: 202,
...
...
@@ -119,11 +133,11 @@ struct StepperExample {
}
events_emitter.on(stateChangeEventThree, this.stateChangCallBack);
var stateChangeEvent
Three
= {
var stateChangeEvent
Four
= {
eventId: 940,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent
Three
, this.stateChangCallBack);
events_emitter.on(stateChangeEvent
Four
, this.stateChangCallBack);
}
...
...
arkui/ace_ets_component/entry/src/main/ets/MainAbility/utils/Common.ets
0 → 100644
浏览文件 @
81d75d03
/**
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export default class CommonFunc {
static rect_left;
static rect_top;
static rect_right;
static rect_bottom;
static rect_value;
static sleep(time){
return new Promise((resolve,reject)=>{
setTimeout(()=>{
resolve("ok")
},time)
}).then(()=>{
console.info(`sleep ${time} over...`)
})
}
static getComponentRect(key) {
let strJson = getInspectorByKey(key);
let obj = JSON.parse(strJson);
console.info("[getInspectorByKey] current component obj is: " + JSON.stringify(obj));
let rectInfo = JSON.parse('[' + obj.$rect + ']')
console.info("[getInspectorByKey] rectInfo is: " + rectInfo);
this.rect_left = JSON.parse('[' + rectInfo[0] + ']')[0]
this.rect_top = JSON.parse('[' + rectInfo[0] + ']')[1]
this.rect_right = JSON.parse('[' + rectInfo[1] + ']')[0]
this.rect_bottom = JSON.parse('[' + rectInfo[1] + ']')[1]
return this.rect_value = {
"left": this.rect_left, "top": this.rect_top, "right": this.rect_right, "bottom": this.rect_bottom
}
}
}
arkui/ace_ets_component/entry/src/main/ets/MainAbility/utils/MessageManager.ets
0 → 100644
浏览文件 @
81d75d03
/**
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export interface Callback {
(message:any):void
}
export class MessageManager {
callback:Callback
callbacks:Map<string,Callback> = new Map()
constructor() {
}
registerCallback(callback:Callback , type?:string) {
if (type == undefined) {
console.error('registerCallback callback set')
this.callback = callback
return
}
this.callbacks.set(type,callback)
}
notify(message:any, type?:string) {
if (type == undefined) {
this.callback(message)
return
}
let tmpCallback:Callback = this.callbacks.get(type)
if (tmpCallback === undefined) {
console.error('callbacks has no callback for type ' + type)
return
}
tmpCallback(message)
}
clear() {
this.callbacks.clear()
this.callback = null
}
}
\ No newline at end of file
arkui/ace_ets_component/entry/src/main/ets/test/StepperJsunit.test.ets
浏览文件 @
81d75d03
...
...
@@ -17,6 +17,8 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "
import router from '@system.router';
import Utils from './Utils.ets';
import events_emitter from '@ohos.events.emitter';
import CommonFunc from '../MainAbility/utils/Common';
import {MessageManager,Callback} from '../MainAbility/utils/MessageManager';
export default function stepperJsunit() {
describe('stepperTest', function () {
...
...
@@ -90,58 +92,55 @@ export default function stepperJsunit() {
});
it('stepperTest_0400', 0, async function (done) {
console.info('stepperTest_0400 START');
let strJson = getInspectorByKey('stepper');
console.info("stepperTest_0400 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("stepperTest_0400 component obj is: " + JSON.stringify(obj));
try {
let eventData = {
data: {
"currentIndex": -558038585,
}
}
let indexEvent = {
eventId: 940,
priority: events_emitter.EventPriority.LOW
}
console.info("stepperTest_0400 start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("stepperTest_0400 change component data error: " + err.message);
}
await Utils.sleep(3000);
await CommonFunc.sleep(1000);
globalThis.value.message.notify({name:'index',value:-558038585})
await CommonFunc.sleep(2000);
let strJsonNew = getInspectorByKey('stepper');
let objNew = JSON.parse(strJsonNew);
console.info("stepperTest_0400 component objNew is: " +
JSON.stringify(objNew)
);
console.info("stepperTest_0400 component objNew is: " +
objNew.$attrs.index
);
expect(objNew.$attrs.index).assertEqual('-558038585');
console.info('stepperTest_0400 END');
done();
//console.info('stepperTest_0400 START');
//let strJson = getInspectorByKey('stepper');
//console.info("stepperTest_0400 component strJson:" + strJson);
//let obj = JSON.parse(strJson);
//console.info("stepperTest_0400 component obj is: " + JSON.stringify(obj));
// try {
// let eventData = {
// data: {
// "currentIndex": -558038585,
// }
// }
// let indexEvent = {
// eventId: 940,
// priority: events_emitter.EventPriority.LOW
// }
//console.info("stepperTest_0400 start to publish emit");
// events_emitter.emit(indexEvent, eventData);
// } catch (err) {
// console.log("stepperTest_0400 change component data error: " + err.message);
//}
// await Utils.sleep(3000);
//let strJsonNew = getInspectorByKey('stepper');
//let objNew = JSON.parse(strJsonNew);
// console.info("stepperTest_0400 component objNew is: " + JSON.stringify(objNew));
//expect(objNew.$attrs.index).assertEqual('-558038585');
//console.info('stepperTest_0400 END');
//done();
});
it('stepperTest_0500', 0, async function (done) {
console.info('[stepperTest_0500] START');
try {
var eventData = {
data: {
"currentIndex": -10
}
}
var innerEvent = {
eventId: 910,
priority: events_emitter.EventPriority.LOW
}
console.info("[stepperTest_0500] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[stepperTest_0500] change component data error: " + err.message);
}
await Utils.sleep(3000);
let strJson = getInspectorByKey('stepper');
let obj = JSON.parse(strJson);
console.info("[stepperTest_0500] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.index).assertEqual('-10');
console.info('stepperTest_0500 END');
await CommonFunc.sleep(1000);
globalThis.value.message.notify({name:'index',value:-10})
await CommonFunc.sleep(2000);
let strJsonNew = getInspectorByKey('stepper');
let objNew = JSON.parse(strJsonNew);
console.info("stepperTest_0500 component objNew is: " + objNew.$attrs.index);
expect(objNew.$attrs.index).assertEqual('-10');
console.info('stepperTest_0400 END');
done();
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录