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

submit the test code

Signed-off-by: Nhekun <hekun18@huawei.com>
上级 131c42e2
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
*/ */
import events_emitter from '@ohos.events.emitter' import events_emitter from '@ohos.events.emitter'
import {MessageManager,Callback} from '../utils/MessageManager';
@Entry @Entry
@Component @Component
struct StepperExample { struct StepperExample {
...@@ -24,6 +24,8 @@ struct StepperExample { ...@@ -24,6 +24,8 @@ struct StepperExample {
@State secondState: ItemState = ItemState.Normal @State secondState: ItemState = ItemState.Normal
@State disabled: ItemState = ItemState.Normal @State disabled: ItemState = ItemState.Normal
messageManager:MessageManager = new MessageManager()
build() { build() {
Stepper({ Stepper({
index: this.currentIndex index: this.currentIndex
...@@ -100,6 +102,18 @@ struct StepperExample { ...@@ -100,6 +102,18 @@ struct StepperExample {
} }
onPageShow() { 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'); console.info('stepper page show called');
var stateChangeEvent = { var stateChangeEvent = {
eventId: 202, eventId: 202,
...@@ -119,11 +133,11 @@ struct StepperExample { ...@@ -119,11 +133,11 @@ struct StepperExample {
} }
events_emitter.on(stateChangeEventThree, this.stateChangCallBack); events_emitter.on(stateChangeEventThree, this.stateChangCallBack);
var stateChangeEventThree = { var stateChangeEventFour = {
eventId: 940, eventId: 940,
priority: events_emitter.EventPriority.LOW 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 " ...@@ -17,6 +17,8 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "
import router from '@system.router'; import router from '@system.router';
import Utils from './Utils.ets'; import Utils from './Utils.ets';
import events_emitter from '@ohos.events.emitter'; import events_emitter from '@ohos.events.emitter';
import CommonFunc from '../MainAbility/utils/Common';
import {MessageManager,Callback} from '../MainAbility/utils/MessageManager';
export default function stepperJsunit() { export default function stepperJsunit() {
describe('stepperTest', function () { describe('stepperTest', function () {
...@@ -90,58 +92,55 @@ export default function stepperJsunit() { ...@@ -90,58 +92,55 @@ export default function stepperJsunit() {
}); });
it('stepperTest_0400', 0, async function (done) { it('stepperTest_0400', 0, async function (done) {
console.info('stepperTest_0400 START');
let strJson = getInspectorByKey('stepper'); await CommonFunc.sleep(1000);
console.info("stepperTest_0400 component strJson:" + strJson); globalThis.value.message.notify({name:'index',value:-558038585})
let obj = JSON.parse(strJson); await CommonFunc.sleep(2000);
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 strJsonNew = getInspectorByKey('stepper');
let objNew = JSON.parse(strJsonNew); 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'); expect(objNew.$attrs.index).assertEqual('-558038585');
console.info('stepperTest_0400 END'); console.info('stepperTest_0400 END');
done(); 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) { it('stepperTest_0500', 0, async function (done) {
console.info('[stepperTest_0500] START'); console.info('[stepperTest_0500] START');
try { await CommonFunc.sleep(1000);
var eventData = { globalThis.value.message.notify({name:'index',value:-10})
data: { await CommonFunc.sleep(2000);
"currentIndex": -10 let strJsonNew = getInspectorByKey('stepper');
} let objNew = JSON.parse(strJsonNew);
} console.info("stepperTest_0500 component objNew is: " + objNew.$attrs.index);
var innerEvent = { expect(objNew.$attrs.index).assertEqual('-10');
eventId: 910, console.info('stepperTest_0400 END');
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');
done(); done();
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册