提交 ccff4e87 编写于 作者: Z zhangrao

add component

Signed-off-by: Nzhangrao <zhangrao@huawei.com>
上级 40524396
......@@ -20,7 +20,7 @@ import prompt from '@system.prompt'
@Entry
@Preview
@Component
struct AppearExample {
struct AppearExample {
@State isShow: boolean = true
@State appearFlag: boolean = false
@State disAppearFlag: boolean = false
......@@ -40,7 +40,7 @@ struct AppearExample {
console.info("[appear] page stateChangCallBack");
if (eventData != null) {
console.info("[appear] page state change called:" + JSON.stringify(eventData));
if(eventData.data.isShow != null) {
if (eventData.data.isShow != null) {
this.isShow = eventData.data.isShow;
}
}
......@@ -60,7 +60,7 @@ struct AppearExample {
this.changeAppear = 'Show Text'
console.info('appearFlag current action state is: ' + this.appearFlag);
prompt.showToast({ message: 'The text is shown', duration: 2000 })
try{
try {
var backData = {
data: {
"ACTION": this.appearFlag,
......@@ -72,7 +72,7 @@ struct AppearExample {
}
console.info("appearFlag start to emit action state")
events_emitter.emit(backEvent, backData)
}catch{
} catch {
console.info("appearFlag emit action state err: " + JSON.stringify(err.message))
}
})
......@@ -81,7 +81,7 @@ struct AppearExample {
this.changeAppear = 'Hide Text'
console.info('disAppearFlag current action state is: ' + this.disAppearFlag);
prompt.showToast({ message: 'The text is hidden', duration: 2000 })
try{
try {
var backData = {
data: {
"ACTION": this.disAppearFlag,
......@@ -93,7 +93,7 @@ struct AppearExample {
}
console.info("disAppearFlag start to emit action state")
events_emitter.emit(backEvent, backData)
}catch{
} catch {
console.info("disAppearFlag emit action state err: " + JSON.stringify(err.message))
}
})
......
// @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 ColumnExample {
@State alignItems: HorizontalAlign = HorizontalAlign.Start;
onPageShow() {
console.info('[column] page show called');
var stateChangeEvent = {
eventId: 192,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
}
private stateChangCallBack = (eventData) => {
console.info("[column] page stateChangCallBack");
if (eventData != null) {
console.info("[column] page state change called:" + JSON.stringify(eventData));
if(eventData.data.alignItems != null) {
this.alignItems = eventData.data.alignItems;
}
}
}
build() {
Column() {
Text('alignItems').fontSize(9).fontColor(0xCCCCCC).width('90%')
Column() {
Column().width('50%').height(30).backgroundColor(0xAFEEEE)
Column().width('50%').height(30).backgroundColor(0x00FFFF)
}
.key("alignItemsColumn")
.width('90%')
.border({ width: 1 })
.alignItems(this.alignItems)
}.width('100%').padding({ top: 5 })
}
}
\ 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 EllipseExample {
@State width: string = "200px";
@State height: string = "200px";
onPageShow() {
console.info('[ellipse] page show called');
var stateChangeEvent = {
eventId: 92,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
}
private stateChangCallBack = (eventData) => {
console.info("[ellipse] page stateChangCallBack");
if (eventData != null) {
console.info("[ellipse] page state change called:" + JSON.stringify(eventData));
if(eventData.data.width != null) {
this.width = eventData.data.width;
}
if(eventData.data.height != null) {
this.height = eventData.data.height;
}
}
}
build() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center,justifyContent: FlexAlign.Center}) {
Ellipse().width(`${this.width}`).height(`${this.height}`).key('ellipse')
}.width('100%').height('100%')
}
// @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 EllipseExample {
@State width: string = "200px";
@State height: string = "200px";
onPageShow() {
console.info('[ellipse] page show called');
var stateChangeEvent = {
eventId: 92,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
var stateChangeEventTwo = {
eventId: 907,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventTwo, this.stateChangCallBack);
var stateChangeEventThree = {
eventId: 908,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventThree, this.stateChangCallBack);
}
private stateChangCallBack = (eventData) => {
console.info("[ellipse] page stateChangCallBack");
if (eventData != null) {
console.info("[ellipse] page state change called:" + JSON.stringify(eventData));
if (eventData.data.width != null) {
this.width = eventData.data.width;
}
if (eventData.data.height != null) {
this.height = eventData.data.height;
}
}
}
build() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Ellipse().width(`${this.width}`).height(`${this.height}`).key('ellipse')
}.width('100%').height('100%')
}
}
\ 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 EnabledExample {
@State enabled: boolean = true;
@State text: string = "enable";
onPageShow() {
console.info('[enabled] page show called ');
var stateChangeEvent = {
eventId: 93,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
}
private stateChangCallBack = (eventData) => {
console.info("[stateChangCallBack] stateChangCallBack ");
if (eventData != null) {
console.info("[stateChangCallBack] state change called: " + JSON.stringify(eventData));
if (eventData.data.enabled != null) {
this.enabled = eventData.data.enabled
}
if (eventData.data.text != null) {
this.text = eventData.data.text
}
}
}
build() {
Flex({ justifyContent: FlexAlign.SpaceAround }) {
Button('disable')
.enabled(false)
.backgroundColor(0x317aff)
.opacity(0.4)
Button(this.text)
.key('enabled')
.backgroundColor(0x317aff)
.enabled(this.enabled)
}
.width('100%')
.padding({ top: 5 })
}
// @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 EnabledExample {
@State enabled: boolean = true;
@State text: string = "enable";
onPageShow() {
console.info('[enabled] page show called ');
var stateChangeEvent = {
eventId: 93,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
var stateChangeEvent2 = {
eventId: 1111,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent2, this.stateChangCallBack);
}
private stateChangCallBack = (eventData) => {
console.info("[stateChangCallBack] stateChangCallBack ");
if (eventData != null) {
console.info("[stateChangCallBack] state change called: " + JSON.stringify(eventData));
if (eventData.data.enabled != null) {
this.enabled = eventData.data.enabled
}
if (eventData.data.text != null) {
this.text = eventData.data.text
}
}
}
build() {
Flex({ justifyContent: FlexAlign.SpaceAround }) {
Button('disable')
.enabled(false)
.backgroundColor(0x317aff)
.opacity(0.4)
Button(this.text)
.key('enabled')
.backgroundColor(0x317aff)
.enabled(this.enabled)
}
.width('100%')
.padding({ top: 5 })
}
}
\ No newline at end of file
......@@ -23,25 +23,24 @@ struct FlexExample {
private stateChangCallBack = (eventData) => {
if (eventData != null) {
console.info("Flex page state change called:" + JSON.stringify(eventData));
if(eventData.data.flexBasis != null) {
if (eventData.data.flexBasis != null) {
this.flexBasis = eventData.data.flexBasis;
}
if(eventData.data.flexGrow != null) {
if (eventData.data.flexGrow != null) {
this.flexGrow = eventData.data.flexGrow;
}
if(eventData.data.flexShrink != null) {
if (eventData.data.flexShrink != null) {
this.flexShrink = eventData.data.flexShrink;
}
if(eventData.data.alignSelf != null) {
if (eventData.data.alignSelf != null) {
this.alignSelf = eventData.data.alignSelf;
}
}
}
private stateChangCallBack = (eventData) => {
if (eventData != null) {
console.info("Flex page state change called:" + JSON.stringify(eventData));
switch(eventData.data.alignSelf) {
switch (eventData.data.alignSelf) {
case 'Auto':
this.alignSelf = ItemAlign.Auto;
break;
......@@ -80,33 +79,60 @@ struct FlexExample {
Text('flexBasis').fontSize(9).fontColor(0xCCCCCC).width('90%')
Flex() {
Text('flexBasis("auto")')
.flexBasis('auto').key("flexBasis").width('60%').height(100).lineHeight(70)
.backgroundColor(0xD2B48C).textAlign(TextAlign.Center)
.flexBasis('auto')
.key("flexBasis")
.width('60%')
.height(100)
.lineHeight(70)
.backgroundColor(0xD2B48C)
.textAlign(TextAlign.Center)
Text('flexBasis(100)')
.flexBasis('100').height(100).lineHeight(70)
.backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
.flexBasis('100')
.height(100)
.lineHeight(70)
.backgroundColor(0xF5DEB3)
.textAlign(TextAlign.Center)
}.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE)
Text('flexGrow').key("flexGrow").fontSize(9).fontColor(0xCCCCCC).width('90%')
Flex() {
Text('flexGrow(2)')
.flexGrow(2).height(100).lineHeight(70)
.backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
.flexGrow(2)
.height(100)
.lineHeight(70)
.backgroundColor(0xF5DEB3)
.textAlign(TextAlign.Center)
Text('flexGrow(1)')
.flexGrow(1).height(100).lineHeight(70)
.backgroundColor(0xD2B48C).textAlign(TextAlign.Center)
.flexGrow(1)
.height(100)
.lineHeight(70)
.backgroundColor(0xD2B48C)
.textAlign(TextAlign.Center)
}.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE)
Text('flexShrink').fontSize(9).fontColor(0xCCCCCC).width('90%')
Flex({ direction: FlexDirection.Row }) {
Text('flexShrink(0)')
.flexShrink(0).key("flexShrink").width('50%').height(100).lineHeight(70)
.backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
.flexShrink(0)
.key("flexShrink")
.width('50%')
.height(100)
.lineHeight(70)
.backgroundColor(0xF5DEB3)
.textAlign(TextAlign.Center)
Text('no flexShrink')
.width('40%').height(100).lineHeight(70).backgroundColor(0xD2B48C).textAlign(TextAlign.Center)
.width('40%')
.height(100)
.lineHeight(70)
.backgroundColor(0xD2B48C)
.textAlign(TextAlign.Center)
Text('flexShrink(2)')
.flexShrink(2).width('40%').height(100) .lineHeight(70)
.backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
.flexShrink(2)
.width('40%')
.height(100)
.lineHeight(70)
.backgroundColor(0xF5DEB3)
.textAlign(TextAlign.Center)
}.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE)
Text('alignSelf').key("alignSelf").fontSize(9).fontColor(0xCCCCCC).width('90%')
......@@ -114,11 +140,20 @@ struct FlexExample {
Text('no alignSelf,height:80').width('33%').height(80)
.backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
Text('alignSelf stretch')
.alignSelf(ItemAlign.Stretch).width('33%').height(80).lineHeight(70)
.backgroundColor(0xD2B48C).textAlign(TextAlign.Center)
.alignSelf(ItemAlign.Stretch)
.width('33%')
.height(80)
.lineHeight(70)
.backgroundColor(0xD2B48C)
.textAlign(TextAlign.Center)
Text('no alignSelf,height:100').width('34%').height(100)
.backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
}.key('flex').width('90%').height(120).padding(10).backgroundColor(0xAFEEEE)
}
.key('flex')
.width('90%')
.height(120)
.padding(10)
.backgroundColor(0xAFEEEE)
}.width('100%').margin({ top: 5 })
}
}
\ 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 GaugeExample {
@State gaugeValue: string = 50;
@State strokeWidthValue: string = 20;
@State startAngleValue: string = 210;
@State endAngleValue: string = 150;
@State colorValues: Array = [[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1], [0x9C554B, 1], [0xD94838, 1]];
private stateChangCallBack = (eventData) => {
if (eventData != null) {
console.info("gauge page state change called:" + JSON.stringify(eventData));
if(eventData.data.gaugeValue != null) {
this.gaugeValue = eventData.data.gaugeValue;
}
if(eventData.data.strokeWidthValue != null) {
this.strokeWidthValue = eventData.data.strokeWidthValue;
}
if(eventData.data.startAngleValue != null) {
this.startAngleValue = eventData.data.startAngleValue;
}
if(eventData.data.endAngleValue != null) {
this.endAngleValue = eventData.data.endAngleValue;
}
if(eventData.data.colorValues != null) {
this.colorValues = JSON.parse(eventData.data.colorValues);
}
}
}
onPageShow() {
console.info('gauge page show called');
var stateChangeEvent = {
eventId: 102,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
var stateChangeEventTwo = {
eventId: 103,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventTwo, this.stateChangCallBack);
}
build() {
Column() {
Gauge({ value: 0, min: 0, max: 100 })
.key("gauge")
.value(`${this.gaugeValue}`)
.startAngle(`${this.startAngleValue}`)
.endAngle(`${this.endAngleValue}`)
.colors(this.colorValues)
.strokeWidth(`${this.strokeWidthValue}`)
.width(200).height(200)
}.width('100%').margin({ top: 300 })
}
}
// @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 GaugeExample {
@State gaugeValue: string = 50;
@State strokeWidthValue: string = 20;
@State startAngleValue: string = 210;
@State endAngleValue: string = 150;
@State colorValues: Array = [[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1], [0x9C554B, 1], [0xD94838, 1]];
private stateChangCallBack = (eventData) => {
if (eventData != null) {
console.info("gauge page state change called:" + JSON.stringify(eventData));
if (eventData.data.gaugeValue != null) {
this.gaugeValue = eventData.data.gaugeValue;
}
if (eventData.data.strokeWidthValue != null) {
this.strokeWidthValue = eventData.data.strokeWidthValue;
}
if (eventData.data.startAngleValue != null) {
this.startAngleValue = eventData.data.startAngleValue;
}
if (eventData.data.endAngleValue != null) {
this.endAngleValue = eventData.data.endAngleValue;
}
if (eventData.data.colorValues != null) {
this.colorValues = JSON.parse(eventData.data.colorValues);
}
}
}
onPageShow() {
console.info('gauge page show called');
var stateChangeEvent = {
eventId: 102,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
var stateChangeEventTwo = {
eventId: 103,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventTwo, this.stateChangCallBack);
var stateChangeEvent3 = {
eventId: 904,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent3, this.stateChangCallBack);
var stateChangeEvent4 = {
eventId: 905,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent4, this.stateChangCallBack);
var stateChangeEvent5 = {
eventId: 906,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent5, this.stateChangCallBack);
}
build() {
Column() {
Gauge({ value: 0, min: 0, max: 100 })
.key("gauge")
.value(`${this.gaugeValue}`)
.startAngle(`${this.startAngleValue}`)
.endAngle(`${this.endAngleValue}`)
.strokeWidth(`${this.strokeWidthValue}`)
.width(200)
.height(200)
}.width('100%').margin({ top: 300 })
}
}
......@@ -17,7 +17,6 @@
@Entry
@Component
struct GlobalExample {
onPageShow() {
}
......@@ -44,9 +43,9 @@ struct GlobalExample {
let width = img.width;
let height = img.height;
this.context.imageSmoothingEnabled = false;
this.context.drawImage( img, 30, 950, 160, 100);
console.log("imagebitmap_width="+width);
console.log("imagebitmap_height="+height);
this.context.drawImage(img, 30, 950, 160, 100);
console.log("imagebitmap_width=" + width);
console.log("imagebitmap_height=" + height);
}
testOffscreenCanvas() {
......@@ -63,17 +62,19 @@ struct GlobalExample {
testImageData() {
var offscreen = new OffscreenCanvas(300, 300);
var offCanvas2 = offscreen.getContext("2d");
var imageData = offCanvas2.createImageData(100,100);
var imageData = offCanvas2.createImageData(100, 100);
var imgData = imageData.data;
console.log("imageData_width="+imageData.width);
console.log("imageData_height="+imageData.height);
console.log("imageData_width=" + imageData.width);
console.log("imageData_height=" + imageData.height);
}
testImage(){
var img = new Image("/images/bg.jpg",100,100)
.onload(()=>{})
.onerror(()=>{});
console.log("img_width="+img.width);
console.log("img_height="+img.height);
testImage() {
var img = new Image("/images/bg.jpg", 100, 100)
.onload(() => {
})
.onerror(() => {
});
console.log("img_width=" + img.width);
console.log("img_height=" + img.height);
}
}
\ No newline at end of file
......@@ -24,8 +24,8 @@ struct GridSetting {
@State gridSpan: number = 1;
@State gridOffset: number = 0;
build(){
GridContainer({sizeType: SizeType.SM}) {
build() {
GridContainer({ sizeType: SizeType.SM }) {
Row({}) {
Row() {
Text('Left').fontSize(25)
......@@ -34,6 +34,7 @@ struct GridSetting {
.height("100%")
.backgroundColor(0x66bbb2cb)
.key('gridOffset')
Row() {
Text('Center').fontSize(25)
}
......@@ -44,6 +45,7 @@ struct GridSetting {
.height("100%")
.backgroundColor(0x66b6c5d1)
.key('gridRow')
Row() {
Text('Right').fontSize(25)
}
......@@ -58,6 +60,7 @@ struct GridSetting {
.margin({ top: 10 })
.key('gridContainer')
}
onPageShow() {
let smChangeEvent = {
eventId: 9,
......@@ -75,6 +78,7 @@ struct GridSetting {
}
events_emitter.on(spanChangeEvent, this.stateChangCallBack);
}
stateChangCallBack = (eventData) => {
console.info("GridSetting page stateChangCallBack" + JSON.stringify(eventData));
if (eventData && eventData.data) {
......
......@@ -28,7 +28,6 @@ struct ImageEffectsExample {
@State contrastValue: string= 20;
@State invertValue: string= 10;
@State hueRotateValue: string= 10
private stateChangCallBack = (eventData) => {
if (eventData != null) {
console.info("imageEffects page state change called:" + JSON.stringify(eventData));
......
......@@ -14,7 +14,6 @@
* limitations under the License.
*/
import file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index.ets";
import testsuite from "../test/List.test.ets";
import featureAbility from "@ohos.ability.featureAbility";
......
// @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';
class ContainerInfo {
label : string = ''
size : string = ''
};
class ChildInfo {
text : string = ''
priority : number = 0
};
@Entry
@Component
struct LayoutConstraints {
private children : string[] = ['1', '2', '3', '4', '5', '6'];
@State aspectRatio: number = 1.5;
private container: ContainerInfo[] = [
{label: 'Big container', size: '97%'},
{label: 'Small container', size: '30%'}];
@State priorityChildren: any[] = [
{text: '1\n(priority:1)', priority: 1},
{text: '2\n(priority:2)', priority: 2},
{text: '3\n(priority:3)', priority: 3},
{text: '4\n(priority:4)', priority: 4}];
@State currentIndex : number = 0;
build() {
Column({ space: 20 }) {
Text('using container: row').fontSize(20).fontColor(Color.Black).width('100%')
Row({space: 10}) {
ForEach(this.children, (item) => {
Text(item)
.backgroundColor(0xbbb2cb)
.fontSize(20)
.aspectRatio(this.aspectRatio)
.height(60)
Text(item)
.backgroundColor(0xbbb2cb)
.fontSize(20)
.aspectRatio(this.aspectRatio)
.width(60)
.key('aspectRatio')
}, item=>item)
}
.size({width: "100%", height: 100})
.backgroundColor(0xd2cab3)
.clip(true)
Text('using container: grid').fontSize(20).fontColor(Color.Black).width('100%')
Grid() {
ForEach(this.children, (item) => {
GridItem() {
Text(item)
.backgroundColor(0xbbb2cb)
.fontSize(40)
.aspectRatio(this.aspectRatio)
}
}, item=>item)
}
.columnsTemplate('1fr 1fr 1fr')
.columnsGap(10)
.rowsGap(10)
.size({width: "100%", height: 165})
.backgroundColor(0xd2cab3)
Text('displayPriority 4').fontSize(20).fontColor(Color.Black).width('100%')
Flex({justifyContent: FlexAlign.SpaceBetween}) {
ForEach(this.priorityChildren, (item)=>{
if (item.priority === 1 || item.priority === 5) {
Text(`1\n(priority:${item.priority})`)
.width(135)
.height(60)
.fontSize(18)
.textAlign(TextAlign.Center)
.backgroundColor(0xbbb2cb)
.displayPriority(item.priority)
.key('displayPriority')
} else {
Text(item.text)
.width(135)
.height(60)
.fontSize(18)
.textAlign(TextAlign.Center)
.backgroundColor(0xbbb2cb)
.displayPriority(item.priority)
}
}, item=>item.text)
}
.width(this.container[this.currentIndex].size)
.backgroundColor(0xd2cab3)
}.padding(10)
}
onPageShow() {
let aspectRatioChangeEvent = {
eventId: 20,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(aspectRatioChangeEvent, this.stateChangCallBack);
let priorityChangeEvent = {
eventId: 21,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(priorityChangeEvent, this.stateChangCallBack);
}
stateChangCallBack = (eventData) => {
console.info("LayoutConstraints page stateChangCallBack" + JSON.stringify(eventData));
if (eventData) {
if (eventData.data.aspectRatio) {
this.aspectRatio = eventData.data.aspectRatio;
} else if (eventData.data.displayPriority) {
let priority = JSON.parse(JSON.stringify(this.priorityChildren));
priority[0].priority = eventData.data.displayPriority;
this.priorityChildren = [];
this.priorityChildren = priority;
}
}
}
// @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';
class ContainerInfo {
label: string = ''
size: string = ''
};
class ChildInfo {
text: string = ''
priority: number = 0
};
@Entry
@Component
struct LayoutConstraints {
private children: string[] = ['1', '2', '3', '4', '5', '6'];
@State aspectRatio: number = 1.5;
private container: ContainerInfo[] = [
{ label: 'Big container', size: '97%' },
{ label: 'Small container', size: '30%' }];
@State priorityChildren: any[] = [
{ text: '1\n(priority:1)', priority: 1 },
{ text: '2\n(priority:2)', priority: 2 },
{ text: '3\n(priority:3)', priority: 3 },
{ text: '4\n(priority:4)', priority: 4 }];
@State currentIndex: number = 0;
build() {
Column({ space: 20 }) {
Text('using container: row').fontSize(20).fontColor(Color.Black).width('100%')
Row({ space: 10 }) {
ForEach(this.children, (item) => {
Text(item)
.backgroundColor(0xbbb2cb)
.fontSize(20)
.aspectRatio(this.aspectRatio)
.height(60)
Text(item)
.backgroundColor(0xbbb2cb)
.fontSize(20)
.aspectRatio(this.aspectRatio)
.width(60)
.key('aspectRatio')
}, item => item)
}
.size({ width: "100%", height: 100 })
.backgroundColor(0xd2cab3)
.clip(true)
Text('using container: grid').fontSize(20).fontColor(Color.Black).width('100%')
Grid() {
ForEach(this.children, (item) => {
GridItem() {
Text(item)
.backgroundColor(0xbbb2cb)
.fontSize(40)
.aspectRatio(this.aspectRatio)
}
}, item => item)
}
.columnsTemplate('1fr 1fr 1fr')
.columnsGap(10)
.rowsGap(10)
.size({ width: "100%", height: 165 })
.backgroundColor(0xd2cab3)
Text('displayPriority 4').fontSize(20).fontColor(Color.Black).width('100%')
Flex({ justifyContent: FlexAlign.SpaceBetween }) {
ForEach(this.priorityChildren, (item) => {
if (item.priority === 1 || item.priority === 5) {
Text(`1\n(priority:${item.priority})`)
.width(135)
.height(60)
.fontSize(18)
.textAlign(TextAlign.Center)
.backgroundColor(0xbbb2cb)
.displayPriority(item.priority)
.key('displayPriority')
} else {
Text(item.text)
.width(135)
.height(60)
.fontSize(18)
.textAlign(TextAlign.Center)
.backgroundColor(0xbbb2cb)
.displayPriority(item.priority)
}
}, item => item.text)
}
.width(this.container[this.currentIndex].size)
.backgroundColor(0xd2cab3)
}.padding(10)
}
onPageShow() {
let aspectRatioChangeEvent = {
eventId: 20,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(aspectRatioChangeEvent, this.stateChangCallBack);
let priorityChangeEvent = {
eventId: 21,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(priorityChangeEvent, this.stateChangCallBack);
let priorityChangeEvent2 = {
eventId: 1112,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(priorityChangeEvent2, this.stateChangCallBack);
}
stateChangCallBack = (eventData) => {
console.info("LayoutConstraints page stateChangCallBack" + JSON.stringify(eventData));
if (eventData) {
if (eventData.data.aspectRatio) {
this.aspectRatio = eventData.data.aspectRatio;
} else if (eventData.data.displayPriority) {
let priority = JSON.parse(JSON.stringify(this.priorityChildren));
priority[0].priority = eventData.data.displayPriority;
this.priorityChildren = [];
this.priorityChildren = priority;
}
}
}
}
\ 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 ListExample {
private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
@State listDirection: Axis = Axis.Vertical;
@State editMode: boolean = false;
@State edgeEffect: EdgeEffect = EdgeEffect.None;
@State chainAnimation: boolean = false;
@State strokeWidth: number = 2.000000;
@State color: string = 0xFFFFFF;
@State startMargin: number = 20.000000;
@State endMargin: number = 20.000000;
onPageShow() {
console.info('[list] page show called');
var stateChangeEvent = {
eventId: 124,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
var stateChangeEventTwo = {
eventId: 125,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventTwo, this.stateChangCallBackTwo);
}
private stateChangCallBack = (eventData) => {
console.info("[stateChangCallBack] stateChangCallBack");
if (eventData != null) {
console.info("[stateChangCallBack] state change called:" + JSON.stringify(eventData));
if(eventData.data.listDirection != null) {
this.listDirection = eventData.data.listDirection;
}
if(eventData.data.editMode != null) {
this.editMode = eventData.data.editMode;
}
if(eventData.data.edgeEffect != null) {
this.edgeEffect = eventData.data.edgeEffect;
}
if(eventData.data.chainAnimation != null) {
this.chainAnimation = eventData.data.chainAnimation;
}
}
}
private stateChangCallBackTwo = (eventData) => {
console.info("[stateChangCallBackTwo] stateChangCallBack");
if (eventData != null) {
console.info("[stateChangCallBackTwo] state change called:" + JSON.stringify(eventData));
if(eventData.data.strokeWidth != null) {
this.strokeWidth = eventData.data.strokeWidth;
}
if(eventData.data.color != null) {
this.color = eventData.data.color;
}
if(eventData.data.startMargin != null) {
this.startMargin = eventData.data.startMargin;
}
if(eventData.data.endMargin != null) {
this.endMargin = eventData.data.endMargin;
}
}
}
build() {
Stack({ alignContent: Alignment.TopStart }) {
Column() {
List({ space: 20, initialIndex: 0 }) {
ForEach(this.arr, (item) => {
ListItem() {
Text('' + item)
.width('100%').height(100).fontSize(16)
.textAlign(TextAlign.Center).borderRadius(10).backgroundColor(0xFFFFFF)
}.editable(true)
}, item => item)
}
.key('list')
.listDirection(this.listDirection)
.divider({ strokeWidth: this.strokeWidth, color: this.color, startMargin: this.startMargin, endMargin: this.endMargin })
.edgeEffect(this.edgeEffect)
.chainAnimation(this.chainAnimation)
.multiSelectable(true)
.onScrollIndex((firstIndex: number, lastIndex: number) => {
console.info('first' + firstIndex)
console.info('last' + lastIndex)
})
.onScroll((scrollOffset: number, scrollState: ScrollState) => {
console.info('scrollOffset:' + scrollOffset)
console.info('scrollState:' + scrollState)
})
.editMode(this.editMode)
.onItemDelete((index: number) => {
console.info(this.arr[index] + 'Delete')
this.arr.splice(index, 1)
console.info(JSON.stringify(this.arr))
this.editFlag = false
return true
}).width('90%')
}.width('100%')
Button('edit list')
.onClick(() => {
this.editMode = !this.editMode
}).margin({ top: 5, left: 20 })
}.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 })
}
// @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 ListExample {
private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
@State listDirection: Axis = Axis.Vertical;
@State editMode: boolean = false;
@State edgeEffect: EdgeEffect = EdgeEffect.None;
@State chainAnimation: boolean = false;
@State strokeWidth: number = 2.000000;
@State color: string = 0xFFFFFF;
@State startMargin: number = 20.000000;
@State endMargin: number = 20.000000;
onPageShow() {
console.info('[list] page show called');
var stateChangeEvent = {
eventId: 124,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
var stateChangeEventTwo = {
eventId: 125,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventTwo, this.stateChangCallBackTwo);
var stateChangeEvent3 = {
eventId: 901,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent3, this.stateChangCallBackTwo);
var stateChangeEvent4 = {
eventId: 902,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent4, this.stateChangCallBackTwo);
var stateChangeEvent5 = {
eventId: 903,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent5, this.stateChangCallBackTwo);
}
private stateChangCallBack = (eventData) => {
console.info("[stateChangCallBack] stateChangCallBack");
if (eventData != null) {
console.info("[stateChangCallBack] state change called:" + JSON.stringify(eventData));
if (eventData.data.listDirection != null) {
this.listDirection = eventData.data.listDirection;
}
if (eventData.data.editMode != null) {
this.editMode = eventData.data.editMode;
}
if (eventData.data.edgeEffect != null) {
this.edgeEffect = eventData.data.edgeEffect;
}
if (eventData.data.chainAnimation != null) {
this.chainAnimation = eventData.data.chainAnimation;
}
}
}
private stateChangCallBackTwo = (eventData) => {
console.info("[stateChangCallBackTwo] stateChangCallBack");
if (eventData != null) {
console.info("[stateChangCallBackTwo] state change called:" + JSON.stringify(eventData));
if (eventData.data.strokeWidth != null) {
this.strokeWidth = eventData.data.strokeWidth;
}
if (eventData.data.color != null) {
this.color = eventData.data.color;
}
if (eventData.data.startMargin != null) {
this.startMargin = eventData.data.startMargin;
}
if (eventData.data.endMargin != null) {
this.endMargin = eventData.data.endMargin;
}
}
}
build() {
Stack({ alignContent: Alignment.TopStart }) {
Column() {
List({ space: 20, initialIndex: 0 }) {
ForEach(this.arr, (item) => {
ListItem() {
Text('' + item)
.width('100%')
.height(100)
.fontSize(16)
.textAlign(TextAlign.Center)
.borderRadius(10)
.backgroundColor(0xFFFFFF)
}.editable(true)
}, item => item)
}
.key('list')
.listDirection(this.listDirection)
.divider({
strokeWidth: this.strokeWidth,
color: this.color,
startMargin: this.startMargin,
endMargin: this.endMargin
})
.edgeEffect(this.edgeEffect)
.chainAnimation(this.chainAnimation)
.multiSelectable(true)
.onScrollIndex((firstIndex: number, lastIndex: number) => {
console.info('first' + firstIndex)
console.info('last' + lastIndex)
})
.onScroll((scrollOffset: number, scrollState: ScrollState) => {
console.info('scrollOffset:' + scrollOffset)
console.info('scrollState:' + scrollState)
})
.editMode(this.editMode)
.onItemDelete((index: number) => {
console.info(this.arr[index] + 'Delete')
this.arr.splice(index, 1)
console.info(JSON.stringify(this.arr))
this.editFlag = false
return true
})
.width('90%')
}.width('100%')
Button('edit list')
.onClick(() => {
this.editMode = !this.editMode
}).margin({ top: 5, left: 20 })
}.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 })
}
}
\ No newline at end of file
......@@ -44,7 +44,7 @@ struct MarqueeExample {
.allowScale(false)
.fontWeight(FontWeight.Bold)
.backgroundColor(Color.Black)
.margin({bottom:40})
.margin({ bottom: 40 })
.onStart(() => {
console.log('Marquee animation complete onStart')
console.info('Onstart current action state is: ' + this.fontColor);
......@@ -125,7 +125,7 @@ struct MarqueeExample {
})
.width(200)
.height(60)
.margin({bottom:20})
.margin({ bottom: 20 })
}
.width('100%')
.height('100%')
......
// @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 OverlayExample {
@State title: string = 'old title'
@State x: number = 0
@State y: number = -15
@State alignment: Alignment = Alignment.Bottom
onPageShow() {
console.info('[overlay] page show called ');
var stateChangeEvent = {
eventId: 143,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
}
private stateChangCallBack = (eventData) => {
console.info("[stateChangCallBack] stateChangCallBack ");
if (eventData != null) {
console.info("[stateChangCallBack] state change called: " + JSON.stringify(eventData));
if (eventData.data.align != null) {
this.alignment = eventData.data.align
}
if (eventData.data.title != null) {
this.title = eventData.data.title
}
if (eventData.data.x != null) {
this.x = eventData.data.x
}
if (eventData.data.y != null) {
this.y = eventData.data.y
}
}
}
build() {
Column() {
Column() {
Text('floating layer')
.fontSize(12).fontColor(0xCCCCCC).maxLines(1)
Column() {
Image('/images/img.jpeg')
.width(340).height(240)
.key('overlay')
.overlay(this.title,
{ align: this.alignment, offset: { x: this.x, y: this.y } })
}.border({ color: Color.Black, width: 2 })
}.width('100%')
}.padding({ top: 20 })
}
// @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 OverlayExample {
@State title: string = 'old title'
@State x: number = 0
@State y: number = -15
@State alignment: Alignment = Alignment.Bottom
onPageShow() {
console.info('[overlay] page show called ');
var stateChangeEvent = {
eventId: 143,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
var stateChangeEvent2 = {
eventId: 1110,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent2, this.stateChangCallBack);
}
private stateChangCallBack = (eventData) => {
console.info("[stateChangCallBack] stateChangCallBack ");
if (eventData != null) {
console.info("[stateChangCallBack] state change called: " + JSON.stringify(eventData));
if (eventData.data.align != null) {
this.alignment = eventData.data.align
}
if (eventData.data.title != null) {
this.title = eventData.data.title
}
if (eventData.data.x != null) {
this.x = eventData.data.x
}
if (eventData.data.y != null) {
this.y = eventData.data.y
}
}
}
build() {
Column() {
Column() {
Text('floating layer')
.fontSize(12).fontColor(0xCCCCCC).maxLines(1)
Column() {
Image('/images/img.jpeg')
.width(340).height(240)
.key('overlay')
.overlay(this.title,
{ align: this.alignment, offset: { x: this.x, y: this.y } })
}.border({ color: Color.Black, width: 2 })
}.width('100%')
}.padding({ top: 20 })
}
}
\ 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 StepperExample {
@State currentIndex: number = 0
@State firstState: ItemState = ItemState.Normal
@State secondState: ItemState = ItemState.Normal
@State disabled: ItemState = ItemState.Normal
build() {
Stepper({
index: this.currentIndex
}) {
StepperItem() {
Text('Page One')
.fontSize(35)
.fontColor(Color.Blue)
.width(200)
.lineHeight(50)
.margin({top:250})
}
.nextLabel('')
.position({x: '35%', y: 0})
.key('stepperItem1')
StepperItem() {
Text('Page Two')
.fontSize(35)
.fontColor(Color.Blue)
.width(200)
.lineHeight(50)
.margin({top:250})
.key('text1')
.onClick(()=>{
this.firstState = this.firstState === ItemState.Skip ? ItemState.Normal : ItemState.Skip
})
}
.nextLabel('Next')
.prevLabel('Previous')
.status(this.firstState)
.position({x: '35%', y: 0})
.key('stepperItem2')
StepperItem() {
Text('Page Three')
.fontSize(35)
.fontColor(Color.Blue)
.width(200)
.lineHeight(50)
.margin({top:250})
.key('text2')
.onClick(()=>{
this.secondState = this.secondState === ItemState.Waiting ? ItemState.Normal : ItemState.Waiting
})
}
.position({x: '35%', y: 0})
.status(this.secondState)
.key('stepperItem3')
StepperItem() {
Text('Page four')
.fontSize(35)
.fontColor(Color.Blue)
.width(200)
.lineHeight(50)
.margin({top:250})
}
.position({x: '35%', y: 0})
.nextLabel('Finish')
.key('stepperItem4')
}
.onFinish(() => {
console.log('onFinish')
})
.onSkip(() => {
console.log('onSkip')
})
.onChange((prevIndex: number, index: number) => {
this.currentIndex = index
})
.align(Alignment.Center)
.key('stepper')
}
onPageShow() {
console.info('stepper page show called');
var stateChangeEvent = {
eventId: 202,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack)
}
private stateChangCallBack = (eventData) => {
console.info("stepper page stateChangCallBack" + JSON.stringify(eventData));
if (eventData != null) {
console.info("stepper page state change called:" + JSON.stringify(eventData));
if(eventData.data.currentIndex != null) {
this.currentIndex = parseInt(eventData.data.currentIndex);
}
if(eventData.data.disabled != null) {
this.disabled = eventData.data.disabled;
}
}
}
// @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 StepperExample {
@State currentIndex: number = 0
@State firstState: ItemState = ItemState.Normal
@State secondState: ItemState = ItemState.Normal
@State disabled: ItemState = ItemState.Normal
build() {
Stepper({
index: this.currentIndex
}) {
StepperItem() {
Text('Page One')
.fontSize(35)
.fontColor(Color.Blue)
.width(200)
.lineHeight(50)
.margin({ top: 250 })
}
.nextLabel('')
.position({ x: '35%', y: 0 })
.key('stepperItem1')
StepperItem() {
Text('Page Two')
.fontSize(35)
.fontColor(Color.Blue)
.width(200)
.lineHeight(50)
.margin({ top: 250 })
.key('text1')
.onClick(() => {
this.firstState = this.firstState === ItemState.Skip ? ItemState.Normal : ItemState.Skip
})
}
.nextLabel('Next')
.prevLabel('Previous')
.status(this.firstState)
.position({ x: '35%', y: 0 })
.key('stepperItem2')
StepperItem() {
Text('Page Three')
.fontSize(35)
.fontColor(Color.Blue)
.width(200)
.lineHeight(50)
.margin({ top: 250 })
.key('text2')
.onClick(() => {
this.secondState = this.secondState === ItemState.Waiting ? ItemState.Normal : ItemState.Waiting
})
}
.position({ x: '35%', y: 0 })
.status(this.secondState)
.key('stepperItem3')
StepperItem() {
Text('Page four')
.fontSize(35)
.fontColor(Color.Blue)
.width(200)
.lineHeight(50)
.margin({ top: 250 })
}
.position({ x: '35%', y: 0 })
.nextLabel('Finish')
.key('stepperItem4')
}
.onFinish(() => {
console.log('onFinish')
})
.onSkip(() => {
console.log('onSkip')
})
.onChange((prevIndex: number, index: number) => {
this.currentIndex = index
})
.align(Alignment.Center)
.key('stepper')
}
onPageShow() {
console.info('stepper page show called');
var stateChangeEvent = {
eventId: 202,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack)
var stateChangeEventTwo = {
eventId: 909,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventTwo, this.stateChangCallBack);
var stateChangeEventThree = {
eventId: 910,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventThree, this.stateChangCallBack);
}
private stateChangCallBack = (eventData) => {
console.info("stepper page stateChangCallBack" + JSON.stringify(eventData));
if (eventData != null) {
console.info("stepper page state change called:" + JSON.stringify(eventData));
if (eventData.data.currentIndex != null) {
this.currentIndex = parseInt(eventData.data.currentIndex);
}
if (eventData.data.disabled != null) {
this.disabled = eventData.data.disabled;
}
}
}
}
\ No newline at end of file
......@@ -92,7 +92,7 @@ struct SwiperExample {
.displayMode(this.displayMode)
.displayCount(this.displayCount)
.effectMode(this.edgeEffect)
.indicatorStyle({ top: 20, right: 20,size:2,color: Color.Blue})
.indicatorStyle({ top: 20, right: 20, size: 2, color: Color.Blue })
.key('swiper')
.onChange((index: number) => {
console.info(index.toString())
......
......@@ -68,8 +68,9 @@ struct TextStyle {
.fontStyle(FontStyle.Normal)
.fontWeight(400)
.fontFamily('source-sans-pro,cursive,sans-serif')
}.width('100%').margin({top: 20})
}.width('100%').margin({ top: 20 })
}
onPageShow() {
let fontColorChangeEvent = {
eventId: 37,
......@@ -97,6 +98,7 @@ struct TextStyle {
}
events_emitter.on(fontFamilyChangeEvent, this.textStyleChangCallBack);
}
textStyleChangCallBack = (eventData) => {
console.info("textStyle page stateChangCallBack" + JSON.stringify(eventData));
if (eventData && eventData.data) {
......
......@@ -19,7 +19,7 @@ import events_emitter from '@ohos.emitter'
@Entry
@Preview
@Component
struct TouchExample {
struct TouchExample {
@State text: string = ''
@State eventType: string = ''
@State touchFlag: boolean = false
......@@ -37,13 +37,13 @@ struct TouchExample {
console.info("[touch] page stateChangCallBack");
if (eventData != null) {
console.info("[touch] page state change called:" + JSON.stringify(eventData));
if(eventData.data.text != null) {
if (eventData.data.text != null) {
this.text = eventData.data.text;
}
if(eventData.data.eventType != null) {
if (eventData.data.eventType != null) {
this.eventType = eventData.data.eventType;
}
if(eventData.data.touchFlag != null) {
if (eventData.data.touchFlag != null) {
this.touchFlag = eventData.data.touchFlag
}
}
......@@ -51,7 +51,10 @@ struct TouchExample {
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Button('Touch').backgroundColor(0x2788D9).height(40).width(80)
Button('Touch')
.backgroundColor(0x2788D9)
.height(40)
.width(80)
.key('touch')
.onTouch((event: Touch) => {
if (event.type === TouchType.Down) {
......@@ -72,7 +75,7 @@ struct TouchExample {
stopPropagation: () => {
console.info('stopPropagation')
}
console.info('onTouch successful, touchFlag is : ' + this.eventType + ', ' +this.touchFlag)
console.info('onTouch successful, touchFlag is : ' + this.eventType + ', ' + this.touchFlag)
console.info(this.text = 'TouchType:' + this.eventType
+ '\nDistance between touch point and touch element:\nx: '
+ event.touches[0].x + '\n' + 'y: ' + event.touches[0].y + '\ncomponent globalPos:('
......@@ -84,7 +87,7 @@ struct TouchExample {
+ event.target.area.globalPos.x + ',' + event.target.area.globalPos.y + ')\nwidth:'
+ event.target.area.width + '\nheight:' + event.target.area.height)
console.log('fang--->A')
try{
try {
console.log('fang--->B')
var backData = {
data: {
......@@ -99,7 +102,7 @@ struct TouchExample {
console.log('fang--->D')
console.info("touchFlag start to emit action state")
events_emitter.emit(backEvent, backData)
}catch{
} catch {
console.info("touchFlag emit action state err: " + JSON.stringify(err.message))
}
})
......
......@@ -23,7 +23,6 @@ struct TouchAbleExample {
@State text1: string = '';
@State text2: string = '';
@State touchableValue: boolean = false;
private stateChangCallBack = (eventData) => {
console.info("[TouchAble] page stateChangCallBack");
if (eventData != null) {
......@@ -46,13 +45,17 @@ struct TouchAbleExample {
build() {
Stack() {
Rect()
.fill(Color.Gray).width(150).height(150)
.fill(Color.Gray)
.width(150)
.height(150)
.onClick(() => {
console.info(this.text1 = 'Rect Clicked')
})
.overlay(this.text1, { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
Ellipse()
.fill(Color.Pink).width(150).height(80)
.fill(Color.Pink)
.width(150)
.height(80)
.key('ellipse')
.touchable(this.touchableValue)
.onClick(() => {
......
// @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 VisibilityExample {
@State visibility: Visibility = Visibility.Visible;
onPageShow() {
let hiddenChangeEvent = {
eventId: 47,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(hiddenChangeEvent, this.hiddenChangCallBack)
let noneChangeEvent = {
eventId: 48,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(noneChangeEvent, this.noneChangCallBack)
}
private hiddenChangCallBack = (eventData) => {
console.info("[hiddenChangCallBack] stateChangCallBack");
if (eventData != null) {
console.info("[hiddenChangCallBack] state change called:" + JSON.stringify(eventData));
if(eventData.data.visibility != null) {
this.visibility = eventData.data.visibility;
}
}
}
private noneChangCallBack = (eventData) => {
console.info("[noneChangCallBack] stateChangCallBack");
if (eventData != null) {
console.info("[noneChangCallBack] state change called:" + JSON.stringify(eventData));
if(eventData.data.visibility != null) {
this.visibility = eventData.data.visibility;
}
}
}
build() {
Column() {
Column() {
Text('BoxOne').fontSize(9).width('90%').fontColor(0xCCCCCC)
Row().visibility(this.visibility).width('90%').height(80).backgroundColor(0xAFEEEE).padding(20).key('box')
Text('BoxTwo').fontSize(9).width('90%').fontColor(0xCCCCCC)
Row().visibility(Visibility.Visible).width('90%').height(80).backgroundColor(0xAFEEEE).padding(20)
}.width('90%').border({ width: 1 })
}.width('100%').margin({ top: 5 })
}
}
// @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 VisibilityExample {
@State visibility: Visibility = Visibility.Visible;
onPageShow() {
let hiddenChangeEvent = {
eventId: 47,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(hiddenChangeEvent, this.hiddenChangCallBack)
let noneChangeEvent = {
eventId: 48,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(noneChangeEvent, this.noneChangCallBack)
var stateChangeEvent2 = {
eventId: 1116,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent2, this.stateChangCallBack);
}
private hiddenChangCallBack = (eventData) => {
console.info("[hiddenChangCallBack] stateChangCallBack");
if (eventData != null) {
console.info("[hiddenChangCallBack] state change called:" + JSON.stringify(eventData));
if (eventData.data.visibility != null) {
this.visibility = eventData.data.visibility;
}
}
}
private noneChangCallBack = (eventData) => {
console.info("[noneChangCallBack] stateChangCallBack");
if (eventData != null) {
console.info("[noneChangCallBack] state change called:" + JSON.stringify(eventData));
if (eventData.data.visibility != null) {
this.visibility = eventData.data.visibility;
}
}
}
build() {
Column() {
Column() {
Text('BoxOne').fontSize(9).width('90%').fontColor(0xCCCCCC)
Row()
.visibility(this.visibility)
.width('90%')
.height(80)
.backgroundColor(0xAFEEEE)
.padding(20)
.key('box')
Text('BoxTwo').fontSize(9).width('90%').fontColor(0xCCCCCC)
Row()
.visibility(Visibility.Visible)
.width('90%')
.height(80)
.backgroundColor(0xAFEEEE)
.padding(20)
}.width('90%').border({ width: 1 })
}.width('100%').margin({ top: 5 })
}
}
// @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 zIndexExample {
@State zIndex: number = 1;
onPageShow() {
console.info('[zIndex] page show called ');
var stateChangeEvent = {
eventId: 236,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
}
private stateChangCallBack = (eventData) => {
console.info("[stateChangCallBack] stateChangCallBack ");
if (eventData != null) {
console.info("[stateChangCallBack] state change called: " + JSON.stringify(eventData));
if (eventData.data.zIndex != null) {
this.zIndex = eventData.data.zIndex
}
}
}
build() {
Column() {
Stack() {
Text('first child, zIndex(2)')
.size({ width: '40%', height: '60%' }).backgroundColor(0xbbb2cb)
.zIndex(2)
Text('second child, default zIndex(0)')
.size({ width: '90%', height: '80%' }).backgroundColor(0xd2cab3).align(Alignment.TopStart)
Text('third child, zIndex(1)')
.size({ width: '70%', height: '50%' })
.backgroundColor(0xc1cbac)
.align(Alignment.TopStart)
.zIndex(this.zIndex)
.key('zIndex')
}
}.width('100%').height(200)
}
// @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 zIndexExample {
@State zIndex: number = 1;
onPageShow() {
console.info('[zIndex] page show called ');
var stateChangeEvent = {
eventId: 236,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
var stateChangeEvent2 = {
eventId: 1113,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent2, this.stateChangCallBack);
}
private stateChangCallBack = (eventData) => {
console.info("[stateChangCallBack] stateChangCallBack ");
if (eventData != null) {
console.info("[stateChangCallBack] state change called: " + JSON.stringify(eventData));
if (eventData.data.zIndex != null) {
this.zIndex = eventData.data.zIndex
}
}
}
build() {
Column() {
Stack() {
Text('first child, zIndex(2)')
.size({ width: '40%', height: '60%' }).backgroundColor(0xbbb2cb)
.zIndex(2)
Text('second child, default zIndex(0)')
.size({ width: '90%', height: '80%' }).backgroundColor(0xd2cab3).align(Alignment.TopStart)
Text('third child, zIndex(1)')
.size({ width: '70%', height: '50%' })
.backgroundColor(0xc1cbac)
.align(Alignment.TopStart)
.zIndex(this.zIndex)
.key('zIndex')
}
}.width('100%').height(200)
}
}
\ 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 appearJsunit() {
describe('appInfoTest', function () {
beforeEach(async function (done) {
console.info("appear beforeEach start");
let options = {
uri: 'pages/appear',
}
let result;
try {
router.clear();
let pages = router.getState();
console.info("get appear state pages: " + JSON.stringify(pages));
if (!("appear" == pages.name)) {
console.info("get appear state pages.name: " + JSON.stringify(pages.name));
result = await router.push(options);
await Utils.sleep(2000);
console.info("push appear page result: " + JSON.stringify(result));
}
} catch (err) {
console.error("push appear page error: " + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("appear after each called");
})
it('testAppear01', 0, async function (done) {
console.info('[testAppear01] START');
await Utils.sleep(1000);
try {
let callBackAppear = (backData) => {
console.info("testAppear01 get appearEvent result is: " + JSON.stringify(appearEvent));
expect(backData.data.ACTION).assertEqual(true);
}
var appearEvent = {
eventId: 58,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(appearEvent, callBackAppear);
} catch (err) {
console.info("testAppear01 on appearEvent err : " + JSON.stringify(err));
}
console.info("testAppear01 click result is: " + JSON.stringify(sendEventByKey('appear', 10, "")));
console.info('[testAppear01] END');
done();
});
it('testAppear02', 0, async function (done) {
console.info('[testAppear02] START');
await Utils.sleep(1000);
try {
let callBackAppear = (backData) => {
console.info("testAppear02 get appearEvent result is: " + JSON.stringify(appearEvent));
expect(backData.data.ACTION).assertEqual(true);
}
var appearEvent = {
eventId: 59,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(appearEvent, callBackAppear);
} catch (err) {
console.info("testAppear02 on appearEvent err : " + JSON.stringify(err));
}
console.info("testAppear02 appearEvent click result is: " + JSON.stringify(sendEventByKey('appear', 10, "")));
try {
let callBackDisAppear = (backData) => {
console.info("testAppear02 get disAppearEvent result is: " + JSON.stringify(disAppearEvent));
expect(backData.data.ACTION).assertEqual(true);
}
var disAppearEvent = {
eventId: 60,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(disAppearEvent, callBackDisAppear);
} catch (err) {
console.info("testAppear02 on disAppearEvent err : " + JSON.stringify(err));
}
console.info("testAppear02 disAppearEvent click result is: " + JSON.stringify(sendEventByKey('appear', 10, "")));
console.info('[testAppear02] END');
done();
});
})
}
// @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.ets';
export default function appearJsunit() {
describe('appearTest', function () {
beforeEach(async function (done) {
console.info("appear beforeEach start");
let options = {
uri: 'pages/appear',
}
let result;
try {
router.clear();
let pages = router.getState();
console.info("get appear state pages: " + JSON.stringify(pages));
if (!("appear" == pages.name)) {
console.info("get appear state pages.name: " + JSON.stringify(pages.name));
result = await router.push(options);
await Utils.sleep(2000);
console.info("push appear page result: " + JSON.stringify(result));
}
} catch (err) {
console.error("push appear page error: " + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("appear after each called");
})
it('testAppear01', 0, async function (done) {
console.info('[testAppear01] START');
await Utils.sleep(1000);
try {
let callBackAppear = (backData) => {
console.info("testAppear01 get appearEvent result is: " + JSON.stringify(appearEvent));
expect(backData.data.ACTION).assertEqual(true);
}
var appearEvent = {
eventId: 58,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(appearEvent, callBackAppear);
} catch (err) {
console.info("testAppear01 on appearEvent err : " + JSON.stringify(err));
}
console.info("testAppear01 click result is: " + JSON.stringify(sendEventByKey('appear', 10, "")));
console.info('[testAppear01] END');
done();
});
it('testAppear02', 0, async function (done) {
console.info('[testAppear02] START');
await Utils.sleep(1000);
try {
let callBackAppear = (backData) => {
console.info("testAppear02 get appearEvent result is: " + JSON.stringify(appearEvent));
expect(backData.data.ACTION).assertEqual(true);
}
var appearEvent = {
eventId: 59,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(appearEvent, callBackAppear);
} catch (err) {
console.info("testAppear02 on appearEvent err : " + JSON.stringify(err));
}
console.info("testAppear02 appearEvent click result is: " + JSON.stringify(sendEventByKey('appear', 10, "")));
try {
let callBackDisAppear = (backData) => {
console.info("testAppear02 get disAppearEvent result is: " + JSON.stringify(disAppearEvent));
expect(backData.data.ACTION).assertEqual(true);
}
var disAppearEvent = {
eventId: 60,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(disAppearEvent, callBackDisAppear);
} catch (err) {
console.info("testAppear02 on disAppearEvent err : " + JSON.stringify(err));
}
console.info("testAppear02 disAppearEvent click result is: " + JSON.stringify(sendEventByKey('appear', 10, "")));
console.info('[testAppear02] END');
done();
});
})
}
// @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 areaChangeJsunit() {
describe('areaChange', function () {
beforeEach(async function (done) {
let options = {
uri: 'pages/areaChange',
}
try {
router.clear();
let pages = router.getState();
console.info("get areaChange state success " + JSON.stringify(pages));
if (!("areaChange" == pages.name)) {
console.info("get areaChange state success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(1000);
console.info("push areaChange page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push areaChange page error: " + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("areaChange after each called");
});
it('areaChangeTest_0100', 0, async function (done) {
console.info('areaChangeTest_0100 START');
let strJson = getInspectorByKey('text1');
console.info("areaChangeTest_0100 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("areaChangeTest_0100 component obj is: " + JSON.stringify(obj));
expect(obj.$type).assertEqual('Text');
expect(obj.$attrs.width).assertEqual('42.000000');
expect(obj.$attrs.height).assertEqual('23.000000');
console.info('areaChangeTest_0100 END');
done();
});
it('areaChangeTest_0200', 0, async function (done) {
console.info('areaChangeTest_0200 START');
let strJson = getInspectorByKey('text2');
console.info("areaChangeTest_0200 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("areaChangeTest_0200 component obj is: " + JSON.stringify(obj));
expect(obj.$type).assertEqual('Text');
expect(obj.$attrs.width).assertEqual('519.000000');
expect(obj.$attrs.height).assertEqual('140.000000');
console.info('areaChangeTest_0200 END');
done();
});
it('areaChangeTest_0300', 0, async function (done) {
console.info('areaChangeTest_0300 START');
await Utils.sleep(1000);
let callback = (indexEvent) => {
console.info("areaChangeTest_0300 get state result is: " + JSON.stringify(indexEvent));
expect(indexEvent.data.value).assertEqual('TextText');
}
let indexEvent = {
eventId: 61,
priority: events_emitter.EventPriority.LOW
}
try {
events_emitter.on(indexEvent, callback);
} catch (err) {
console.info("areaChangeTest_0300 on events_emitter err : " + JSON.stringify(err));
}
console.info("areaChangeTest_0300 click result is: " + JSON.stringify(sendEventByKey('text1', 10, "")));
var innerEventOne = {
eventId: 62,
priority: events_emitter.EventPriority.LOW
}
await Utils.sleep(1500);
var callback1 = (eventData) => {
console.info("areaChangeTest_0300 get event state result is: " + JSON.stringify(eventData));
expect(eventData.data.ACTION).assertEqual(true);
}
try {
events_emitter.on(innerEventOne, callback1);
} catch (err) {
console.info("areaChangeTest_0300 on events_emitter err : " + JSON.stringify(err));
}
console.info('areaChangeTest_0300 END');
done();
});
it('areaChangeTest_0400', 0, async function (done) {
console.info('areaChangeTest_0400 START');
await Utils.sleep(1000);
let callback = (indexEvent) => {
console.info("areaChangeTest_0400 get state result is: " + JSON.stringify(indexEvent));
expect(indexEvent.data.value).assertEqual('TextTextText');
}
let indexEvent = {
eventId: 62,
priority: events_emitter.EventPriority.LOW
}
try {
events_emitter.on(indexEvent, callback);
} catch (err) {
console.info("areaChangeTest_0400 on events_emitter err : " + JSON.stringify(err));
}
console.info("areaChangeTest_0400 click result is: " + JSON.stringify(sendEventByKey('text1',10,"")));
console.info('areaChangeTest_0400 END');
done();
});
})
}
// @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.ets';
export default function areaChangeJsunit() {
describe('areaChangeTest', function () {
beforeEach(async function (done) {
let options = {
uri: 'pages/areaChange',
}
try {
router.clear();
let pages = router.getState();
console.info("get areaChange state success " + JSON.stringify(pages));
if (!("areaChange" == pages.name)) {
console.info("get areaChange state success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(1000);
console.info("push areaChange page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push areaChange page error: " + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("areaChange after each called");
});
it('areaChangeTest_0100', 0, async function (done) {
console.info('areaChangeTest_0100 START');
let strJson = getInspectorByKey('text1');
console.info("areaChangeTest_0100 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("areaChangeTest_0100 component obj is: " + JSON.stringify(obj));
expect(obj.$type).assertEqual('Text');
expect(obj.$attrs.width).assertEqual('42.000000');
expect(obj.$attrs.height).assertEqual('23.000000');
console.info('areaChangeTest_0100 END');
done();
});
it('areaChangeTest_0200', 0, async function (done) {
console.info('areaChangeTest_0200 START');
let strJson = getInspectorByKey('text2');
console.info("areaChangeTest_0200 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("areaChangeTest_0200 component obj is: " + JSON.stringify(obj));
expect(obj.$type).assertEqual('Text');
expect(obj.$attrs.width).assertEqual('519.000000');
expect(obj.$attrs.height).assertEqual('210.000000');
console.info('areaChangeTest_0200 END');
done();
});
it('areaChangeTest_0300', 0, async function (done) {
console.info('areaChangeTest_0300 START');
await Utils.sleep(1000);
let callback = (indexEvent) => {
console.info("areaChangeTest_0300 get state result is: " + JSON.stringify(indexEvent));
expect(indexEvent.data.value).assertEqual('TextText');
}
let indexEvent = {
eventId: 61,
priority: events_emitter.EventPriority.LOW
}
try {
events_emitter.on(indexEvent, callback);
} catch (err) {
console.info("areaChangeTest_0300 on events_emitter err : " + JSON.stringify(err));
}
console.info("areaChangeTest_0300 click result is: " + JSON.stringify(sendEventByKey('text1', 10, "")));
var innerEventOne = {
eventId: 62,
priority: events_emitter.EventPriority.LOW
}
await Utils.sleep(1500);
var callback1 = (eventData) => {
console.info("areaChangeTest_0300 get event state result is: " + JSON.stringify(eventData));
expect(eventData.data.ACTION).assertEqual(true);
}
try {
events_emitter.on(innerEventOne, callback1);
} catch (err) {
console.info("areaChangeTest_0300 on events_emitter err : " + JSON.stringify(err));
}
console.info('areaChangeTest_0300 END');
done();
});
it('areaChangeTest_0400', 0, async function (done) {
console.info('areaChangeTest_0400 START');
await Utils.sleep(1000);
let callback = (indexEvent) => {
console.info("areaChangeTest_0400 get state result is: " + JSON.stringify(indexEvent));
expect(indexEvent.data.value).assertEqual('TextTextText');
}
let indexEvent = {
eventId: 62,
priority: events_emitter.EventPriority.LOW
}
try {
events_emitter.on(indexEvent, callback);
} catch (err) {
console.info("areaChangeTest_0400 on events_emitter err : " + JSON.stringify(err));
}
console.info("areaChangeTest_0400 click result is: " + JSON.stringify(sendEventByKey('text1', 10, "")));
console.info('areaChangeTest_0400 END');
done();
});
})
}
// @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.ets';
export default function columnJsunit() {
describe('columnTest', function () {
beforeEach(async function (done) {
console.info("column beforeEach start");
let options = {
uri: 'pages/column',
}
try {
router.clear();
let pages = router.getState();
console.info("get column state pages:" + JSON.stringify(pages));
if (!("column" == pages.name)) {
console.info("get column state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push column page result:" + JSON.stringify(result));
}
} catch (err) {
console.error("push column page error:" + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("column after each called");
});
it('testColumn01', 0, async function (done) {
console.info('[testColumn01] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('alignItemsColumn');
let obj = JSON.parse(strJson);
console.info("[testColumn01] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.alignItems).assertEqual('HorizontalAlign.Start');
console.info('[testColumn01] END');
done();
});
it('testColumn02', 0, async function (done) {
console.info('[testColumn02] START');
try {
var eventData = {
data: {
"alignItems":HorizontalAlign.Center
}
}
var innerEvent = {
eventId: 192,
priority: events_emitter.EventPriority.LOW
}
console.info("[testColumn02] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testColumn02] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('alignItemsColumn');
let obj = JSON.parse(strJson);
console.info("[testColumn02] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.alignItems).assertEqual('HorizontalAlign.Center');
console.info('[testColumn02] END');
done();
});
})
}
// @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 ellipseJsunit() {
describe('appInfoTest', function () {
beforeEach(async function (done) {
console.info("ellipse beforeEach start");
let options = {
uri: 'pages/ellipse',
}
try {
router.clear();
let pages = router.getState();
console.info("get ellipse state pages:" + JSON.stringify(pages));
if (!("ellipse" == pages.name)) {
console.info("get ellipse state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push ellipse page result:" + JSON.stringify(result));
}
} catch (err) {
console.error("push ellipse page error:" + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("ellipse after each called");
});
it('testEllipse01', 0, async function (done) {
console.info('[testEllipse01] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson);
console.info("[testEllipse02] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.height).assertEqual('200.00px');
expect(obj.$attrs.width).assertEqual('200.00px');
console.info('testEllipse02 END');
done();
});
it('testEllipse02', 0, async function (done) {
console.info('[testEllipse02] START');
try {
var eventData = {
data: {
"width": '100px'
}
}
var innerEvent = {
eventId: 92,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEllipse02] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEllipse02] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson);
console.info("[testEllipse02] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.width).assertEqual('100.00px');
console.info('testEllipse02 END');
done();
});
it('testEllipse03', 0, async function (done) {
console.info('[testEllipse03] START');
try {
var eventData = {
data: {
"height": '500px'
}
}
var innerEvent = {
eventId: 92,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEllipse03] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEllipse03] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson);
console.info("[testEllipse03] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.height).assertEqual('500.00px');
console.info('testEllipse03 END');
done();
});
})
}
// @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.ets';
export default function ellipseJsunit() {
describe('ellipseTest', function () {
beforeEach(async function (done) {
console.info("ellipse beforeEach start");
let options = {
uri: 'pages/ellipse',
}
try {
router.clear();
let pages = router.getState();
console.info("get ellipse state pages:" + JSON.stringify(pages));
if (!("ellipse" == pages.name)) {
console.info("get ellipse state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push ellipse page result:" + JSON.stringify(result));
}
} catch (err) {
console.error("push ellipse page error:" + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("ellipse after each called");
});
it('testEllipse01', 0, async function (done) {
console.info('[testEllipse01] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson);
console.info("[testEllipse02] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.height).assertEqual('200.00px');
expect(obj.$attrs.width).assertEqual('200.00px');
console.info('testEllipse02 END');
done();
});
it('testEllipse02', 0, async function (done) {
console.info('[testEllipse02] START');
try {
var eventData = {
data: {
"width": '100px'
}
}
var innerEvent = {
eventId: 92,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEllipse02] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEllipse02] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson);
console.info("[testEllipse02] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.width).assertEqual('100.00px');
console.info('testEllipse02 END');
done();
});
it('testEllipse03', 0, async function (done) {
console.info('[testEllipse03] START');
try {
var eventData = {
data: {
"height": '500px'
}
}
var innerEvent = {
eventId: 92,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEllipse03] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEllipse03] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson);
console.info("[testEllipse03] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.height).assertEqual('500.00px');
console.info('testEllipse03 END');
done();
});
it('testEllipse04', 0, async function (done) {
console.info('[testEllipse04] START');
try {
var eventData = {
data: {
"width": '1111111111111'
}
}
var innerEvent = {
eventId: 907,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEllipse04] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEllipse04] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson);
console.info("[testEllipse04] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.width).assertEqual('1111111111111.00px');
console.info('testEllipse04 END');
done();
});
it('testEllipse05', 0, async function (done) {
console.info('[testEllipse05] START');
try {
var eventData = {
data: {
"height": '12111111111111'
}
}
var innerEvent = {
eventId: 907,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEllipse05] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEllipse05] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson);
console.info("[testEllipse05] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.height).assertEqual('12111111111111.00px');
console.info('testEllipse05 END');
done();
});
it('testEllipse06', 0, async function (done) {
console.info('[testEllipse06] START');
try {
var eventData = {
data: {
"height": '-40'
}
}
var innerEvent = {
eventId: 908,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEllipse06] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEllipse06] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson);
console.info("[testEllipse06] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.height).assertEqual('-40.00px');
console.info('testEllipse06 END');
done();
});
it('testEllipse07', 0, async function (done) {
console.info('[testEllipse07] START');
try {
var eventData = {
data: {
"width": '-10'
}
}
var innerEvent = {
eventId: 908,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEllipse07] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEllipse07] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson);
console.info("[testEllipse07] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.width).assertEqual('-10.00px');
console.info('testEllipse07 END');
done();
});
})
}
// @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 enableJsunit() {
describe('appInfoTest', function () {
beforeEach(async function (done) {
console.info("enable beforeEach start");
let options = {
uri: 'pages/enable',
}
try {
router.clear();
let pages = router.getState();
console.info("get enable state pages: " + JSON.stringify(pages));
if (!("enable" == pages.name)) {
console.info("get enable state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push enable page result:" + JSON.stringify(result));
}
} catch (err) {
console.error("push enable page error:" + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("enable after each called");
});
it('testEnable01', 0, async function (done) {
console.info('[testEnable01] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('enabled');
let obj = JSON.parse(strJson);
console.info("[testEnable01] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.enabled).assertEqual(true);
console.info('[testEnable01] END');
done();
});
it('testEnable02', 0, async function (done) {
console.info('[testEnable02] START');
try {
var eventData = {
data: {
"enabled": false,
"text": "disable"
}
}
var innerEvent = {
eventId: 93,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEnable02] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEnable02] change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJson = getInspectorByKey('enabled');
let obj = JSON.parse(strJson);
console.info("[testEnable02] obj is: " + JSON.stringify(obj.$attrs.enabled));
expect(obj.$attrs.enabled).assertEqual(false);
console.info('testEnable02 END');
done();
});
})
}
// @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.ets';
export default function enableJsunit() {
describe('enableTest', function () {
beforeEach(async function (done) {
console.info("enable beforeEach start");
let options = {
uri: 'pages/enable',
}
try {
router.clear();
let pages = router.getState();
console.info("get enable state pages: " + JSON.stringify(pages));
if (!("enable" == pages.name)) {
console.info("get enable state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push enable page result:" + JSON.stringify(result));
}
} catch (err) {
console.error("push enable page error:" + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("enable after each called");
});
it('testEnable01', 0, async function (done) {
console.info('[testEnable01] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('enabled');
let obj = JSON.parse(strJson);
console.info("[testEnable01] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.enabled).assertEqual(true);
console.info('[testEnable01] END');
done();
});
it('testEnable02', 0, async function (done) {
console.info('[testEnable02] START');
try {
var eventData = {
data: {
"enabled": false,
"text": "disable"
}
}
var innerEvent = {
eventId: 93,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEnable02] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEnable02] change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJson = getInspectorByKey('enabled');
let obj = JSON.parse(strJson);
console.info("[testEnable02] obj is: " + JSON.stringify(obj.$attrs.enabled));
expect(obj.$attrs.enabled).assertEqual(false);
console.info('testEnable02 END');
done();
});
it('testEnable03', 0, async function (done) {
console.info('[testEnable03] START');
try {
var eventData = {
data: {
"enabled": -3
}
}
var innerEvent = {
eventId: 1111,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEnable03] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEnable03] change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJson = getInspectorByKey('enabled');
let obj = JSON.parse(strJson);
console.info("[testEnable03] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.enabled).assertEqual(true);
console.info('testEnable03 END');
done();
});
it('testEnable04', 0, async function (done) {
console.info('testEnable04 START');
try {
let eventData = {
data: {
"enabled": 33567444
}
}
let indexEvent = {
eventId: 1111,
priority: events_emitter.EventPriority.LOW
}
console.info("testEnable04 start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("testEnable04 change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJsonNew = getInspectorByKey('enabled');
let objNew = JSON.parse(strJsonNew);
console.info("testEnable04 component objNew is: " + JSON.stringify(objNew));
expect(objNew.$attrs.enabled).assertEqual(true);
done();
});
})
}
......@@ -15,7 +15,7 @@
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets"
import router from '@system.router';
import Utils from './Utils';
import Utils from './Utils.ets';
export default function globalJsunit() {
describe('globalJsunit', function () {
......@@ -50,7 +50,7 @@ export default function globalJsunit() {
* @tc.desc Test setTimeout
*/
it('ACE_global_setTimeout', 0, function (done) {
let caseName:string = "ACE_global_setTimeout"
let caseName: string = "ACE_global_setTimeout"
console.info(`${caseName} START`);
setTimeout(() => {
expect(true).assertTrue();
......@@ -65,9 +65,9 @@ export default function globalJsunit() {
* @tc.desc Test canIUse
*/
it('ACE_global_canIUse', 0, function (done) {
let caseName:string = "ACE_global_canIUse"
let caseName: string = "ACE_global_canIUse"
console.info(`${caseName} START`);
let syscapName:string = "";
let syscapName: string = "";
var result = canIUse(syscapName);
expect(result === false).assertTrue();
console.info(`${caseName} END`);
......@@ -80,11 +80,12 @@ export default function globalJsunit() {
* @tc.desc Test getApp
*/
it('ACE_global_getApp', 0, function (done) {
let caseName:string = "ACE_global_getApp"
let caseName: string = "ACE_global_getApp"
console.info(`${caseName} START`);
try{
try {
var info = getApp();
}catch(err){}
} catch (err) {
}
console.info(`${caseName} END`);
done();
});
......@@ -95,11 +96,12 @@ export default function globalJsunit() {
* @tc.desc Test createLocalParticleAbility
*/
it('ACE_global_createLocalParticleAbility', 0, function (done) {
let caseName:string = "ACE_global_createLocalParticleAbility"
let caseName: string = "ACE_global_createLocalParticleAbility"
console.info(`${caseName} START`);
try{
try {
var info = createLocalParticleAbility(100);
}catch(err){}
} catch (err) {
}
console.info(`${caseName} END`);
done();
});
......@@ -166,6 +168,5 @@ export default function globalJsunit() {
});
})
}
// @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 girdContainerJsunit() {
describe('appInfoTest', function () {
beforeEach(async function (done) {
console.info("girdContainer beforeEach start");
let options = {
uri: 'pages/gridContainer',
}
try {
router.clear();
let pages = router.getState();
console.info("get girdContainer state pages:" + JSON.stringify(pages));
if (!("gridContainer" == pages.name)) {
console.info("get girdContainer state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push girdContainer page result:" + JSON.stringify(result));
}
} catch (err) {
console.error("push girdContainer page error:" + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("girdContainer after each called");
});
it('testGirdContainer01', 0, async function (done) {
console.info('[testGirdContainer01] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('gridContainer');
let obj = JSON.parse(strJson);
console.info("[testGirdContainer01] obj is: " + JSON.stringify(obj));
expect(obj.$type).assertEqual('GridContainer');
expect(obj.$attrs.constructor.columns).assertEqual('12');
expect(obj.$attrs.constructor.sizeType).assertEqual('SizeType.XS');
expect(obj.$attrs.constructor.gutter).assertEqual('10.00vp');
expect(obj.$attrs.constructor.margin).assertEqual('20.00vp');
console.info('testGirdContainer01 END');
done();
});
it('testGirdContainer02', 0, async function (done) {
console.info('[testEllipse02] START');
try {
var eventData = {
data: {
"sizeType": 'SM'
}
}
var innerEvent = {
eventId: 109,
priority: events_emitter.EventPriority.LOW
}
console.info("[testGirdContainer02] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testGirdContainer02] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('gridContainer');
let obj = JSON.parse(strJson);
console.info("[testGirdContainer02] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.constructor.sizeType).assertEqual('SizeType.SM');
console.info('testGirdContainer02 END');
done();
});
})
}
// @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.ets';
export default function girdContainerJsunit() {
describe('girdContainerTest', function () {
beforeEach(async function (done) {
console.info("girdContainer beforeEach start");
let options = {
uri: 'pages/gridContainer',
}
try {
router.clear();
let pages = router.getState();
console.info("get girdContainer state pages:" + JSON.stringify(pages));
if (!("gridContainer" == pages.name)) {
console.info("get girdContainer state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push girdContainer page result:" + JSON.stringify(result));
}
} catch (err) {
console.error("push girdContainer page error:" + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("girdContainer after each called");
});
it('testGirdContainer01', 0, async function (done) {
console.info('[testGirdContainer01] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('gridContainer');
let obj = JSON.parse(strJson);
console.info("[testGirdContainer01] obj is: " + JSON.stringify(obj));
expect(obj.$type).assertEqual('GridContainer');
expect(obj.$attrs.constructor.columns).assertEqual('12');
expect(obj.$attrs.constructor.sizeType).assertEqual('SizeType.XS');
expect(obj.$attrs.constructor.gutter).assertEqual('10.00vp');
expect(obj.$attrs.constructor.margin).assertEqual('20.00vp');
console.info('testGirdContainer01 END');
done();
});
it('testGirdContainer02', 0, async function (done) {
console.info('[testEllipse02] START');
try {
var eventData = {
data: {
"sizeType": 'SM'
}
}
var innerEvent = {
eventId: 109,
priority: events_emitter.EventPriority.LOW
}
console.info("[testGirdContainer02] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testGirdContainer02] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('gridContainer');
let obj = JSON.parse(strJson);
console.info("[testGirdContainer02] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.constructor.sizeType).assertEqual('SizeType.SM');
console.info('testGirdContainer02 END');
done();
});
})
}
// @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.ets';
export default function layoutConstraintsJsunit() {
describe('layoutConstraintsTest', function () {
beforeEach(async function (done) {
console.info("layoutConstraints beforeEach start");
let options = {
uri: 'pages/layoutConstraints',
}
try {
router.clear();
let pages = router.getState();
console.info("get layoutConstraints state pages:" + JSON.stringify(pages));
if (!("layoutConstraints" == pages.name)) {
console.info("get layoutConstraints state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push layoutConstraints page result:" + JSON.stringify(result));
}
} catch (err) {
console.error("push layoutConstraints page error:" + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("layoutConstraints after each called");
});
it('testLayoutConstraints001', 0, async function (done) {
console.info('[testLayoutConstraints001] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('aspectRatio');
console.info("[testLayoutConstraints001] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints001] aspectRatio: " + obj.$attrs.aspectRatio);
expect(obj.$attrs.aspectRatio).assertEqual(1.5);
done();
});
it('testLayoutConstraints002', 0, async function (done) {
console.info('[testLayoutConstraints002] START');
try {
let eventData = {
data: {
"aspectRatio": 2
}
}
let indexEvent = {
eventId: 20,
priority: events_emitter.EventPriority.LOW
}
console.info("[testLayoutConstraints002] start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("[testLayoutConstraints002] change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJson = getInspectorByKey('aspectRatio');
console.info("[testLayoutConstraints002] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints002] aspectRatio: " + obj.$attrs.aspectRatio);
expect(obj.$attrs.aspectRatio).assertEqual(2);
done();
});
it('testLayoutConstraints003', 0, async function (done) {
console.info('[testLayoutConstraints003] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('displayPriority');
console.info("[testLayoutConstraints003] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints003] displayPriority: " + obj.$attrs.displayPriority);
expect(obj.$attrs.displayPriority).assertEqual(1);
done();
});
it('testLayoutConstraints004', 0, async function (done) {
console.info('[testLayoutConstraints004] START');
try {
let eventData = {
data: {
"displayPriority": 5
}
}
let indexEvent = {
eventId: 21,
priority: events_emitter.EventPriority.LOW
}
console.info("[testLayoutConstraints004] start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("[testLayoutConstraints004] change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJson = getInspectorByKey('displayPriority');
console.info("[testLayoutConstraints004] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints004] displayPriority: " + obj.$attrs.displayPriority);
expect(obj.$attrs.displayPriority).assertEqual(5);
done();
});
});
// @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.ets';
export default function layoutConstraintsJsunit() {
describe('layoutConstraintsTest', function () {
beforeEach(async function (done) {
console.info("layoutConstraints beforeEach start");
let options = {
uri: 'pages/layoutConstraints',
}
try {
router.clear();
let pages = router.getState();
console.info("get layoutConstraints state pages:" + JSON.stringify(pages));
if (!("layoutConstraints" == pages.name)) {
console.info("get layoutConstraints state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push layoutConstraints page result:" + JSON.stringify(result));
}
} catch (err) {
console.error("push layoutConstraints page error:" + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("layoutConstraints after each called");
});
it('testLayoutConstraints001', 0, async function (done) {
console.info('[testLayoutConstraints001] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('aspectRatio');
console.info("[testLayoutConstraints001] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints001] aspectRatio: " + obj.$attrs.aspectRatio);
expect(obj.$attrs.aspectRatio).assertEqual(1.5);
done();
});
it('testLayoutConstraints002', 0, async function (done) {
console.info('[testLayoutConstraints002] START');
try {
let eventData = {
data: {
"aspectRatio": 2
}
}
let indexEvent = {
eventId: 20,
priority: events_emitter.EventPriority.LOW
}
console.info("[testLayoutConstraints002] start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("[testLayoutConstraints002] change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJson = getInspectorByKey('aspectRatio');
console.info("[testLayoutConstraints002] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints002] aspectRatio: " + obj.$attrs.aspectRatio);
expect(obj.$attrs.aspectRatio).assertEqual(2);
done();
});
it('testLayoutConstraints003', 0, async function (done) {
console.info('[testLayoutConstraints003] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('displayPriority');
console.info("[testLayoutConstraints003] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints003] displayPriority: " + obj.$attrs.displayPriority);
expect(obj.$attrs.displayPriority).assertEqual(1);
done();
});
it('testLayoutConstraints004', 0, async function (done) {
console.info('[testLayoutConstraints004] START');
try {
let eventData = {
data: {
"displayPriority": 5
}
}
let indexEvent = {
eventId: 21,
priority: events_emitter.EventPriority.LOW
}
console.info("[testLayoutConstraints004] start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("[testLayoutConstraints004] change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJson = getInspectorByKey('displayPriority');
console.info("[testLayoutConstraints004] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints004] displayPriority: " + obj.$attrs.displayPriority);
expect(obj.$attrs.displayPriority).assertEqual(5);
done();
});
it('testLayoutConstraints005', 0, async function (done) {
console.info('[testLayoutConstraints005] START');
try {
let eventData = {
data: {
"aspectRatio": -4
}
}
let indexEvent = {
eventId: 1112,
priority: events_emitter.EventPriority.LOW
}
console.info("[testLayoutConstraints005] start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("[testLayoutConstraints005] change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJson = getInspectorByKey('aspectRatio');
console.info("[testLayoutConstraints005] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints005] aspectRatio: " + obj.$attrs.aspectRatio);
expect(obj.$attrs.aspectRatio).assertEqual(-4);
done();
});
it('testLayoutConstraints006', 0, async function (done) {
console.info('[testLayoutConstraints006] START');
try {
let eventData = {
data: {
"aspectRatio": 9997077
}
}
let indexEvent = {
eventId: 1112,
priority: events_emitter.EventPriority.LOW
}
console.info("[testLayoutConstraints006] start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("[testLayoutConstraints006] change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJson = getInspectorByKey('aspectRatio');
console.info("[testLayoutConstraints006] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints006] aspectRatio: " + obj.$attrs.aspectRatio);
expect(obj.$attrs.aspectRatio).assertEqual(9997077);
done();
});
});
}
\ No newline at end of file
......@@ -51,7 +51,7 @@ export default function touchAbleJsunit() {
let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson);
console.info("[testTouchAble001] component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.focusable).assertEqual(false);
expect(obj.$attrs.focusable).assertEqual(true);
done();
});
......
......@@ -19,21 +19,22 @@ import events_emitter from '@ohos.emitter'
@Component
struct ParentComp {
@State isCountDown: boolean = true
build() {
Column() {
Text(this.isCountDown ? 'Count Down' : 'Stopwatch')
if (this.isCountDown) {
Image($rawfile('ic_health_heart.png')).width(50).height(50)
TimerComponent({counter: 10, changePerSec: -1, showInColor: Color.Red})
TimerComponent({ counter: 10, changePerSec: -1, showInColor: Color.Red })
} else {
Image($rawfile('ic_health_heart.png')).width(150).height(150)
TimerComponent({counter: 0, changePerSec: +1, showInColor: Color.Black })
TimerComponent({ counter: 0, changePerSec: +1, showInColor: Color.Black })
}
Button(this.isCountDown ? 'Swtich to Stopwatch' : 'Switch to Count Down')
.onClick(() => {
this.isCountDown = !this.isCountDown
})
.key('button1')
.key('button1')
}
}
}
......@@ -43,8 +44,8 @@ struct TimerComponent {
@State counter: number = 0
private changePerSec: number = -1
private showInColor: Color = Color.Black
private timerId : number = -1
@State onActionCalled :boolean = false
private timerId: number = -1
@State onActionCalled: boolean = false
build() {
Text(`${this.counter}sec`)
......@@ -52,7 +53,9 @@ struct TimerComponent {
}
aboutToAppear() {
this.timerId = setInterval(() => {this.counter += this.changePerSec}, 1000)
this.timerId = setInterval(() => {
this.counter += this.changePerSec
}, 1000)
}
aboutToDisappear() {
......
......@@ -14,7 +14,6 @@
* limitations under the License.
*/
import file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index.ets";
import testsuite from "../test/List.test.ets";
import featureAbility from "@ohos.ability.featureAbility";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册