提交 81d75d03 编写于 作者: H hekun

submit the test code

Signed-off-by: Nhekun <hekun18@huawei.com>
上级 131c42e2
......@@ -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 stateChangeEventThree = {
var stateChangeEventFour = {
eventId: 940,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventThree, this.stateChangCallBack);
events_emitter.on(stateChangeEventFour, this.stateChangCallBack);
}
......
/**
* 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
}
}
}
/**
* 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
......@@ -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.
先完成此消息的编辑!
想要评论请 注册