提交 e33e2fff 编写于 作者: Z zhangrao

add

Signed-off-by: Nzhangrao <zhangrao@huawei.com>
上级 433e12dd
// @ts-nocheck
/**
* Copyright (c) 2021 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.
*/
import events_emitter from '@ohos.emitter'
@Entry
@Component
struct ContentTable {
private foodItem: FoodData
@State fontWeight: FontWeight = FontWeight.Medium
@Builder IngredientItem(title:string, name: string, value: string) {
Flex() {
Text(title)
.fontSize(17.4)
.fontWeight(this.fontWeight)
.layoutWeight(1)
Flex() {
Text(name)
.fontSize(17.4)
.flexGrow(1)
Text(value)
.fontSize(17.4)
}
.layoutWeight(2)
}
.key('fontWeight')
}
build() {
Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Start }) {
this.IngredientItem('Calories', 'Calories', this.foodItem.calories + 'kcal')
this.IngredientItem('Nutrition', 'Protein', this.foodItem.protein + 'g')
this.IngredientItem('', 'Fat', this.foodItem.fat + 'g')
this.IngredientItem('', 'Carbohydrates', this.foodItem.carbohydrates + 'g')
this.IngredientItem('', 'VitaminC', this.foodItem.vitaminC + 'mg')
}
.height(280)
.padding({ top: 30, right: 30, left: 30 })
}
}
\ No newline at end of file
// @ts-nocheck
/**
* Copyright (c) 2021 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.
*/
import events_emitter from '@ohos.emitter'
@Entry
@Component
struct SideBarExample {
normalIcon : Resource = ($rawfile("ic_health_heart.png"))
selectedIcon: Resource = ($rawfile("test.png"))
@State arr: number[] = [1, 2, 3]
@State current: number = 1
@State widthValue: number = 10
@State heightValue: number = 10
@State controlButton: ButtonStyle = ButtonStyle.left
@State iconsValue: object= { shown: string=10, hidden: string=10, switching:string=10 };
private stateChangCallBack = (eventData) => {
if (eventData != null) {
console.info("sideBar page state change called:" + JSON.stringify(eventData));
if (eventData.data.widthValue != null) {
this.widthValue = eventData.data.widthValue;
}
if (eventData.data.heightValue != null) {
this.heightValue = JSON.parse(eventData.data.heightValue);
}
if (eventData.data.iconsValue != null) {
this.iconsValue = eventData.data.iconsValue;
}
if (eventData.data.controlButton != null) {
this.controlButton = eventData.data.controlButton;
}
}
}
onPageShow() {
console.info('sideBar page show called');
var stateChangeEvent = {
eventId: 45,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
}
build() {
SideBarContainer(SideBarContainerType.Embed)
{
Column() {
ForEach(this.arr, (item, index) => {
Column({ space: 5 }) {
Image(this.current === item ? this.selectedIcon : this.normalIcon).width(64).height(64)
Text("Index0" + item)
.fontSize(25)
.fontColor(this.current === item ? '#0A59F7' : '#999')
.fontFamily('source-sans-pro,cursive,sans-serif')
}
.onClick(() => {
this.current = item
})
}, item => item)
}.width('100%')
.backgroundColor('#19000000')
RowSplit() {
Column(){
Text('Split page one').fontSize(30)
}
Column(){
Text('Split page two').fontSize(30)
}
}.width('100%')
}
.key('sidebar')
.width(this.widthValue)
.height(this.heightValue)
.controlButton(this.controlButton)
.sideBarWidth(240)
.minSideBarWidth(210)
.maxSideBarWidth(260)
.onChange((value: boolean) => {
console.info('status:' + value)
})
}
}
......@@ -106,7 +106,7 @@ import flexWrapJsunit from './FlexWrapJsunit.test.ets';
import datePickerJsunit from './DatePickerJsunit.test.ets';
import enmusVerticalAlignJsunit from './EnmusVerticalAlignJsunit.test.ets';
import enmusHorizontalAlignJsunit from './EnmusHorizontalAlignJsunit.test.ets';
import direction2Jsunit from './direction2Jsunit.test.ets';
import direction2Jsunit from './Direction2Jsunit.test.ets';
import patternLockJsunit from './PatternLockJsunit.test.ets';
import enumsImageJsunit from './EnmusImageJsunit.test.ets';
import sliderJsunit from './sliderJsunit.test.ets'
......@@ -134,6 +134,7 @@ import playModeJsunit from './PlayModeJsunit.test.ets';
import SwipeDirectionJsunit from './SwipeDirectionJsunit.test.ets';
import GestureModeJsunit from './GestureModeJsunit.test.ets';
import PanDirectionJsunit from './PanDirectionJsunit.test.ets';
import sideBarJsunit from './SideBarJsunit.test.ets';
export default function testsuite() {
gaugeJsunit();
......@@ -258,5 +259,6 @@ export default function testsuite() {
SwipeDirectionJsunit();
GestureModeJsunit();
PanDirectionJsunit();
sideBarJsunit();
systemAppJsunit(); //此测试文件会终止APP运行,提代码请将文件放在此文件之前
}
\ No newline at end of file
// @ts-nocheck
/**
* Copyright (c) 2021 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.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets"
import router from '@system.router';
import events_emitter from '@ohos.events.emitter';
import Utils from './Utils';
export default function sidebarJsunit() {
describe('appInfoTest', function () {
beforeEach(async function (done) {
let options = {
uri: 'pages/sideBar',
}
try {
router.clear();
let pages = router.getState();
console.info("get sideBar state success " + JSON.stringify(pages));
if (!("sideBar" == pages.name)) {
console.info("get sideBar success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push sideBar page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push sideBar page error: " + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(2000);
console.info("sideBar after each called");
});
it('testSideBar001', 0, async function (done) {
console.info('[testSideBar001] START');
await Utils.sleep(2000);
let strJson = getInspectorByKey('sidebar');
console.info("[testSideBar001] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testSideBar001] width:" + obj.$attrs.width);
expect(obj.$attrs.width).assertEqual('10.000000vp');
done();
});
it('testSideBar002', 0, async function (done) {
console.info('testSideBar002 START');
await Utils.sleep(1000);
try {
var eventData = {
data: {
"widthValue": '20',
}
}
var innerEvent = {
eventId: 45,
priority: events_emitter.EventPriority.LOW
}
console.info("testSideBar002 start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("testSideBar002 change component color error: " + err.message);
}
await Utils.sleep(2000);
let strJson = getInspectorByKey('sidebar');
let obj = JSON.parse(strJson);
console.info("testSideBar002 component obj is: " + JSON.stringify(obj.$attrs.widthValue));
expect(obj.$attrs.widthValue).assertEqual('20');
done();
});
it('testSideBar003', 0, async function (done) {
console.info('[testSideBar003] START');
await Utils.sleep(2000);
let strJson = getInspectorByKey('sidebar');
console.info("[testSideBar003] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testSideBar003] height:" + obj.$attrs.height);
expect(obj.$attrs.height).assertEqual('10.000000vp');
done();
});
it('testSideBar004', 0, async function (done) {
console.info('[testSideBar004] START');
try {
let eventData = {
data: {
"heightValue":"30"
}
}
let indexEvent = {
eventId: 45,
priority: events_emitter.EventPriority.LOW
}
console.info("[testSideBar004] start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("[testSideBar004] change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJson = getInspectorByKey('sidebar');
console.info("[testSideBar004] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testSideBar004] height:" + obj.$attrs.height);
expect(obj.$attrs.height).assertEqual('30');
done();
});
it('testSidebar005', 0, async function (done) {
console.info('[testSidebar005] START');
await Utils.sleep(2000);
let strJson = getInspectorByKey('sidebar');
console.info("[testSidebar005] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testSidebar005] icons:" + obj.$attrs.icons);
expect(obj.$attrs.icons).assertEqual('10.000000vp');
done();
});
it('testSidebar006', 0, async function (done) {
console.info('[testSidebar006] START');
await Utils.sleep(1000);
let iconsValue: object= {shown: string=20, hidden: string=30, switching:string=10 };
try {
var eventData = {
data: {
"iconsValue": JSON.stringify(iconsValue)
}
}
var innerEvent = {
eventId: 45,
priority: events_emitter.EventPriority.LOW
}
console.info("[testSidebar006] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testSidebar006] change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJsonNew = getInspectorByKey('sidebar');
let objNew = JSON.parse(strJsonNew);
console.info("[testSidebar006] component objNew is: " + JSON.stringify(objNew));
expect(objNew.$attrs.icons.shown).assertEqual("20.000000");
expect(objNew.$attrs.icons.hidden).assertEqual("30.000000");
expect(objNew.$attrs.icons.switching).assertEqual("10.000000");
done();
});
it('testSidebar007', 0, async function (done) {
console.info('[testSidebar007] START');
await Utils.sleep(2000);
let strJson = getInspectorByKey('sidebar');
console.info("[testSidebar007] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testSidebar007] controlButton:" + obj.$attrs.controlButton);
expect(obj.$attrs.controlButton).assertEqual('10.000000vp');
done();
});
it('testSidebar008', 0, async function (done) {
console.info('[testSidebar008] START');
await Utils.sleep(1000);
try {
var eventData = {
data: {
"controlButton": controlButton.top
}
}
var innerEvent = {
eventId: 45,
priority: events_emitter.EventPriority.LOW
}
console.info("[testSidebar008] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testSidebar008] change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJsonNew = getInspectorByKey('sidebar');
let objNew = JSON.parse(strJsonNew);
console.info("[testSidebar008] component objNew is: " + JSON.stringify(objNew));
expect(objNew.$attrs.controlButton).assertEqual("controlButton.top");
done();
});
})
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册