提交 721c29d9 编写于 作者: Z zhangrao

add compnent

Signed-off-by: Nzhangrao <zhangrao@huawei.com>
上级 ee562c51
......@@ -21,6 +21,7 @@ struct CanvasExample {
private scroller: Scroller = new Scroller();
private settings: RenderingContextSettings = new RenderingContextSettings(true);
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
build() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) {
Scroll(this.scroller) {
......@@ -47,6 +48,7 @@ struct CanvasExample {
this.shadowOffsetX();
this.shadowOffsetY();
this.imageSmoothingEnabled();
this.imageSmoothingQuality();
this.fillRect();
this.strokeRect();
this.clearRect();
......@@ -62,11 +64,27 @@ struct CanvasExample {
this.rect();
this.transform();
this.setTransform();
// this.getTransform();
// this.resetTransform();
this.translate();
this.drawImage();
this.createImageData();
this.createImageDataByImageData();
this.getImageData();
this.putImageData();
this.createLinearGradient();
this.createRadialGradient();
this.restore();
this.save();
this.addPath();
this.lineDash();
this.toDataURL();
this.getWidth();
this.getHeight();
this.fill();
this.direction();
this.textMetrics();
this.getBitImageSize();
})
.key('canvas1')
}.width('100%').height('400%')
......@@ -228,6 +246,11 @@ struct CanvasExample {
this.context.imageSmoothingEnabled = false;
this.context.drawImage( img, 30, 950, 160, 100);
}
imageSmoothingQuality() {
// let img = new ImageBitmap('/images/img.jpeg');
// this.context.imageSmoothingQuality('high');
// this.context.drawImage( img, 30, 950, 160, 100);
}
fillRect() {
this.context.fillRect(10, 1080, 80, 80);
}
......@@ -244,7 +267,7 @@ struct CanvasExample {
this.context.fillText("Hello World!", 120, 1200);
}
strokeText() {
this.context.font = '20px sans-serif'
this.context.font = '20px sans-serif';
this.context.strokeText("Hello World!", 260, 1195);
}
measureText() {
......@@ -320,6 +343,13 @@ struct CanvasExample {
this.context.fillRect(0, 1650, 100, 100);
this.context.setTransform(1, 0, 0, 1, 0, 0);
}
getTransform() {
let data = this.context.getTransform();
console.info("[canvas] get transform----" + data);
}
resetTransform() {
this.context.resetTransform();
}
translate() {
this.context.fillRect(180, 1650, 50, 50);
this.context.translate(50, 50);
......@@ -327,7 +357,8 @@ struct CanvasExample {
}
drawImage() {
let img = new ImageBitmap('/images/img.jpeg');
this.context.drawImage(img, 0, 0, 500, 500, 0, 1780, 300, 150);
// this.context.filter('grayscale(50%)');
this.context.drawImage(img, 0, 0, 500, 500, 0, 1780, 200, 100);
}
createImageData() {
let imageData = this.context.createImageData(100, 100);
......@@ -342,4 +373,82 @@ struct CanvasExample {
let imageData = this.context.getImageData(10, 10, 80, 80);
console.info("[canvas] get image data-----" + JSON.stringify(imageData));
}
putImageData() {
let imageData = this.context.createImageData(80, 80);
for (var i = 0; i < imageData.data.length; i += 4) {
imageData.data[i + 0] = 255;
imageData.data[i + 1] = 0;
imageData.data[i + 2] = 255;
imageData.data[i + 3] = 255;
}
this.context.putImageData(imageData, 250, 1660);
}
createLinearGradient() {
let grad = this.context.createLinearGradient(50, 1900, 150, 2000);
grad.addColorStop(0.0, 'red');
grad.addColorStop(0.5, 'white');
grad.addColorStop(1.0, 'green');
this.context.fillStyle = grad;
this.context.fillRect(10, 1900, 150, 150);
}
createRadialGradient() {
let grad = this.context.createRadialGradient(280, 1970, 40, 280, 1970, 80);
grad.addColorStop(0.0, 'red');
grad.addColorStop(0.5, 'white');
grad.addColorStop(1.0, 'green');
this.context.fillStyle = grad;
this.context.fillRect(200, 1900, 150, 150);
this.context.closePath();
}
restore() {
this.context.restore();
}
save() {
this.context.save();
}
addPath() {
let path2Da = new Path2D("M250 150 L150 350 L350 350 Z");
let path2Db = new Path2D();
path2Db.addPath(path2Da);
this.context.stroke(path2Db);
}
lineDash() {
this.context.beginPath();
this.context.arc(20, 2130, 50, 0, 6.28);
this.context.setLineDash([10, 20]);
this.context.stroke();
// let obj = this.context.getLineDash();
// console.info("[canvas] get line dash----" + JSON.stringify(obj));
}
toDataURL() {
let dataUrl = this.context.toDataURL();
console.info("[canvas] canvas rendering context2D toDataURL-----" + JSON.stringify(dataUrl));
}
getWidth() {
let width = this.context.width;
console.info("[canvas] canvas width---" + width);
}
getHeight() {
let height = this.context.height;
console.info("[canvas] canvas height---" + height);
}
fill() {
this.context.beginPath();
this.context.rect(130, 2080, 100, 100);
this.context.fill('nonzero');
}
direction() {
// this.context.direction('inherit');
}
textMetrics() {
this.context.font = '20px sans-serif';
this.context.fillText("Hello World!", 120, 2150);
let obj = this.context.measureText("Hello World!");
console.info("[canvas] textMetrics info---" + JSON.stringify(obj));
}
getBitImageSize() {
let img = new ImageBitmap('/images/img.jpeg');
let width = img.width;
let height = img.height;
}
}
\ No newline at end of file
/**
* 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 Canvas2Example {
private scroller: Scroller = new Scroller();
private settings: RenderingContextSettings = new RenderingContextSettings(true);
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings);
build() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) {
Scroll(this.scroller) {
Column() {
Canvas(this.context)
.width('100%')
.height('100%')
.backgroundColor('#ffff00')
.onReady(() => {
this.transferFromImageBitmap();
this.offScreenToDataURL();
})
.key('canvas1')
}.width('100%').height('400%')
}.scrollable(ScrollDirection.Vertical).scrollBar(BarState.On)
.scrollBarColor(Color.Gray).scrollBarWidth(10)
}
.width('100%')
.height('100%')
}
onPageShow() {
}
transferFromImageBitmap() {
this.offContext.fillStyle = '#0000ff';
this.offContext.fillRect(20, 160, 150, 100);
let image = this.offContext.transferToImageBitmap();
this.context.transferFromImageBitmap(image);
}
offScreenToDataURL() {
let dataUrl = this.offContext.toDataURL();
console.info("[canvas] offContext canvas rendering context2D toDataURL-----" + JSON.stringify(dataUrl));
}
}
\ 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.
*/
@Entry
@Component
struct ColumnExample {
build() {
Column({ space: 5 }) {
Text('space').fontSize(9).fontColor(0xCCCCCC).width('90%')
Column({ space: 5 }) {
Column().width('100%').height(50).backgroundColor(0xAFEEEE)
Column().width('100%').height(50).backgroundColor(0x00FFFF).key('column')
}.width('90%').height(107).border({ width: 1 })
Text('alignItems(Start)').fontSize(9).fontColor(0xCCCCCC).width('90%')
Column() {
Column().width('50%').height(50).backgroundColor(0xAFEEEE)
Column().width('50%').height(50).backgroundColor(0x00FFFF)
}.alignItems(HorizontalAlign.Start).width('90%').border({ width: 1 })
Text('alignItems(End)').fontSize(9).fontColor(0xCCCCCC).width('90%')
Column() {
Column().width('50%').height(50).backgroundColor(0xAFEEEE)
Column().width('50%').height(50).backgroundColor(0x00FFFF)
}.alignItems(HorizontalAlign.End).width('90%').border({ width: 1 })
}.width('100%').padding({ top: 5 })
}
}
\ No newline at end of file
// @ts-nocheck
import events_emitter from '@ohos.emitter'
@Entry
@Component
struct MotionPathExample {
@State offsetX: number = 0
@State offsetY: number = 0
@State toggle: boolean = true
@State rotatable: boolean = false
@State path:string='Mstart.x start.y L300 200 L300 500 Lend.x end.y'
@State fromX:number = 0
@State toY:number = 1
build() {
Column() {
Button('click me')
.key('button')
.motionPath({ path: this.path, from: this.fromX, to: this.toY, rotatable:this.rotatable })
.onClick(() => {
this.rotatable = true;
console.info('button rotate current action state is:' + this.rotatable);
try {
var backData = {
data: {
"ACTION": this.rotatable,
}
}
var backEvent = {
eventId: 2,
priority: events_emitter.EventPriority.LOW
}
console.info("button start to emit action state")
events_emitter.emit(backEvent, backData)
} catch (err) {
console.info("button emit action state err: " + JSON.stringify(err.message))
}
animateTo({ duration: 4000, curve: Curve.Linear }, () => {
this.toggle = !this.toggle;
})
})
.backgroundColor(0x317aff)
Button('next')
.key('button1')
.onClick(() => {
try {
var backData = {
data: {
"fromX": this.fromX,
"toY": this.toY
}
}
var backEvent = {
eventId: 3,
priority: events_emitter.EventPriority.LOW
}
console.info("button1 position start to emit action state")
events_emitter.emit(backEvent, backData)
} catch (err) {
console.info("button1 position emit action state err: " + JSON.stringify(err.message))
}
})
}
.key('motionPath')
.width('100%').height('100%').alignItems(this.toggle ? HorizontalAlign.Start : HorizontalAlign.Center)
}
onPageShow(){
console.info('motionPath page show called');
var stateChangeEvent = {
eventId:1,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent,this.stateChangeCallBack)
}
private stateChangeCallBack = (eventData) =>{
if(eventData != null){
console.info('motionPath page state change called:' + JSON.stringify(eventData));
if(eventData.data.fromX != null){
this.fromX == parseInt(eventData.data.fromX);
}
if(eventData.data.toY != null){
this.toY == parseInt(eventData.data.toY);
}
}
}
}
/**
* 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 RatingExample {
@State rating: number = 1
@State indicator: boolean = false
private stateChangCallBack = (eventData) => {
console.info("rating page stateChangCallBack");
if (eventData != null) {
console.info("rating page state change called:" + JSON.stringify(eventData.data.rating));
if(eventData.data.rating != null) {
this.rating = eventData.data.rating;
}
}
}
onPageShow() {
console.info('rating page show called');
var stateChangeEvent = {
eventId: 440,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack)
var stateChangeEventTwo = {
eventId: 441,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventTwo, this.stateChangCallBack)
var stateChangeEventThree = {
eventId: 442,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventThree, this.stateChangCallBack)
var stateChangeEventFour = {
eventId: 443,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventFour, this.stateChangCallBack)
var stateChangeEventFive = {
eventId: 444,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventFive, this.stateChangCallBack)
var stateChangeEventSix = {
eventId: 444,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventSix , this.stateChangCallBack)
var stateChangeEventSeven = {
eventId: 445,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventSeven , this.stateChangCallBack)
}
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('current score is ' + this.rating).fontSize(20)
Rating({ rating: this.rating, indicator: this.indicator })
.stars(5).key('Rating')
.stepSize(0.5)
.onChange((value: number) => {
this.rating = value
})
}.width(350).height(200).padding(35)
}
}
// @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 scrollCode {
@State scrollable: ScrollDirection = ScrollDirection.Vertical;
@State scrollBar: BarState = BarState.On;
@State scrollBarColor: Color = "#FF0000FF";
@State scrollBarWidth: number = 30;
scroller: Scroller = new Scroller()
private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
private stateChangCallBack = (eventData) => {
if (eventData != null) {
console.info("scrollCode page state change called:" + JSON.stringify(eventData));
var scrollableValue = eventData.data.scrollable;
console.info("scrollableValue:" + scrollableValue);
if (scrollableValue!= null && scrollableValue.length != 0) {
this.scrollable = scrollableValue;
console.info("this.scrollable:" + this.scrollable);
}else{
console.info("scrollableValue is null or empty " + scrollableValue);
}
var scrollBarValue = eventData.data.scrollBar;
console.info("scrollBarValue:" + scrollBarValue);
if (scrollBarValue!= null && scrollBarValue.length != 0) {
this.scrollBar = scrollBarValue;
console.info("this.scrollBar:" + this.scrollBar);
}else{
console.info("scrollBarValue is null or empty " + scrollBarValue);
}
var scrollBarColorValue = eventData.data.scrollBarColor;
console.info("scrollBarColorValue:" + scrollBarColorValue);
if (scrollBarColorValue!= null && scrollBarColorValue.length != 0) {
this.scrollBarColor = scrollBarColorValue;
console.info("this.scrollBarColor:" + this.scrollBarColor);
}else{
console.info("scrollBarColorValue is null or empty " + scrollBarColorValue);
}
var scrollBarWidthValue = eventData.data.scrollBarWidth;
console.info("scrollBarWidthValue:" + scrollBarWidthValue);
if (scrollBarWidthValue!= null && scrollBarWidthValue.length != 0) {
this.scrollBarWidth = scrollBarWidthValue;
console.info("this.scrollBarWidth:" + this.scrollBarWidth);
}else{
console.info("scrollBarWidthValue is null or empty " + scrollBarWidthValue);
}
} else {
console.info("scrollCode page color not change called:" + JSON.stringify(eventData));
}
}
onPageShow() {
console.info('scrollCode page show called');
var stateChangeEvent = {
eventId: 90,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
var stateChangeEvent = {
eventId: 80,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
var stateChangeEvent = {
eventId: 85,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
var stateChangeEvent = {
eventId: 95,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
}
build() {
Stack({ alignContent: Alignment.TopStart }) {
Scroll(this.scroller) {
Column() {
ForEach(this.arr, (item) => {
Text(item.toString())
.width('90%').height(150).backgroundColor(0xFFFFFF)
.borderRadius(15).fontSize(16).textAlign(TextAlign.Center)
.margin({ top: 10 })
}, item => item)
}.width('100%')
}
.key("ScrollCode")
.scrollable(this.scrollable)
.scrollBar(this.scrollBar)
.scrollBarColor(this.scrollBarColor)
.scrollBarWidth(this.scrollBarWidth)
.onScroll((xOffset: number, yOffset: number) => {
console.info(xOffset + ' ' + yOffset)
})
.onScrollEdge((side: Edge) => {
console.info('To the edge')
})
.onScrollEnd(() => {
console.info('Scroll Stop')
})
Button('scroll 100')
.onClick(() => {
this.scroller.scrollTo({ xOffset: 0, yOffset: this.scroller.currentOffset().yOffset + 100 })
})
.margin({ top: 10, left: 20 })
Button('back top')
.onClick(() => {
this.scroller.scrollEdge(Edge.Top)
})
.margin({ top: 60, left: 20 })
Button('next page')
.onClick(() => {
this.scroller.scrollPage({ next: true })
})
.margin({ top: 110, left: 20 })
}.width('100%').height('100%').backgroundColor(0xDCDCDC)
}
}
\ 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 ShapeExample {
@State strokeDashOffset: numbert = 0;
@State strokeLineCap: LineCapStyle = LineCapStyle.Butt;
@State strokeLineJoin: LineJoinStyle = LineJoinStyle.Miter;
@State strokeMiterLimit: number = 4;
@State strokeOpacity: number = 1;
@State strokeWidth: number = 1;
@State antiAlias: boolean = true;
@State strokeDashArray: Array<Length> = [20];
@State fillOpacity: number = 0;
private stateChangCallBack = (eventData) => {
if (eventData != null) {
console.info("text page state change called:" + JSON.stringify(eventData));
if (eventData.data.strokeDashOffset != null) {
this.strokeDashOffset = parseInt(eventData.data.strokeDashOffset);
}
if (eventData.data.strokeLineCap != null) {
this.strokeLineCap = eventData.data.strokeLineCap;
}
if (eventData.data.strokeLineJoin != null) {
this.strokeLineJoin = eventData.data.strokeLineJoin;
}
if (eventData.data.strokeMiterLimit != null) {
this.strokeMiterLimit = parseInt(eventData.data.strokeMiterLimit);
}
if (eventData.data.strokeOpacity != null) {
this.strokeOpacity = parseInt(eventData.data.strokeOpacity);
}
if (eventData.data.fillOpacity != null) {
this.fillOpacity = parseInt(eventData.data.fillOpacity);
}
if (eventData.data.antiAlias != null) {
this.antiAlias = eventData.data.antiAlias;
}
if (eventData.data.strokeDashArrayOne != null) {
this.strokeDashArray[0] = parseInt(eventData.data.strokeDashArrayOne);
}
if (eventData.data.strokeDashArrayTwo != null) {
this.strokeDashArray[1] = parseInt(eventData.data.strokeDashArrayTwo);
}
if (eventData.data.strokeDashArrayThree != null) {
this.strokeDashArray[2] = parseInt(eventData.data.strokeDashArrayThree);
}
}
}
onPageShow() {
console.info('qrCode page show called');
var stateChangeEvent = {
eventId: 901,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
}
build() {
Column({ space: 2 }) {
Text('basic').fontSize(30).fontColor(0xCCCCCC).width(320)
Shape() {
Rect().width(300).height(50)
Ellipse().width(300).height(50).offset({ x: 0, y: 60 })
Path().width(300).height(10).commands('M0 0 L900 0').offset({ x: 0, y: 120 })
}
.key('shape')
.viewPort({ x: -2, y: -2, width: 304, height: 130 })
.fill(0x317Af7)
.stroke(Color.Black)
.strokeDashArray(this.strokeDashArray)
.strokeDashOffset(this.strokeDashOffset)
.strokeLineCap(this.strokeLineCap)
.strokeLineJoin(this.strokeLineJoin)
.strokeMiterLimit(this.strokeMiterLimit)
.strokeOpacity(this.strokeOpacity)
.strokeWidth(this.strokeWidth)
.antiAlias(this.antiAlias)
.fillOpacity(this.fillOpacity)
}.width('100%').margin({ top: 15 })
}
}
\ 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 SpanExample {
@State decorationValue:object={ type: TextDecorationType.None, color: Color.Red }
@State textCaseValue:TextCase=TextCase.Normal
@State fontSizeValue:number=40
private stateChangCallBack = (eventData) => {
console.info("span page state change called:" + JSON.stringify(eventData));
if (eventData != null) {
if (eventData.data.decorationValue != null) {
this.decorationValue = JSON.parse(eventData.data.decorationValue);
}
if (eventData.data.textCaseValue != null) {
this.textCaseValue = eventData.data.textCaseValue;
}
}
}
onPageShow() {
console.info('span page show called');
var stateChangeEvent = {
eventId: 40,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
var stateChangeEvent2 = {
eventId: 41,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent2, this.stateChangCallBack);
}
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
Text('Basic Usage').fontSize(9).fontColor(0xCCCCCC)
Text() {
Span('This is the Span component').fontSize(this.fontSizeValue).textCase(this.textCaseValue)
.decoration(this.decorationValue).key('decoration')
}
}.width('100%').height(250).padding({ left: 35, right: 35, top: 35 })
}
}
\ No newline at end of file
......@@ -17,13 +17,19 @@ import events_emitter from '@ohos.emitter'
@Entry
@Component
struct TextExample {
@State fontSize: number = 9
@State fontSize: number = 9
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
Text('lineHeight')
.fontSize(this.fontSize)
.fontColor(0xCCCCCC)
.key('text')
Text($r('app.string.string_hello'))
.fontColor($r('app.color.color_hello'))
.fontSize($r('app.float.font_hello'))
.key('text1')
Image($rawfile('test.png'))
.key('image')
}
.height(600)
.width(350)
......
// @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 ToggleExample {
@State selectedColor : color = '#330A59F7';
@State toggleType : ToggleType = ToggleType.Button;
@State isOn : boolean = false;
onPageShow() {
console.info('[toggle] page show called');
var stateChangeEvent = {
eventId: 1011,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
}
private stateChangCallBack = (eventData) => {
console.info("[toggle] page stateChangCallBack");
if (eventData != null) {
console.info("[toggle] page state change called:" + JSON.stringify(eventData));
if(eventData.data.selectedColor != null) {
this.selectedColor = eventData.data.selectedColor;
}
if(eventData.data.toggleType != null) {
this.toggleType = eventData.data.toggleType;
}
if(eventData.data.isOn != null) {
this.isOn = eventData.data.isOn;
}
}
}
build() {
Column({ space: 10 }) {
Text('type: Button').fontSize(12).fontColor(0xcccccc).width('90%').key('button')
Flex({ justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center }) {
Toggle({ type: this.toggleType, isOn: this.isOn }) {
Text('status button').padding({ left: 12, right: 12 })
}
.key('toggle')
.selectedColor(this.selectedColor)
.onChange((isOn: boolean) => {
console.info('Component status:' + isOn)
})
Toggle({ type: ToggleType.Button, isOn: true }) {
Text('status button').padding({ left: 12, right: 12 })
}
.selectedColor(0x39a2db)
.onChange((isOn: boolean) => {
console.info('Component status:' + isOn)
})
}
}.width('100%').padding(24)
}
}
\ No newline at end of file
......@@ -46,151 +46,151 @@ export default function animateJsunit() {
console.info("animate after each called");
});
// it('animateTest_0100', 0, async function (done) {
// console.info('animateTest_0100 START');
// await Utils.sleep(1500);
// let indexEvent = {
// eventId: 60,
// priority: events_emitter.EventPriority.LOW
// }
// let callback= (indexEvent) => {
// console.info("animateTest_0100 get state result is: " + JSON.stringify(indexEvent))
// except(indexEvent.data.duration).assertEqual('100')
// }
// try {
// events_emitter.on(indexEvent, callback);
// } catch (err) {
// console.info("animateTest_0100 on events_emitter err : " + JSON.stringify(err));
// }
// console.info("animateTest_0100 click result is: " + JSON.stringify(sendEventByKey('button1',10,"")));
// await Utils.sleep(2000);
// console.info('animateTest_0100 END');
// done();
// });
//
// it('animateTest_0200', 0, async function (done) {
// console.info('animateTest_0200 START');
// await Utils.sleep(1500);
// let indexEvent = {
// eventId: 61,
// priority: events_emitter.EventPriority.LOW
// }
// let callback= (indexEvent) => {
// console.info("animateTest_0500 get state result is: " + JSON.stringify(indexEvent))
// except(indexEvent.data.curve).assertEqual('Ease')
// }
// try {
// events_emitter.on(indexEvent, callback);
// } catch (err) {
// console.info("animateTest_0200 on events_emitter err : " + JSON.stringify(err));
// }
// console.info("animateTest_0200 click result is: " + JSON.stringify(sendEventByKey('button2',10,"")));
// await Utils.sleep(2000);
// console.info('animateTest_0200 END');
// done();
// });
//
// it('animateTest_0300', 0, async function (done) {
// console.info('animateTest_0300 START');
// await Utils.sleep(1500);
// let indexEvent = {
// eventId: 62,
// priority: events_emitter.EventPriority.LOW
// }
// let callback= (indexEvent) => {
// console.info("animateTest_0500 get state result is: " + JSON.stringify(indexEvent))
// except(indexEvent.data.iteration).assertEqual('1')
// }
// try {
// events_emitter.on(indexEvent, callback);
// } catch (err) {
// console.info("animateTest_0300 on events_emitter err : " + JSON.stringify(err));
// }
// console.info("animateTest_0300 click result is: " + JSON.stringify(sendEventByKey('button3',10,"")));
// await Utils.sleep(2000);
// console.info('animateTest_0300 END');
// done();
// });
//
// it('animateTest_0400', 0, async function (done) {
// console.info('animateTest_0400 START');
// await Utils.sleep(1500);
// let indexEvent = {
// eventId: 63,
// priority: events_emitter.EventPriority.LOW
// }
// let callback= (indexEvent) => {
// console.info("animateTest_0400 get state result is: " + JSON.stringify(indexEvent))
// except(indexEvent.data.tempo).assertEqual(1000)
// }
// try {
// events_emitter.on(indexEvent, callback);
// } catch (err) {
// console.info("animateTest_0400 on events_emitter err : " + JSON.stringify(err));
// }
// console.info("animateTest_0400 click result is: " + JSON.stringify(sendEventByKey('button4',10,"")));
// await Utils.sleep(2000);
// console.info('animateTest_0400 END');
// done();
// });
//
// it('animateTest_0500', 0, async function (done) {
// console.info('animateTest_0500 START');
// await Utils.sleep(1500);
// let indexEvent = {
// eventId: 64,
// priority: events_emitter.EventPriority.LOW
// }
// let callback= (indexEvent) => {
// console.info("animateTest_0500 get state result is: " + JSON.stringify(indexEvent))
// except(indexEvent.data.playmode).assertEqual('normal')
// }
// try {
// events_emitter.on(indexEvent, callback);
// } catch (err) {
// console.info("animateTest_0500 on events_emitter err : " + JSON.stringify(err));
// }
// console.info("animateTest_0500 click result is: " + JSON.stringify(sendEventByKey('button5',10,"")));
// await Utils.sleep(2000);
// console.info('animateTest_0500 END');
// done();
// });
//
// it('animateTest_0600', 0, async function (done) {
// console.info('animateTest_0500 START');
// try {
// let eventData = {
// data: {
// "duration":'2000'
// }
// }
// let indexEventOne = {
// eventId: 65,
// priority: events_emitter.EventPriority.LOW
// }
// console.info("animateTest_0600 start to publish emit");
// events_emitter.emit(indexEventOne, eventData);
// } catch (err) {
// console.log("animateTest_0600 change component data error: " + err.message);
// }
// let indexEvent = {
// eventId: 60,
// priority: events_emitter.EventPriority.LOW
// }
// let callback= (indexEvent) => {
// console.info("animateTest_0600 get state result is: " + JSON.stringify(indexEvent))
// except(indexEvent.data.duration).assertEqual('2000')
// }
// try {
// events_emitter.on(indexEvent, callback);
// } catch (err) {
// console.info("animateTest_0600 on events_emitter err : " + JSON.stringify(err));
// }
// console.info("animateTest_0600 click result is: " + JSON.stringify(sendEventByKey('button1',10 ,"")));
// await Utils.sleep(2000);
// console.info('animateTest_0600 END');
// done();
// });
it('animateTest_0100', 0, async function (done) {
console.info('animateTest_0100 START');
await Utils.sleep(1500);
let indexEvent = {
eventId: 60,
priority: events_emitter.EventPriority.LOW
}
let callback= (indexEvent) => {
console.info("animateTest_0100 get state result is: " + JSON.stringify(indexEvent))
except(indexEvent.data.duration).assertEqual('100')
}
try {
events_emitter.on(indexEvent, callback);
} catch (err) {
console.info("animateTest_0100 on events_emitter err : " + JSON.stringify(err));
}
console.info("animateTest_0100 click result is: " + JSON.stringify(sendEventByKey('button1',10,"")));
await Utils.sleep(2000);
console.info('animateTest_0100 END');
done();
});
it('animateTest_0200', 0, async function (done) {
console.info('animateTest_0200 START');
await Utils.sleep(1500);
let indexEvent = {
eventId: 61,
priority: events_emitter.EventPriority.LOW
}
let callback= (indexEvent) => {
console.info("animateTest_0500 get state result is: " + JSON.stringify(indexEvent))
except(indexEvent.data.curve).assertEqual('Ease')
}
try {
events_emitter.on(indexEvent, callback);
} catch (err) {
console.info("animateTest_0200 on events_emitter err : " + JSON.stringify(err));
}
console.info("animateTest_0200 click result is: " + JSON.stringify(sendEventByKey('button2',10,"")));
await Utils.sleep(2000);
console.info('animateTest_0200 END');
done();
});
it('animateTest_0300', 0, async function (done) {
console.info('animateTest_0300 START');
await Utils.sleep(1500);
let indexEvent = {
eventId: 62,
priority: events_emitter.EventPriority.LOW
}
let callback= (indexEvent) => {
console.info("animateTest_0500 get state result is: " + JSON.stringify(indexEvent))
except(indexEvent.data.iteration).assertEqual('1')
}
try {
events_emitter.on(indexEvent, callback);
} catch (err) {
console.info("animateTest_0300 on events_emitter err : " + JSON.stringify(err));
}
console.info("animateTest_0300 click result is: " + JSON.stringify(sendEventByKey('button3',10,"")));
await Utils.sleep(2000);
console.info('animateTest_0300 END');
done();
});
it('animateTest_0400', 0, async function (done) {
console.info('animateTest_0400 START');
await Utils.sleep(1500);
let indexEvent = {
eventId: 63,
priority: events_emitter.EventPriority.LOW
}
let callback= (indexEvent) => {
console.info("animateTest_0400 get state result is: " + JSON.stringify(indexEvent))
except(indexEvent.data.tempo).assertEqual(1000)
}
try {
events_emitter.on(indexEvent, callback);
} catch (err) {
console.info("animateTest_0400 on events_emitter err : " + JSON.stringify(err));
}
console.info("animateTest_0400 click result is: " + JSON.stringify(sendEventByKey('button4',10,"")));
await Utils.sleep(2000);
console.info('animateTest_0400 END');
done();
});
it('animateTest_0500', 0, async function (done) {
console.info('animateTest_0500 START');
await Utils.sleep(1500);
let indexEvent = {
eventId: 64,
priority: events_emitter.EventPriority.LOW
}
let callback= (indexEvent) => {
console.info("animateTest_0500 get state result is: " + JSON.stringify(indexEvent))
except(indexEvent.data.playmode).assertEqual('normal')
}
try {
events_emitter.on(indexEvent, callback);
} catch (err) {
console.info("animateTest_0500 on events_emitter err : " + JSON.stringify(err));
}
console.info("animateTest_0500 click result is: " + JSON.stringify(sendEventByKey('button5',10,"")));
await Utils.sleep(2000);
console.info('animateTest_0500 END');
done();
});
it('animateTest_0600', 0, async function (done) {
console.info('animateTest_0500 START');
try {
let eventData = {
data: {
"duration":'2000'
}
}
let indexEventOne = {
eventId: 65,
priority: events_emitter.EventPriority.LOW
}
console.info("animateTest_0600 start to publish emit");
events_emitter.emit(indexEventOne, eventData);
} catch (err) {
console.log("animateTest_0600 change component data error: " + err.message);
}
let indexEvent = {
eventId: 60,
priority: events_emitter.EventPriority.LOW
}
let callback= (indexEvent) => {
console.info("animateTest_0600 get state result is: " + JSON.stringify(indexEvent))
except(indexEvent.data.duration).assertEqual('2000')
}
try {
events_emitter.on(indexEvent, callback);
} catch (err) {
console.info("animateTest_0600 on events_emitter err : " + JSON.stringify(err));
}
console.info("animateTest_0600 click result is: " + JSON.stringify(sendEventByKey('button1',10 ,"")));
await Utils.sleep(2000);
console.info('animateTest_0600 END');
done();
});
it('animateTest_0700', 0, async function (done) {
console.info('animateTest_0700 START');
......
// @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.emitter';
import Utils from './Utils';
export default function canvasJsunit() {
describe('canvasTest', function () {
beforeEach(async function (done) {
console.info("canvas beforeEach start");
let options = {
uri: 'pages/canvas2',
}
try {
router.clear();
let pages = router.getState();
console.info("get canvas2 state pages:" + JSON.stringify(pages));
if (!("canvas2" == pages.name)) {
console.info("get canvas2 state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push canvas2 page result:" + JSON.stringify(result));
}
} catch (err) {
console.error("push canvas page error:" + JSON.stringify(result));
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("canvas2 after each called");
});
it('testCanvas01', 0, async function (done) {
console.info('[testCanvas01] START');
await Utils.sleep(1000);
console.info('[testCanvas01]----------- START');
console.info('testCanvas01 END');
done();
});
});
}
......@@ -50,10 +50,6 @@ export default function canvasJsunit() {
console.info('[testCanvas01] START');
await Utils.sleep(1000);
console.info('[testCanvas01]----------- START');
let strJson = getInspectorByKey('canvas1');
let obj = JSON.parse(strJson);
console.info("[testCanvas01] obj is: " + JSON.stringify(obj));
console.info('testCanvas01 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 columnJsunit() {
describe('appInfoTest', 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:" + JSON.stringify(result));
}
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('column');
let obj = JSON.parse(strJson);
console.info("[testColumn01] obj is: " + JSON.stringify(obj));
console.info('[testColumn01] 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"
export default function commonJsunit() {
describe('commonTest', function () {
it('commonTest_0100', 0, async function (done) {
console.info('commonTest_0100 START');
var a = 90;
var b = vp2px(a);
console.info('commonTest_0100 vp2px result:' + b);
expect(b == 90).assertTrue();
console.info('commonTest_0100 END');
done();
});
it('commonTest_0200', 0, async function (done) {
console.info('commonTest_0200 START');
var a = -90;
var b = vp2px(a);
console.info('commonTest_0200 vp2px result:' + b);
expect(b == -90).assertTrue();
console.info('commonTest_0200 END');
done();
});
it('commonTest_0300', 0, async function (done) {
console.info('commonTest_0300 START');
var a = '30';
var b = vp2px(a);
console.info('commonTest_0300 vp2px result:' + b);
expect(b == undefined).assertTrue();
console.info('commonTest_0300 END');
done();
});
it('commonTest_0400', 0, async function (done) {
console.info('commonTest_0400 START');
var a = 80;
var b = px2vp(a);
console.info('commonTest_0400 px2vp result:' + b);
expect(b == 80).assertTrue();
console.info('commonTest_0400 END');
done();
});
it('commonTest_0500', 0, async function (done) {
console.info('commonTest_0500 START');
var a = -800000000;
var b = px2vp(a);
console.info('commonTest_0500 px2vp result:' + b);
expect(b == -800000000).assertTrue();
console.info('commonTest_0500 END');
done();
});
it('commonTest_0600', 0, async function (done) {
console.info('commonTest_0600 START');
var a = '80';
var b = px2vp(a);
console.info('commonTest_0600 px2vp result:' + b);
expect(b == undefined).assertTrue();
console.info('commonTest_0600 END');
done();
});
it('commonTest_0700', 0, async function (done) {
console.info('commonTest_0700 START');
var a = 70;
var b = fp2px(a);
console.info('commonTest_0700 fp2px result:' + b);
expect(b == 70).assertTrue();
console.info('commonTest_0700 END');
done();
});
it('commonTest_0800', 0, async function (done) {
console.info('commonTest_0800 START');
var a = -7000000000000;
var b = fp2px(a);
console.info('commonTest_0800 fp2px result:' + b);
expect(b == -2147483648).assertTrue();
console.info('commonTest_0800 END');
done();
});
it('commonTest_0900', 0, async function (done) {
console.info('commonTest_0900 START');
var a = '70';
var b = fp2px(a);
console.info('commonTest_0900 fp2px result:' + b);
expect(b == undefined).assertTrue();
console.info('commonTest_0900 END');
done();
});
it('commonTest_1000', 0, async function (done) {
console.info('commonTest_1000 START');
var a = 60;
var b = px2fp(a);
console.info('commonTest_1000 px2fp result:' + b);
expect(b == 60).assertTrue();
console.info('commonTest_1000 END');
done();
});
it('commonTest_1100', 0, async function (done) {
console.info('commonTest_1100 START');
var a = -6000000000;
var b = px2fp(a);
console.info('commonTest_1100 px2fp result:' + b);
expect(b == -6000000000).assertTrue();
console.info('commonTest_1100 END');
done();
});
it('commonTest_1200', 0, async function (done) {
console.info('commonTest_1200 START');
var a = '60';
var b = px2fp(a);
console.info('commonTest_1200 px2fp result:' + b);
expect(b == undefined).assertTrue();
console.info('commonTest_1200 END');
done();
});
it('commonTest_1300', 0, async function (done) {
console.info('commonTest_1300 START');
var a = 50;
var b = lpx2px(a);
console.info('commonTest_1300 lpx2px result:' + b);
expect(b == 33).assertTrue();
console.info('commonTest_1300 END');
done();
});
it('commonTest_1400', 0, async function (done) {
console.info('commonTest_1400 START');
var a = -500000000;
var b = lpx2px(a);
console.info('commonTest_1400 lpx2px result:' + b);
expect(b == -333333343).assertTrue();
console.info('commonTest_1400 END');
done();
});
it('commonTest_1500', 0, async function (done) {
console.info('commonTest_1500 START');
var a = '50';
var b = lpx2px(a);
console.info('commonTest_1500 lpx2px result:' + b);
expect(b == undefined).assertTrue();
console.info('commonTest_1500 END');
done();
});
it('commonTest_1600', 0, async function (done) {
console.info('commonTest_1600 START');
var a = 40;
var b = px2lpx(a);
console.info('commonTest_1600 px2lpx result:' + b);
expect(b == 59.99999821186071).assertTrue();
console.info('commonTest_1600 END');
done();
});
it('commonTest_1700', 0, async function (done) {
console.info('commonTest_1700 START');
var a = -400000;
var b = px2lpx(a);
console.info('commonTest_1700 px2lpx result:' + b);
expect(b == -599999.9821186071).assertTrue();
console.info('commonTest_1700 END');
done();
});
it('commonTest_1800', 0, async function (done) {
console.info('commonTest_1800 START');
var a = '40';
var b = px2lpx(a);
console.info('commonTest_1800 px2lpx result:' + b);
expect(b == undefined).assertTrue();
console.info('commonTest_1800 END');
done();
});
})
}
\ No newline at end of file
......@@ -65,10 +65,7 @@ export default function gaugeJsunit() {
try {
var eventData = {
data: {
"gaugeValue": "10",
"strokeWidthValue": "30",
"startAngleValue": "200",
"endAngleValue": "200"
"gaugeValue": "10"
}
}
var innerEvent = {
......@@ -84,8 +81,7 @@ export default function gaugeJsunit() {
let strJsonNew = getInspectorByKey('gauge');
let objNew = JSON.parse(strJsonNew);
console.info("[testGauge002] component objNew is: " + JSON.stringify(objNew));
expect(objNew.$attrs.strokeWidth).assertEqual('30.000000vp');
expect(objNew.$attrs.value).assertEqual('10.00');
expect(objNew.$attrs.gauge).assertEqual('10.00');
done();
});
......@@ -95,11 +91,11 @@ export default function gaugeJsunit() {
try {
var eventData = {
data: {
"colorValues": JSON.stringify([[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1]])
"strokeWidthValue": "30",
}
}
var innerEvent = {
eventId: 2,
eventId: 1,
priority: events_emitter.EventPriority.LOW
}
console.info("[testGauge003] start to publish emit");
......@@ -107,6 +103,84 @@ export default function gaugeJsunit() {
} catch (err) {
console.log("[testGauge003] change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJsonNew = getInspectorByKey('gauge');
let objNew = JSON.parse(strJsonNew);
console.info("[testGauge003] component objNew is: " + JSON.stringify(objNew));
expect(objNew.$attrs.strokeWidth).assertEqual('30.000000vp');
done();
});
it('testGauge004', 0, async function (done) {
console.info('[testGauge004] START');
await Utils.sleep(1000);
try {
var eventData = {
data: {
"startAngleValue": "200"
}
}
var innerEvent = {
eventId: 1,
priority: events_emitter.EventPriority.LOW
}
console.info("[testGauge004] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testGauge004] change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJsonNew = getInspectorByKey('gauge');
let objNew = JSON.parse(strJsonNew);
console.info("[testGauge004] component objNew is: " + JSON.stringify(objNew));
expect(objNew.$attrs.startAngle).assertEqual('200.00');
done();
});
it('testGauge005', 0, async function (done) {
console.info('[testGauge005] START');
await Utils.sleep(1000);
try {
var eventData = {
data: {
"endAngleValue": "200"
}
}
var innerEvent = {
eventId: 1,
priority: events_emitter.EventPriority.LOW
}
console.info("[testGauge005] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testGauge005] change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJsonNew = getInspectorByKey('gauge');
let objNew = JSON.parse(strJsonNew);
console.info("[testGauge005] component objNew is: " + JSON.stringify(objNew));
expect(objNew.$attrs.endAngle).assertEqual('200.00');
done();
});
it('testGauge006', 0, async function (done) {
console.info('[testGauge006] START');
await Utils.sleep(1000);
try {
var eventData = {
data: {
"colorValues": JSON.stringify([[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1]])
}
}
var innerEvent = {
eventId: 2,
priority: events_emitter.EventPriority.LOW
}
console.info("[testGauge006] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testGauge006] change component data error: " + err.message);
}
done();
});
})
......
// @ts-nocheck
/**
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
......@@ -56,6 +55,16 @@ import qrCodeJsunit from './QrCodeJsunit.test.ets';
import tapGesture from './TapGesture.test.ets';
import progressJsunit from './ProgressJsunit.test.ets';
import animateJsunit from './AnimateJsunit.test.ets';
import commonJsunit from './CommonJsunit.test.ets';
import spanJsunit from './SpanJsunit.test.ets';
import columnJsunit from './ColumnJsunit.test.ets';
import ratingJsunit from './RatingJsunit.test.ets';
import canvas2Jsunit from './Canvas2Jsunit.test.ets';
import toggleJsunit from './ToggleJsunit.test.ets';
import shapeJsunit from './ShapeJsunit.test.ets'
import motionPathJsunit from './MotionPathJsunit.test.ets';
import scrollCodeJsunit from './ScrollCodeJsunit.test.ets';
export default function testsuite() {
gaugeJsunit();
......@@ -92,6 +101,7 @@ export default function testsuite() {
textJsunit();
badgeJsunit();
canvasJsunit();
canvas2Jsunit();
longPressGestureJsUnit();
buttonJsunit();
responseRegionJsunit();
......@@ -101,4 +111,12 @@ export default function testsuite() {
tapGesture();
progressJsunit();
animateJsunit();
commonJsunit();
spanJsunit();
ratingJsunit();
toggleJsunit();
shapeJsunit();
motionPathJsunit();
columnJsunit();
scrollCodeJsunit();
}
\ No newline at end of file
......@@ -69,10 +69,7 @@ export default function listJsunit() {
try {
var eventData = {
data: {
"listDirection": Axis.Horizontal,
"editMode": true,
"edgeEffect": EdgeEffect.Spring,
"chainAnimation": true
"listDirection": Axis.Horizontal
}
}
var innerEvent = {
......@@ -89,9 +86,6 @@ export default function listJsunit() {
let obj = JSON.parse(strJson);
console.info("[testList02] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.listDirection).assertEqual('Axis.Horizontal');
expect(obj.$attrs.editMode).assertEqual('true');
expect(obj.$attrs.edgeEffect).assertEqual('EdgeEffect.Spring');
expect(obj.$attrs.chainAnimation).assertEqual('true');
console.info('testList02 END');
done();
});
......@@ -101,14 +95,11 @@ export default function listJsunit() {
try {
var eventData = {
data: {
"strokeWidth": "3.000000vp",
"color": "#FF0000FF",
"startMargin": "30.000000vp",
"endMargin": "30.000000vp"
"editMode": true
}
}
var innerEvent = {
eventId: 81,
eventId: 80,
priority: events_emitter.EventPriority.LOW
}
console.info("[testList03] start to publish emit:" + JSON.stringify(eventData.data));
......@@ -116,15 +107,168 @@ export default function listJsunit() {
} catch (err) {
console.log("[testList03] change component data error: " + err.message);
}
await Utils.sleep(1000);
await Utils.sleep(4000);
let strJson = getInspectorByKey('list');
let obj = JSON.parse(strJson);
console.info("[testList03] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.editMode).assertEqual('true');
console.info('testList03 END');
done();
});
it('testList04', 0, async function (done) {
console.info('[testList04] START');
try {
var eventData = {
data: {
"edgeEffect": EdgeEffect.Spring
}
}
var innerEvent = {
eventId: 80,
priority: events_emitter.EventPriority.LOW
}
console.info("[testList04] start to publish emit:" + JSON.stringify(eventData.data));
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testList04] change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJson = getInspectorByKey('list');
let obj = JSON.parse(strJson);
console.info("[testList04] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.edgeEffect).assertEqual('EdgeEffect.Spring');
console.info('testList04 END');
done();
});
it('testList05', 0, async function (done) {
console.info('[testList05] START');
try {
var eventData = {
data: {
"chainAnimation": true
}
}
var innerEvent = {
eventId: 80,
priority: events_emitter.EventPriority.LOW
}
console.info("[testList05] start to publish emit:" + JSON.stringify(eventData.data));
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testList05] change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJson = getInspectorByKey('list');
let obj = JSON.parse(strJson);
console.info("[testList05] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.chainAnimation).assertEqual('true');
console.info('testList05 END');
done();
});
it('testList06', 0, async function (done) {
console.info('[testList06] START');
try {
var eventData = {
data: {
"strokeWidth": "3.000000vp"
}
}
var innerEvent = {
eventId: 81,
priority: events_emitter.EventPriority.LOW
}
console.info("[testList06] start to publish emit:" + JSON.stringify(eventData.data));
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testList06] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('list');
let obj = JSON.parse(strJson);
console.info("[testList06] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.divider.strokeWidth).assertEqual("3.000000vp");
console.info('testList06 END');
done();
});
it('testList07', 0, async function (done) {
console.info('[testList07] START');
try {
var eventData = {
data: {
"color": "#FF0000FF"
}
}
var innerEvent = {
eventId: 81,
priority: events_emitter.EventPriority.LOW
}
console.info("[testList07] start to publish emit:" + JSON.stringify(eventData.data));
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testList07] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('list');
let obj = JSON.parse(strJson);
console.info("[testList07] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.divider.color).assertEqual("#FF0000FF");
console.info('testList07 END');
done();
});
it('testList08', 0, async function (done) {
console.info('[testList08] START');
try {
var eventData = {
data: {
"startMargin": "30.000000vp"
}
}
var innerEvent = {
eventId: 81,
priority: events_emitter.EventPriority.LOW
}
console.info("[testList08] start to publish emit:" + JSON.stringify(eventData.data));
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testList08] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('list');
let obj = JSON.parse(strJson);
console.info("[testList08] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.divider.startMargin).assertEqual("30.000000vp");
console.info('testList08 END');
done();
});
it('testList09', 0, async function (done) {
console.info('[testList09] START');
try {
var eventData = {
data: {
"endMargin": "30.000000vp"
}
}
var innerEvent = {
eventId: 81,
priority: events_emitter.EventPriority.LOW
}
console.info("[testList09] start to publish emit:" + JSON.stringify(eventData.data));
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testList09] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('list');
let obj = JSON.parse(strJson);
console.info("[testList09] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.divider.endMargin).assertEqual("30.000000vp");
console.info('testList03 END');
console.info('testList09 END');
done();
});
})
......
// @ts-nocheck
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets"
import router from '@system.router';
import Utils from './Utils';
import events_emitter from '@ohos.events.emitter';
export default function motionPathJsunit() {
describe('motionPathTest', function () {
beforeEach(async function (done) {
let options = {
uri: 'pages/motionPath',
}
try {
router.clear();
let pages = router.getState();
console.info("get motionPath state success " + JSON.stringify(pages));
if (!("motionPath" == pages.name)) {
console.info("get motionPath state success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(1000);
console.info("push motionPath page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push motionPath page error " + JSON.stringify(result));
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("motionPath after each called");
});
it('motionPathTest_0100', 0, async function (done) {
console.info('motionPathTest_0100 START');
let strJson = getInspectorByKey('motionPath');
console.info("motionPathTest_0100 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("motionPathTest_0100 component obj is: " + JSON.stringify(obj));
expect(obj.$type).assertEqual('Column');
done();
});
it('motionPathTest_0200', 0, async function (done) {
console.info('motionPathTest_0200 START');
let callback = (indexEventOne) => {
console.info("motionPathTest_0200 get state result is: " + JSON.stringify(indexEventOne));
expect(indexEventOne.data.fromX).assertEqual(0);
expect(indexEventOne.data.toY).assertEqual(1);
}
let indexEventOne = {
eventId: 3,
priority: events_emitter.EventPriority.LOW
}
try {
events_emitter.on(indexEventOne, callback);
} catch (err) {
console.info("motionPathTest_0200 on events_emitter err : " + JSON.stringify(err));
}
console.info("motionPathTest_0200 click result is: " + JSON.stringify(sendEventByKey('button1',10,"")));
await Utils.sleep(1000);
console.info('motionPathTest_0200 END');
done();
});
it('motionPathTest_0300', 0, async function (done) {
console.info('motionPathTest_0300 START');
await Utils.sleep(1500);
let callback = (indexEvent) => {
console.info("motionPathTest_0300 get state result is: " + JSON.stringify(indexEvent));
expect(indexEvent.data.ACTION).assertEqual(true);
}
let indexEvent = {
eventId: 2,
priority: events_emitter.EventPriority.LOW
}
try {
events_emitter.on(indexEvent, callback);
} catch (err) {
console.info("motionPathTest_0300 on events_emitter err : " + JSON.stringify(err));
}
console.info("motionPathTest_0300 click result is: " + JSON.stringify(sendEventByKey('button',10,"")));
await Utils.sleep(1000);
console.info('motionPathTest_0300 END');
done();
});
})
}
/**
* 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 Utils from './Utils';
import events_emitter from '@ohos.events.emitter';
export default function ratingJsunit() {
describe('ratingTest', function () {
beforeEach(async function (done) {
let options = {
uri: 'pages/rating',
}
try {
router.clear();
let pages = router.getState();
console.info("get rating state success " + JSON.stringify(pages));
if (!("rating" == pages.name)) {
console.info("get rating state success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(4000);
console.info("push rating page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push rating page error " + JSON.stringify(err));
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("rating after each called");
});
it('testRating_100', 0, async function (done) {
console.info('testRating_100 START');
await Utils.sleep(1000);
try {
let eventData = {
data: {
"rating": 2
}
}
var innerEvent = {
eventId: 440,
priority: events_emitter.EventPriority.LOW
}
console.info("testRating_100 start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("testRating_100 change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJson = getInspectorByKey('Rating');
let obj = JSON.parse(strJson);
console.info("testRating_100 component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.rating).assertEqual("2.000000");
console.info('testRating_100 END');
done();
});
it('testRating_200', 0, async function (done) {
console.info('[testRating_200] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('Rating');
let obj = JSON.parse(strJson);
console.info("testRating_200 component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.stepSize).assertEqual("0.500000");
console.info('testRating_200 END');
done();
});
it('testRating_300', 0, async function (done) {
console.info('testRating_300 START');
await Utils.sleep(1000);
try {
var eventData = {
data: {
"rating": 3
}
}
var innerEvent = {
eventId: 441,
priority: events_emitter.EventPriority.LOW
}
console.info("testRating_300 start to publish emit");
console.info("eventData.data.rating value" + eventData.data.rating);
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("testRating_300 change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJson = getInspectorByKey('Rating');
let obj = JSON.parse(strJson);
console.info("testRating_300 component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.rating).assertEqual("3.000000");
console.info('testRating_300 END');
done();
});
it('testRating_400', 0, async function (done) {
console.info('testRating_400 START');
await Utils.sleep(1000);
try {
let eventData = {
data: {
"rating": 4
}
}
var innerEvent = {
eventId: 442,
priority: events_emitter.EventPriority.LOW
}
console.info("testRating_400 start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("testRating_400 change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJson = getInspectorByKey('Rating');
let obj = JSON.parse(strJson);
console.info("testRating_400 component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.rating).assertEqual("4.000000");
console.info('testRating_400 END');
done();
});
it('testRating_500', 0, async function (done) {
console.info('testRating_500 START');
await Utils.sleep(1000);
try {
let eventData = {
data: {
"rating": 5
}
}
var innerEvent = {
eventId: 443,
priority: events_emitter.EventPriority.LOW
}
console.info("testRating_500 start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("testRating_500 change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJson = getInspectorByKey('Rating');
let obj = JSON.parse(strJson);
console.info("testRating_500 component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.rating).assertEqual("5.000000");
console.info('testRating_500 END');
done();
});
it('testRating_600', 0, async function (done) {
console.info('testRating_600 START');
await Utils.sleep(1000);
try {
let eventData = {
data: {
"rating": 0
}
}
var innerEvent = {
eventId: 444,
priority: events_emitter.EventPriority.LOW
}
console.info("testRating_600 start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("testRating_600 change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJson = getInspectorByKey('Rating');
let obj = JSON.parse(strJson);
console.info("testRating_600 component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.rating).assertEqual("0.000000");
console.info('testRating_600 END');
done();
});
it('testRating_700', 0, async function (done) {
console.info('testRating_700 START');
await Utils.sleep(1000);
try {
let eventData = {
data: {
"rating": 1
}
}
var innerEvent = {
eventId: 445,
priority: events_emitter.EventPriority.LOW
}
console.info("testRating_700 start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("testRating_700 change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJson = getInspectorByKey('Rating');
let obj = JSON.parse(strJson);
console.info("testRating_700 component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.rating).assertEqual("1.000000");
console.info('testRating_700 END');
done();
});
})
}
\ 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 scrollCodeJsunit() {
describe('appInfoTest', function () {
beforeEach(async function (done) {
let options = {
uri: 'pages/scrollCode',
}
try {
router.clear();
let pages = router.getState();
console.info("get ScrollCode state success " + JSON.stringify(pages));
if (!("ScrollCode" == pages.name)) {
console.info("get ScrollCode pages success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push ScrollCode page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push ScrollCode page error " + JSON.stringify(err));
}
done()
});
afterEach(async function () {
await Utils.sleep(2000);
console.info("ScrollCode after each called");
});
it('test_scrollCode_001', 0, async function (done) {
console.info('[test_scrollCode_001] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('ScrollCode');
let obj = JSON.parse(strJson);
console.info("[test_scrollCode_001] component obj is: " + JSON.stringify(obj));
await Utils.sleep(1000);
expect(obj.$attrs.scrollable).assertEqual('ScrollDirection.Vertical');
expect(obj.$attrs.scrollBar).assertEqual('BarState.On');
expect(obj.$attrs.scrollBarColor).assertEqual('#FF0000FF');
expect(obj.$attrs.scrollBarWidth).assertEqual('30.000000px');
done();
});
it('test_scrollCode_002', 0, async function (done) {
console.info('[test_scrollCode_002] START');
await Utils.sleep(1000);
try {
var eventData = {
data: {
"scrollable": "ScrollDirection.Vertical"
}
}
var innerEvent = {
eventId: 90,
priority: events_emitter.EventPriority.LOW
}
console.info("[test_scrollCode_002] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[test_scrollCode_002] change scrollable error: " + err.message);
}
await Utils.sleep(2000);
let strJson = getInspectorByKey('ScrollCode');
let obj = JSON.parse(strJson);
console.info("[test_scrollCode_002] component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.scrollable).assertEqual('ScrollDirection.Vertical');
done();
});
it('test_scrollCode_003', 0, async function (done) {
console.info('[test_scrollCode_003] START');
await Utils.sleep(1000);
try {
var eventData = {
data: {
"scrollBar": "BarState.Off"
}
}
var innerEvent = {
eventId: 80,
priority: events_emitter.EventPriority.LOW
}
console.info("[test_scrollCode_003] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[test_scrollCode_003] change scrollBar error: " + err.message);
}
await Utils.sleep(2000);
let strJson = getInspectorByKey('ScrollCode');
let obj = JSON.parse(strJson);
console.info("[test_scrollCode_003] component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.scrollBar).assertEqual('BarState.Off');
done();
});
it('test_scrollCode_004', 0, async function (done) {
console.info('[test_scrollCode_004] START');
await Utils.sleep(1000);
try {
var eventData = {
data: {
"scrollBarColor": "#FFB6C1"
}
}
var innerEvent = {
eventId: 85,
priority: events_emitter.EventPriority.LOW
}
console.info("[test_scrollCode_004] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[test_scrollCode_004] change scrollBar error: " + err.message);
}
await Utils.sleep(2000);
let strJson = getInspectorByKey('ScrollCode');
let obj = JSON.parse(strJson);
console.info("[test_scrollCode_004] component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.scrollBarColor).assertEqual('#FFFFB6C1');
done();
});
it('test_scrollCode_005', 0, async function (done) {
console.info('[test_scrollCode_005] START');
await Utils.sleep(1000);
try {
var eventData = {
data: {
"scrollBarWidth": 40
}
}
var innerEvent = {
eventId: 95,
priority: events_emitter.EventPriority.LOW
}
console.info("[test_scrollCode_005] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[test_scrollCode_005] change scrollBar error: " + err.message);
}
await Utils.sleep(2000);
let strJson = getInspectorByKey('ScrollCode');
let obj = JSON.parse(strJson);
console.info("[test_scrollCode_005] component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.scrollBarWidth).assertEqual('40.000000px');
done();
});
})
}
\ 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 spanJsunit() {
describe('appInfoTest', function () {
beforeEach(async function (done) {
let options = {
uri: 'pages/span',
}
try {
router.clear();
let pages = router.getState();
console.info("get span state success " + JSON.stringify(pages));
if (!("span" == pages.name)) {
console.info("get span success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push span page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push span page error " + JSON.stringify(err));
}
done()
});
afterEach(async function () {
await Utils.sleep(2000);
console.info("span after each called");
});
it('testSpan001', 0, async function (done) {
console.info('[testSpan001] START');
await Utils.sleep(2000);
let strJson = getInspectorByKey('decoration');
console.info("[testSpan001] component strJson:" + strJson);
let obj = JSON.parse(strJson);
let decoration = JSON.parse(obj.$attrs.decoration);
expect(decoration.type).assertEqual('TextDecorationType.None');
expect(decoration.color).assertEqual('#FFFF0000');
done();
});
it('testSpan002', 0, async function (done) {
console.info('[testSpan002] START');
await Utils.sleep(2000);
let strJson = getInspectorByKey('decoration');
console.info("[testSpan002] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testSpan002] textCase:" + obj.$attrs.textCase);
expect(obj.$attrs.textCase).assertEqual('TextCase.Normal');
done();
});
it('testSpan003', 0, async function (done) {
console.info('[testSpan003] START');
try {
let eventData = {
data: {
"textCaseValue": TextCase.UpperCase
}
}
let indexEvent = {
eventId: 41,
priority: events_emitter.EventPriority.LOW
}
console.info("[testSpan003] start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("[testSpan003] change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJson = getInspectorByKey('decoration');
console.info("[testSpan003] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testSpan003] textCase:" + obj.$attrs.textCase);
expect(obj.$attrs.textCase).assertEqual('TextCase.UpperCase');
done();
});
})
}
\ No newline at end of file
......@@ -60,6 +60,57 @@ export default function textJsunit() {
it('testText_0200', 0, async function (done) {
console.info('testText_0200 START');
let strJson = getInspectorByKey('text1');
console.info("testText_0200 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("testText_0200 component obj is: " + JSON.stringify(obj));
expect(obj.$type).assertEqual('Text');
expect(obj.$attrs.fontSize).assertEqual('28.000000px');
console.info('testText_0200 END');
done();
});
it('testText_0300', 0, async function (done) {
console.info('testText_0300 START');
let strJson = getInspectorByKey('text1');
console.info("testText_0300 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("testText_0300 component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.content).assertEqual('Hello');
console.info('testText_0300 END');
done();
});
it('testText_0400', 0, async function (done) {
console.info('testText_0400 START');
let strJson = getInspectorByKey('text1');
console.info("testText_0400 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("testText_0400 component obj is: " + JSON.stringify(obj));
expect(obj.$type).assertEqual('Text');
expect(obj.$attrs.fontColor).assertEqual('#FFFF0000');
console.info('testText_0400 END');
done();
});
it('testText_0500', 0, async function (done) {
console.info('testText_0500 START');
let strJson = getInspectorByKey('image');
console.info("testText_0500 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("testText_0500 component obj is: " + JSON.stringify(obj));
var res = obj.$attrs.src.indexOf('rawfile/test.png');
console.info("testText_0500 result is: " + res);
var sres = obj.$attrs.src.slice(res,res + 16);
console.info("testText_0500 slice result is: " + sres);
expect(obj.$type).assertEqual('Image');
expect(obj.$attrs.src.slice(res,res + 16)).assertEqual('rawfile/test.png');
console.info('testText_0500 END');
done();
});
it('testText_0600', 0, async function (done) {
console.info('testText_0600 START');
try {
let eventData = {
data: {
......@@ -70,17 +121,17 @@ export default function textJsunit() {
eventId: 60,
priority: events_emitter.EventPriority.LOW
}
console.info("testText_0200 start to publish emit");
console.info("testText_0600 start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("testText_0200 change component data error: " + err.message);
console.log("testText_0600 change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJsonNew = getInspectorByKey('text');
let objNew = JSON.parse(strJsonNew);
console.info("testText_0200 component objNew is: " + JSON.stringify(objNew));
console.info("testText_0600 component objNew is: " + JSON.stringify(objNew));
expect(objNew.$attrs.fontSize).assertEqual('10.000000fp');
console.info('testText_0200 END');
console.info('testText_0600 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 ToggleJsunit() {
describe('appInfoTest', function () {
beforeEach(async function (done) {
console.info("toggle beforeEach start");
let options = {
uri: 'pages/toggle',
}
try {
router.clear();
let pages = router.getState();
console.info("get toggle state pages:" + JSON.stringify(pages));
if (!("toggle" == pages.name)) {
console.info("get toggle state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push toggle page result:" + JSON.stringify(result));
}
} catch (err) {
console.error("push toggle page error:" + JSON.stringify(result));
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("toggle after each called");
});
it('testToggle01', 0, async function (done) {
console.info('[testToggle01] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('toggle');
let obj = JSON.parse(strJson);
console.info("[testToggle01] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.selectedColor).assertEqual('#330A59F7');
console.info('[testToggle01] END');
done();
});
it('testToggle02', 0, async function (done) {
console.info('[testToggle02] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('toggle');
let obj = JSON.parse(strJson);
console.info("[testToggle02] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.type).assertEqual('ToggleType.Button');
console.info('[testToggle02] END');
done();
});
it('testToggle03', 0, async function (done) {
console.info('[testToggle03] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('toggle');
let obj = JSON.parse(strJson);
console.info("[testToggle03] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.isOn).assertEqual('false');
console.info('[testToggle03] END');
done();
});
it('testToggle04', 0, async function (done) {
console.info('testToggle04 START');
try {
let eventData = {
data: {
"isOn": true,
}
}
let indexEvent = {
eventId: 1011,
priority: events_emitter.EventPriority.LOW
}
console.info("testToggle04 start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("testToggle04 change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJsonNew = getInspectorByKey('toggle');
let objNew = JSON.parse(strJsonNew);
console.info("testToggle04 component objNew is: " + JSON.stringify(objNew));
expect(objNew.$attrs.isOn).assertEqual('true');
console.info('testToggle04 END');
done();
});
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册