提交 22cf64c8 编写于 作者: Z zhangrao

add swiper

Signed-off-by: Nzhangrao <zhangrao@huawei.com>
上级 9e4101ba
# 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
# 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.
group("ace") {
testonly = true
deps = [
"ace_ets_standard:ActsAceEtsStTest",
"ace_ets_test:ActsAceEtsTest",
"ace_ets_third_test:ActsAceEtsThirdTest",
"ace_standard:ace_standard_test",
]
}
group("ace") {
testonly = true
deps = [
"ace_ets_component:AceEtsComponentTest",
"ace_ets_standard:ActsAceEtsStTest",
"ace_ets_test:ActsAceEtsTest",
"ace_ets_third_test:ActsAceEtsThirdTest",
"ace_standard:ace_standard_test",
"ace_ets_component:AceEtsComponentTest",
]
}
# 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("AceEtsComponentTest") {
hap_profile = "./entry/src/main/config.json"
deps = [
":ace_ets_component_assets",
":ace_ets_component_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "AceEtsComponentTest"
}
ohos_js_assets("ace_ets_component_assets") {
source_dir = "./entry/src/main/ets/MainAbility"
}
ohos_resources("ace_ets_component_resources") {
sources = [ "./entry/src/main/resources" ]
hap_profile = "./entry/src/main/config.json"
}
{
"description": "Configuration for aceceshi Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "60000",
"package": "com.open.harmony.acetest",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"AceEtsComponentTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
{
"app": {
"bundleName": "com.open.harmony.acetest",
"vendor": "open",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 7,
"releaseType": "Release",
"target": 7
}
},
"deviceConfig": {},
"module": {
"package": "com.open.harmony.acetest",
"name": ".MyApplication",
"mainAbility": "com.open.harmony.acetest.MainAbility",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"visible": true,
"srcPath": "MainAbility",
"name": ".MainAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:description_mainability",
"formsEnabled": false,
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index",
"pages/ellipse",
"pages/systemRouterA",
"pages/systemRouterB"
],
"name": ".MainAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
\ 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.
*/
export default {
onCreate() {
console.info('Application onCreate')
},
onDestroy() {
console.info('Application onDestroy')
},
}
\ 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: 5,
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%')
}
}
\ 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 GridContainerExample {
@State sizeType: SizeType = SizeType.XS;
private stateChangCallBack = (eventData) => {
if (eventData != null) {
console.info("gridContainer page state change called:" + JSON.stringify(eventData));
switch (eventData.data.sizeType) {
case 'Auto':
this.sizeType = SizeType.Auto;
break;
case 'XS':
this.sizeType = SizeType.XS;
break;
case 'SM':
this.sizeType = SizeType.SM;
break;
case 'MD':
this.sizeType = SizeType.MD;
break;
case 'LG':
this.sizeType = SizeType.LG;
break;
default:
this.sizeType = SizeType.Auto;
}
}
}
onPageShow() {
console.info('gridContainer page show called');
var stateChangeEvent = {
eventId: 7,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
}
build() {
Column({ space: 5 }) {
GridContainer({ columns: 12, sizeType: this.sizeType, gutter: 10, margin: 20 }) {
Row() {
Text('1')
.fontSize(20)
.useSizeType({
xs: { span: 6, offset: 0 },
sm: { span: 2, offset: 0 },
md: { span: 2, offset: 0 },
lg: { span: 2, offset: 0 }
})
.height(50)
.backgroundColor(0x4582B4)
.textAlign(TextAlign.Center)
Text('2')
.fontSize(20)
.useSizeType({
xs: { span: 2, offset: 6 },
sm: { span: 6, offset: 2 },
md: { span: 2, offset: 2 },
lg: { span: 2, offset: 2 }
})
.height(50)
.backgroundColor(0x00BFFF)
.textAlign(TextAlign.Center)
Text('3')
.fontSize(20)
.useSizeType({
xs: { span: 2, offset: 8 },
sm: { span: 2, offset: 8 },
md: { span: 6, offset: 4 },
lg: { span: 2, offset: 4 }
})
.height(50)
.backgroundColor(0x4682B4)
.textAlign(TextAlign.Center)
Text('4')
.fontSize(20)
.useSizeType({
xs: { span: 2, offset: 10 },
sm: { span: 2, offset: 10 },
md: { span: 2, offset: 10 },
lg: { span: 6, offset: 6 }
})
.height(50)
.backgroundColor(0x00BFFF)
.textAlign(TextAlign.Center)
}
}.width('90%').key('gridContainer').margin({ top: 300 })
}
}
}
\ 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 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";
@Entry
@Component
struct MyComponent {
aboutToAppear() {
console.info("start run testcase!!!!")
featureAbility.getWant()
.then((Want) => {
const core = Core.getInstance();
const expectExtend = new ExpectExtend({
'id': 'extend'
});
core.addService('expect', expectExtend);
const reportExtend = new ReportExtend(file);
core.addService('report', reportExtend);
core.init();
core.subscribeEvent('task', reportExtend);
const configService = core.getDefaultService('config');
console.info('parameters---->' + JSON.stringify(Want.parameters));
configService.setConfig(Want.parameters);
testsuite();
core.execute();
console.info('Operation successful. Data: ' + JSON.stringify(Want));
})
.catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
}
build() {
Flex({
direction: FlexDirection.Column,
alignItems: ItemAlign.Center,
justifyContent: FlexAlign.Center
}) {
Text('ACE ETS TEST')
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.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'
class MyDataSource implements IDataSource {
private list: number[] = []
private listener: DataChangeListener
constructor(list: number[]) {
this.list = list
}
totalCount(): number {
return this.list.length
}
getData(index: number): any {
return this.list[index]
}
registerDataChangeListener(listener: DataChangeListener): void {
this.listener = listener
}
unregisterDataChangeListener() {
}
}
@Entry
@Component
struct SwiperExample {
private swiperController: SwiperController = new SwiperController()
private data: MyDataSource = new MyDataSource([])
@State index: number = 1
@State autoPlay: boolean = true
@State interval: number = 4000
@State indicator: boolean = true
@State loop: boolean = false
@State duration: number = 1000
@State vertical: boolean = false
@State itemSpace: number = 0
@State onActionCalledOne: boolean = false;
@State onActionCalledTwo: boolean = false;
@State onActionCalledThree: boolean = false;
private aboutToAppear(): void {
let list = []
for (var i = 1; i <= 10; i++) {
list.push(i.toString());
}
this.data = new MyDataSource(list)
}
build() {
Column({ space: 5 }) {
Swiper(this.swiperController) {
LazyForEach(this.data, (item: string) => {
Text(item)
.width('90%')
.height(160)
.backgroundColor(0xAFEEEE)
.textAlign(TextAlign.Center)
.fontSize(20)
}, item => item)
}
.cachedCount(2)
.index(this.index)
.autoPlay(this.autoPlay)
.interval(this.interval)
.indicator(this.indicator)
.loop(this.loop)
.duration(this.duration)
.vertical(this.vertical)
.itemSpace(this.itemSpace)
.key('swiper')
.onChange((index: number) => {
console.info(index.toString())
this.onActionCalledThree = true;
console.info('onChange current action state is: ' + this.onActionCalledThree);
try {
var backData = {
data: {
"ACTION": this.onActionCalledThree,
}
}
var backEvent = {
eventId: 20,
priority: events_emitter.EventPriority.LOW
}
console.info("onChange start to emit action state")
events_emitter.emit(backEvent, backData)
} catch (err) {
console.info("onChange emit action state err: " + JSON.stringify(err.message))
}
})
Flex({ justifyContent: FlexAlign.SpaceAround }) {
Button('next')
.key('button1')
.onClick(() => {
this.swiperController.showNext();
this.onActionCalledOne = true;
console.info('button1 current action state is: ' + this.onActionCalledOne);
try {
var backData = {
data: {
"ACTION": this.onActionCalledOne,
}
}
var backEvent = {
eventId: 18,
priority: events_emitter.EventPriority.LOW
}
console.info("button1 start to emit action state")
events_emitter.emit(backEvent, backData)
} catch (err) {
console.info("button1 emit action state err: " + JSON.stringify(err.message))
}
})
Button('preview')
.key('button2')
.onClick(() => {
this.swiperController.showPrevious()
this.onActionCalledTwo = true;
console.info('button2 current action state is: ' + this.onActionCalledTwo);
try {
var backData = {
data: {
"ACTION": this.onActionCalledTwo,
}
}
var backEvent = {
eventId: 19,
priority: events_emitter.EventPriority.LOW
}
console.info("button2 start to emit action state")
events_emitter.emit(backEvent, backData)
} catch (err) {
console.info("button2 emit action state err: " + JSON.stringify(err.message))
}
})
}
}.margin({ top: 5 })
}
onPageShow() {
console.info('swiper page show called');
var stateChangeEvent = {
eventId: 17,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack)
var stateChangeEventOne = {
eventId: 55,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEventOne, this.stateChangCallBack)
}
private stateChangCallBack = (eventData) => {
if (eventData != null) {
console.info("swiper page state change called:" + JSON.stringify(eventData));
if (eventData.data.index != null) {
this.index = parseInt(eventData.data.index);
}
if (eventData.data.autoPlay != null) {
this.autoPlay = eventData.data.autoPlay;
}
if (eventData.data.interval != null) {
this.interval = parseInt(eventData.data.interval);
}
if (eventData.data.indicator != null) {
this.indicator = eventData.data.indicator;
}
if (eventData.data.loop != null) {
this.loop = eventData.data.loop;
}
if (eventData.data.duration != null) {
this.duration = parseInt(eventData.data.duration);
}
if (eventData.data.vertical != null) {
this.vertical = eventData.data.vertical;
}
if (eventData.data.itemSpace != null) {
this.itemSpace = parseInt(eventData.data.itemSpace);
}
}
}
}
\ 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 router from '@system.router';
@Entry
@Component
struct SystemRouterA {
build() {
Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center}) {
Text('A Page')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button('Push')
.key('pushButtonA')
.backgroundColor('#FF0B8FE2')
.fontSize(20)
.margin({top: 20})
.onClick(() => {
router.push({
uri: 'pages/systemRouterB',
params: {
data: 'B Page'
}
});
});
Button('Replace')
.key('ReplaceButtonA')
.backgroundColor('#FF0B8FE2')
.fontSize(20)
.margin({top: 20})
.onClick(() => {
router.replace({
uri: 'pages/systemRouterB',
params: {
data: 'B Page'
}
});
});
}.width('100%').height('100%')
}
}
\ 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 router from '@system.router';
import events_emitter from '@ohos.emitter';
@Entry
@Component
struct SystemRouterB {
build() {
Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center}) {
Text('B Page')
.fontSize(50)
.fontWeight(FontWeight.Bold)
}.width('100%').height('100%')
}
onPageShow() {
let params = router.getParams();
if (params && params.data) {
console.info("[SystemRouterB] getParams result: " + params.data);
this.getRouterParams(params.data);
}
}
getRouterParams(data) {
try {
let paramsData = {
data: {
"params": data,
}
}
let paramsEvent = {
eventId: 3,
priority: events_emitter.EventPriority.LOW
}
console.info("[SystemRouterB] start to emit params");
events_emitter.emit(paramsEvent, paramsData);
} catch (err) {
console.info("[SystemRouterB] emit params err: " + JSON.stringify(err.message));
}
}
}
\ 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.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:" + JSON.stringify(result));
}
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.000000px');
expect(obj.$attrs.width).assertEqual('200.000000px');
console.info('testEllipse02 END');
done();
});
it('testEllipse02', 0, async function (done) {
console.info('[testEllipse02] START');
try {
var eventData = {
data: {
"width": '500px',
"height": '500px'
}
}
var innerEvent = {
eventId: 5,
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.height).assertEqual('500.000000px');
expect(obj.$attrs.width).assertEqual('500.000000px');
console.info('testEllipse02 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.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:" + JSON.stringify(result));
}
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.000000vp');
expect(obj.$attrs.constructor.margin).assertEqual('20.000000vp');
console.info('testGirdContainer01 END');
done();
});
it('testGirdContainer02', 0, async function (done) {
console.info('[testEllipse02] START');
try {
var eventData = {
data: {
"sizeType": 'SM'
}
}
var innerEvent = {
eventId: 7,
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();
});
})
}
/**
* 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 ellipseJsunit from './EllipseJsunit.test.ets';
import systemRouterJsunit from './SystemRouterJsunit.test.ets';
export default function testsuite() {
ellipseJsunit();
systemRouterJsunit();
}
\ 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.
*/
// @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.emitter';
export default function swiperJsunit() {
describe('swiperTest', function () {
beforeEach(async function (done) {
let options = {
uri: 'pages/swiper',
}
try {
router.clear();
let pages = router.getState();
console.info("get swiper state success " + JSON.stringify(pages));
if (!("stepper" == pages.name)) {
console.info("get swiper state success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(1000);
console.info("push swiper page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push swiper page error " + JSON.stringify(result));
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("swiper after each called");
});
it('swiperTest_0100', 0, async function (done) {
console.info('swiperTest_0100 START');
let strJson = getInspectorByKey('swiper');
console.info("swiperTest_0100 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("swiperTest_0100 component obj is: " + JSON.stringify(obj));
expect(obj.$type).assertEqual('Swiper');
expect(obj.$attrs.index).assertEqual('1');
expect(obj.$attrs.autoPlay).assertEqual('true');
expect(obj.$attrs.interval).assertEqual('4000');
expect(obj.$attrs.indicator).assertEqual('true');
expect(obj.$attrs.loop).assertEqual('false');
expect(obj.$attrs.duration).assertEqual('1000.000000');
expect(obj.$attrs.vertical).assertEqual('false');
expect(obj.$attrs.itemSpace).assertEqual('0.000000vp');
expect(obj.$attrs.disableSwipe).assertEqual('false');
console.info('swiperTest_0100 END');
done();
});
it('swiperTest_0200', 0, async function (done) {
console.info('swiperTest_0200 START');
try {
let eventData = {
data: {
"index": "3",
"autoPlay": "false",
"interval": "3000",
"indicator": "false",
"duration": "500",
"itemSpace": "1",
}
}
let indexEvent = {
eventId: 17,
priority: events_emitter.EventPriority.LOW
}
console.info("swiperTest_0200 start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("swiperTest_0200 change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJsonNew = getInspectorByKey('swiper');
let objNew = JSON.parse(strJsonNew);
console.info("swiperTest_0200 component objNew is: " + JSON.stringify(objNew));
expect(objNew.$attrs.index).assertEqual('3');
expect(objNew.$attrs.autoPlay).assertEqual('false');
expect(objNew.$attrs.interval).assertEqual('3000');
expect(objNew.$attrs.indicator).assertEqual('false');
expect(objNew.$attrs.duration).assertEqual('500.000000');
expect(objNew.$attrs.itemSpace).assertEqual('1.000000vp');
console.info('swiperTest_0200 END');
done();
});
it('swiperTest_0300', 0, async function (done) {
console.info('swiperTest_0300 START');
await Utils.sleep(1500);
let callback = (indexEvent) => {
console.info("swiperTest_0300 get state result is: " + JSON.stringify(indexEvent));
expect(indexEvent.data.ACTION).assertEqual(true);
}
let indexEvent = {
eventId: 18,
priority: events_emitter.EventPriority.LOW
}
try {
events_emitter.on(indexEvent, callback);
} catch (err) {
console.info("swiperTest_0300 on events_emitter err : " + JSON.stringify(err));
}
console.info("swiperTest_0300 click result is: " + JSON.stringify(sendEventByKey('button1',10,"")));
await Utils.sleep(1000);
console.info('swiperTest_0300 END');
done();
});
it('swiperTest_0400', 0, async function (done) {
console.info('swiperTest_0400 START');
await Utils.sleep(1500);
let callback = (indexEvent) => {
console.info("swiperTest_0400 get state result is: " + JSON.stringify(indexEvent));
expect(indexEvent.data.ACTION).assertEqual(true);
}
let indexEvent = {
eventId: 19,
priority: events_emitter.EventPriority.LOW
}
try {
events_emitter.on(indexEvent, callback);
} catch (err) {
console.info("swiperTest_0400 on events_emitter err : " + JSON.stringify(err));
}
console.info("swiperTest_0400 click result is: " + JSON.stringify(sendEventByKey('button2',10,"")));
await Utils.sleep(1000);
console.info('swiperTest_0400 END');
done();
});
it('swiperTest_0500', 0, async function (done) {
console.info('swiperTest_0500 START');
await Utils.sleep(1500);
let callbackOne = (indexEventOne) => {
console.info("swiperTest_0500 get state result is: " + JSON.stringify(indexEventOne));
expect(indexEventOne.data.ACTION).assertEqual(true);
}
let indexEventOne = {
eventId: 19,
priority: events_emitter.EventPriority.LOW
}
try {
events_emitter.on(indexEventOne, callbackOne);
} catch (err) {
console.info("swiperTest_0500 on events_emitter err : " + JSON.stringify(err));
}
console.info("swiperTest_0500 click result is: " + JSON.stringify(sendEventByKey('button2',10,"")));
await Utils.sleep(1500);
let callback = (indexEvent) => {
console.info("swiperTest_0500 get state result is: " + JSON.stringify(indexEvent));
expect(indexEvent.data.ACTION).assertEqual(true);
}
let indexEvent = {
eventId: 20,
priority: events_emitter.EventPriority.LOW
}
try {
events_emitter.on(indexEvent, callback);
} catch (err) {
console.info("swiperTest_0500 on events_emitter err : " + JSON.stringify(err));
}
console.info('swiperTest_0500 END');
done();
});
it('swiperTest_0600', 0, async function (done) {
console.info('swiperTest_0600 START');
try {
let eventData = {
data: {
"loop": true,
"vertical": true,
}
}
let indexEvent = {
eventId: 55,
priority: events_emitter.EventPriority.LOW
}
console.info("swiperTest_0600 start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("swiperTest_0600 change component data error: " + err.message);
}
await Utils.sleep(3000);
let strJsonNew = getInspectorByKey('swiper');
let objNew = JSON.parse(strJsonNew);
console.info("swiperTest_0600 component objNew is: " + JSON.stringify(objNew));
expect(objNew.$attrs.loop).assertEqual('true');
expect(objNew.$attrs.vertical).assertEqual('true');
console.info('swiperTest_0600 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 Utils from './Utils';
import events_emitter from '@ohos.emitter';
export default function systemRouterJsunit() {
describe('systemRouterTest', function () {
it('systemRouterTest001', 0, async function (done) {
console.info('[systemRouterTest001] START');
let options = {
uri: 'pages/systemRouterA',
}
try {
let result = await router.push(options);
await Utils.sleep(1000);
console.info("[systemRouterTest001] push page success " + JSON.stringify(result));
let pages = router.getState();
expect(pages.index).assertEqual(2);
expect(pages.name).assertEqual('systemRouterA');
expect(pages.path).assertEqual('pages/');
} catch (err) {
console.error("[systemRouterTest001] push page error " + JSON.stringify(result));
}
await Utils.sleep(2000);
done();
});
it('systemRouterTest002', 0, async function (done) {
console.info('[systemRouterTest002] START');
let options = {
uri: 'pages/systemRouterA'
}
try {
let result = await router.push(options);
console.info("[systemRouterTest002] push page success " + JSON.stringify(result));
} catch (err) {
console.error("[systemRouterTest002] push page error " + JSON.stringify(result));
}
await Utils.sleep(1500);
let callback = (paramsEvent) => {
console.info("[systemRouterTest002] get state result is: " + JSON.stringify(paramsEvent));
expect(paramsEvent.data.params).assertEqual('B Page');
}
let paramsEvent = {
eventId: 3,
priority: events_emitter.EventPriority.LOW
}
try {
events_emitter.on(paramsEvent, callback);
} catch (err) {
console.info("[systemRouterTest002] on events_emitter err : " + JSON.stringify(err));
}
console.info("[systemRouterTest002] click push button result is: "
+ JSON.stringify(sendEventByKey('pushButtonA', 10, "")));
await Utils.sleep(1000);
router.back();
await Utils.sleep(1000);
done();
});
it('systemRouterTest003', 0, async function (done) {
console.info('[systemRouterTest003] START');
await Utils.sleep(1000);
router.clear();
await Utils.sleep(2000);
let size = router.getLength();
console.info("[systemRouterTest003] size" + size);
expect(size).assertEqual("1");
await Utils.sleep(1000);
done();
});
it('systemRouterTest004', 0, async function (done) {
console.info('[systemRouterTest004] START');
router.clear();
await Utils.sleep(1000);
let options = {
uri: 'pages/systemRouterA'
}
try {
let result = await router.push(options);
console.info("[systemRouterTest004] push page success " + JSON.stringify(result));
} catch (err) {
console.error("[systemRouterTest004] push page error " + JSON.stringify(result));
}
await Utils.sleep(1000);
let optionsB = {
uri: 'pages/systemRouterB'
}
try {
let result = await router.replace(optionsB);
console.info("[systemRouterTest004] push page success " + JSON.stringify(result));
} catch (err) {
console.error("[systemRouterTest004] push page error " + JSON.stringify(result));
}
await Utils.sleep(1500);
let size = router.getLength();
console.info("[systemRouterTest004] size" + size);
expect(size).assertEqual("2");
done();
});
it('systemRouterTest005', 0, async function(done) {
console.info('[systemRouterTest005] START');
let options = {
uri: 'pages/systemRouterA'
}
try {
let result = await router.push(options);
console.info("[systemRouterTest005] push page success " + JSON.stringify(result));
} catch (err) {
console.error("[systemRouterTest005] push page error " + JSON.stringify(result));
}
await Utils.sleep(1000);
router.clear();
await Utils.sleep(1500);
let callback = (paramsEvent) => {
console.info("[systemRouterTest005] get state result is: " + JSON.stringify(paramsEvent));
expect(paramsEvent.data.params).assertEqual('B Page');
}
let paramsEvent = {
eventId: 3,
priority: events_emitter.EventPriority.LOW
}
try {
events_emitter.on(paramsEvent, callback);
} catch (err) {
console.info("[systemRouterTest005] on events_emitter err : " + JSON.stringify(err));
}
console.info("[systemRouterTest005] click replace button result is: "
+ JSON.stringify(sendEventByKey('ReplaceButtonA', 10, "")));
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.
*/
export default class Utils {
static rect_left;
static rect_top;
static rect_right;
static rect_bottom;
static rect_value;
static sleep(time) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, time)
}).then(() => {
console.info(`sleep ${time} over...`)
})
}
static getComponentRect(key) {
let strJson = getInspectorByKey(key);
let obj = JSON.parse(strJson);
console.info("[getInspectorByKey] current component obj is: " + JSON.stringify(obj));
let rectInfo = JSON.parse('[' + obj.$rect + ']')
console.info("[getInspectorByKey] rectInfo is: " + rectInfo);
this.rect_left = JSON.parse('[' + rectInfo[0] + ']')[0]
this.rect_top = JSON.parse('[' + rectInfo[0] + ']')[1]
this.rect_right = JSON.parse('[' + rectInfo[1] + ']')[0]
this.rect_bottom = JSON.parse('[' + rectInfo[1] + ']')[1]
return this.rect_value = {
"left": this.rect_left, "top": this.rect_top, "right": this.rect_right, "bottom": this.rect_bottom
}
}
static async swipe(downX, downY, upX, upY, steps) {
console.info('start to swipe')
this.drags(downX, downY, upX, upY, steps, false)
}
static async drag(downX, downY, upX, upY, steps) {
console.info('start to drag')
this.drags(downX, downY, upX, upY, steps, true)
}
static async drags(downX, downY, upX, upY, steps, drag) {
var xStep;
var yStep;
var swipeSteps;
var ret;
xStep = 0;
yStep = 0;
ret = false;
swipeSteps = steps;
if (swipeSteps == 0) {
swipeSteps = 1;
}
xStep = (upX - downX) / swipeSteps;
yStep = (upY - downY) / swipeSteps;
console.info('move step is: ' + 'xStep: ' + xStep + ' yStep: ' + yStep)
var downPonit: TouchObject = {
id: 1,
x: downX,
y: downY,
type: TouchType.Down,
}
console.info('down touch started: ' + JSON.stringify(downPonit))
sendTouchEvent(downPonit);
console.info('start to move')
if (drag) {
await this.sleep(500)
}
for (var i = 1;i <= swipeSteps; i++) {
var movePoint: TouchObject = {
id: 1,
x: downX + (xStep * i),
y: downY + (yStep * i),
type: TouchType.Move
}
console.info('move touch started: ' + JSON.stringify(movePoint))
ret = sendTouchEvent(movePoint)
if (ret == false) {
break;
}
await this.sleep(5)
}
console.info('start to up')
if (drag) {
await this.sleep(100)
}
var upPoint: TouchObject = {
id: 1,
x: upX,
y: upY,
type: TouchType.Up,
}
console.info('up touch started: ' + JSON.stringify(upPoint))
sendTouchEvent(upPoint)
await this.sleep(500)
}
}
/**
* 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.
*/
const TYPE = '$type'
const ID = '$ID'
const Z_INDEX = '$z-index'
const RECT = '$rect'
const DEBUGLINE = '$debugLine'
const ATTRS = '$attrs'
const ATTRS_SEPIA = 'sepia'
const ATTRS_ASPECTRATIO = 'aspectRatio'
const ATTRS_CONTRAST = 'contrast'
const ATTRS_SATURATE = 'saturate'
const ATTRS_HUEROTATE = 'hueRotate'
const ATTRS_INVERT = 'invert'
const ATTRS_BRIGHTNESS = 'brightness'
const ATTRS_BACKDROPBLUR = 'backdropBlur'
const ATTRS_GRAYSCALE = 'grayscale'
const ATTRS_BLUR = 'blur'
const ATTRS_GRIDOFFSET = 'gridOffset'
const ATTRS_FLEXSHRINK = 'flexShrink'
const ATTRS_FLEXGROW = 'flexGrow'
const ATTRS_OPACITY = 'opacity'
const ATTRS_DIRECTION = 'direction'
const ATTRS_ALIGN = 'align'
const ATTRS_HEIGHT = 'height'
const ATTRS_BACKGROUNDCOLOR = 'backgroundColor'
const ATTRS_ALIGNSELF = 'alignSelf'
const ATTRS_BORDERWIDTH = 'borderWidth'
const ATTRS_WIDTH = 'width'
const ATTRS_BORDERCOLOR = 'borderColor'
const ATTRS_MARGIN_BOTTOM = 'margin-bottom'
const ATTRS_BORDERSTYLE = 'borderStyle'
const ATTRS_MARGIN_RIGHT = 'margin-right'
const ATTRS_CONSTRAINTSIZE = 'constraintSize'
const ATTRS_NARGIN_LEFT = 'margin-left'
const ATTRS_BACKGROUNDIMAGE = 'backgroundImage'
const ATTRS_MARGIN_TOP = 'margin-top'
const ATTRS_BORDERRADIUS = 'borderRadius'
const ATTRS_FLEXBASIC = 'flexBasis'
const ATTRS_VISIBILITY = 'visibility'
const ATTRS_PASSWORD = 'password'
const ATTRS_CHECKED = 'checked'
const ATTRS_SELECTED = 'selected'
const ATTRS_LONG_CLICKABLE = 'long-clickable'
const ATTRS_FOCUSED = 'focused'
const ATTRS_SCROLLABLE = 'scrollable'
const ATTRS_CLICKABLE = 'clickable'
const ATTRS_FOCUSABLE = 'focusable'
const ATTRS_CHECKABLE = 'checkable'
const ATTRS_CLIP = 'clip'
const ATTRS_ENABLE = 'enabled'
const ATTRS_DISPLAYPRIORITY = 'displayPriority'
const ATTRS_LAYOUTWEIGHT = 'layoutWeight'
const ATTRS_LAYOUTPRIORITY = 'layoutPriority'
const ATTRS_GRIDSPAN = 'gridSpan'
const ATTRS_ZINDEX = 'zIndex'
const ATTRS_USEALIGN = 'useAlign'
const ATTRS_USEALIGN_EDGE = 'edge'
const ATTRS_USEALIGN_OFFSET = 'offset'
const ATTRS_MASK = 'mask'
const ATTRS_MARKANCHOR = 'markAnchor'
const ATTRS_MARKANCHOR_X = 'x'
const ATTRS_MARKANCHOR_Y = 'y'
const ATTRS_PADDING = 'padding'
const ATTRS_POSITION = 'position'
const ATTRS_POSITION_X = 'x'
const ATTRS_POSITION_Y = 'y'
const ATTRS_BACKGROUNDIMAGEPOSITION = 'backgroundImagePosition'
const ATTRS_BACKGROUNDIMAGEPOSITION_X = 'x'
const ATTRS_BACKGROUNDIMAGEPOSITION_Y = 'y'
const ATTRS_BACKGROUNDIMAGESIZE = 'backgroundImageSize'
const ATTRS_OFFSET = 'offset'
const ATTRS_OFFSET_X = 'x'
const ATTRS_OFFSET_Y = 'y'
const ATTRS_SHADOW = 'shadow'
const ATTRS_SHADOW_RADIUS = 'radius'
const ATTRS_SHADOW_COLOR = 'color'
const ATTRS_SHADOW_OFFSETX = 'offsetX'
const ATTRS_SHADOW_OFFSETY = 'offsetY'
const ATTRS_WINDOWBLUR = 'windowBlur'
const ATTRS_WINDOWBLUR_PERCENT = 'percent'
const ATTRS_WINDOWBLUR_STYLE = 'style'
const ATTRS_FONTFAMILY = 'fontFamily'
const ATTRS_FONTWEIGHT = 'fontWeight'
const ATTRS_FONTSTYLE = 'fontStyle'
const ATTRS_FONTSIZE = 'fontSize'
const ATTRS_TEXTCASE = 'textCase'
const ATTRS_MAXLINES = 'maxLines'
const ATTRS_DECORATION = 'decoration'
const ATTRS_BASELINEOFFSET = 'baselineOffset'
const ATTRS_TEXTOVERFLOW = 'textOverflow'
const ATTRS_LINEHEIGHT = 'lineHeight'
const ATTRS_FONTCOLOR = 'fontColor'
const ATTRS_TEXTALIGN = 'textAlign'
const ATTRS_CONTENT = 'content'
{
"string": [
{
"name": "entry_MainAbility",
"value": "entry_MainAbility"
},
{
"name": "description_mainability",
"value": "ETS_Empty Ability"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册