From fa0d540dab0010f117fec2e85092fe77dee9a837 Mon Sep 17 00:00:00 2001 From: huangdong57 Date: Thu, 13 Jul 2023 14:10:04 +0800 Subject: [PATCH] getcomponent xts Signed-off-by: huangdong57 --- .../ets/TestAbility/pages/getcomponent.ets | 159 ++++++++++ .../ets/TestAbility/pages/textObscured.ets | 2 +- .../src/main/ets/test/List.test.ets | 2 + .../src/main/ets/test/common/Utils.ets | 67 +++++ .../src/main/ets/test/getcomponent.test.ets | 278 ++++++++++++++++++ .../resources/base/profile/test_pages.json | 3 +- 6 files changed, 509 insertions(+), 2 deletions(-) create mode 100644 arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/TestAbility/pages/getcomponent.ets create mode 100644 arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/test/common/Utils.ets create mode 100644 arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/test/getcomponent.test.ets diff --git a/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/TestAbility/pages/getcomponent.ets b/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/TestAbility/pages/getcomponent.ets new file mode 100644 index 000000000..4c0333e7d --- /dev/null +++ b/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/TestAbility/pages/getcomponent.ets @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +@Entry +@Component +struct getcomponent { + + private scroller: Scroller = new Scroller() + private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] + @State Number: String[] = ['0', '1', '2', '3', '4'] + + + @State message: string = 'Hello World' + build() { + Row() { + Column() { + + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .key('ArkUX_Get_component_0010') + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + + Checkbox({name: 'checkbox1', group: 'checkboxGroup'}) + .select(true) + .selectedColor(0xed6f21) + .key('ArkUX_Get_component_0020') + + Image($r('app.media.icon')) + .width(110).height(110).border({ width: 1 }).borderStyle(BorderStyle.Dashed) + .overlay('png', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) + .key('ArkUX_Get_component_0030') + + Text('Radio1') + Radio({ value: 'Radio1', group: 'radioGroup' }).checked(true) + .height(50) + .width(50) + .key('ArkUX_Get_component_0040') + + Scroll(this.scroller) { + Flex({ direction: FlexDirection.Column }) { + ForEach(this.arr, (item) => { + Row() { + Text(item.toString()) + .width('80%') + .height(60) + .backgroundColor('#3366CC') + .borderRadius(15) + .fontSize(16) + .textAlign(TextAlign.Center) + .margin({ top: 5 }) + } + }, item => item) + }.margin({ right: 15 }) + } + .width('90%') + .scrollBar(BarState.Off) + .scrollable(ScrollDirection.Vertical) + ScrollBar({ scroller: this.scroller, direction: ScrollBarDirection.Vertical,state: BarState.Auto }) { + Text() + .width(20) + .height(100) + .borderRadius(10) + .backgroundColor('#C0C0C0') + }.width(20).backgroundColor('#ededed') + .key('ArkUX_Get_component_0050') + + Select([{value:'aaa'},{value:'bbb'},{value:'ccc'}]) + .selected(2) + .value('TTTTT') + .font({ size: 16, weight: 500 }) + .fontColor('#182431') + .selectedOptionFont({ size: 16, weight: 400 }) + .optionFont({ size: 16, weight: 400 }) + .key('ArkUX_Get_component_0060') + + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .key('ArkUX_Get_component_0070') + + Grid() { + ForEach(this.Number, (day: string) => { + ForEach(this.Number, (day: string) => { + GridItem() { + Text(day) + .fontSize(16) + .backgroundColor(0xF9CF93) + .width('100%') + .height('100%') + .textAlign(TextAlign.Center) + } + }, day => day) + }, day => day) + } + .columnsTemplate('1fr 1fr 1fr 1fr 1fr') + .rowsTemplate('1fr 1fr 1fr 1fr 1fr') + .columnsGap(10) + .rowsGap(10) + .width('90%') + .backgroundColor(0xFAEEE0) + .height(300) + .key('ArkUX_Get_component_0080') + + + List({ space: 20, initialIndex: 0 }) { + ForEach(this.arr, (item) => { + ListItem() { + Text('' + item) + .width('100%').height(100).fontSize(16) + .textAlign(TextAlign.Center).borderRadius(10).backgroundColor(0xFFFFFF) + } + }, item => item) + } + .key('ArkUX_Get_component_0090') + .listDirection(Axis.Vertical) + .divider({ strokeWidth: 2, color: 0xFFFFFF, startMargin: 20, endMargin: 20 }) + .edgeEffect(EdgeEffect.Spring) + .onScrollIndex((firstIndex: number, lastIndex: number) => { + console.info('first' + firstIndex) + console.info('last' + lastIndex) + }) + .width('90%') + + TextInput({ placeholder: 'input your password...' }) + .width(400) + .height(40) + .margin(20) + .type(InputType.Password) + .maxLength(9) + .showPasswordIcon(true) + .key('ArkUX_Get_component_0100') + + + }.width('100%') + + }.height('100%') + } +} \ No newline at end of file diff --git a/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/TestAbility/pages/textObscured.ets b/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/TestAbility/pages/textObscured.ets index 9aa6ac51f..d15f83643 100644 --- a/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/TestAbility/pages/textObscured.ets +++ b/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/TestAbility/pages/textObscured.ets @@ -15,7 +15,7 @@ @Entry @Component -struct Index { +struct textObscured { private scroller: Scroller = new Scroller() @State message: string = 'Hello World' diff --git a/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/test/List.test.ets b/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/test/List.test.ets index 9ec9b1af8..0038fb6ed 100644 --- a/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/test/List.test.ets +++ b/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/test/List.test.ets @@ -39,6 +39,7 @@ import assemblyCallbackTest from './assemblyCallback.test'; import ActsGridTest from './Grid.test'; import ActsListTest from './Listitem.test'; import ActsSwiperTest from './Swiper.test'; +import ActsgetcomponentTest from './getcomponent.test'; export default function testsuite() { @@ -68,4 +69,5 @@ export default function testsuite() { ActsGridTest() ActsListTest() ActsSwiperTest() + ActsgetcomponentTest() } \ No newline at end of file diff --git a/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/test/common/Utils.ets b/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/test/common/Utils.ets new file mode 100644 index 000000000..2288fc431 --- /dev/null +++ b/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/test/common/Utils.ets @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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 componentRect from '@ohos.componentUtils' + + +export default class Utils { + + static rect_width; + static rect_height; + + static rect_localOffsetX; + static rect_localOffsetY; + + static rect_windowOffsetX; + static rect_windowOffsetY; + + static rect_screenOffsetX; + static rect_screenOffsetY; + +// static rect_matrix4X; +// static rect_matrix4Y; +// static rect_matrix4Z; + + static rect_value; + + static getComponentRect(key) { + let strJson = componentRect.getRectangleById(key); + + this.rect_width = strJson.size.width + this.rect_height = strJson.size.height + this.rect_localOffsetX = strJson.localOffset.x + this.rect_localOffsetY = strJson.localOffset.y + + this.rect_windowOffsetX = strJson.windowOffset.x + this.rect_windowOffsetY = strJson.windowOffset.y + + this.rect_screenOffsetX = strJson.screenOffset.x + this.rect_screenOffsetY = strJson.screenOffset.y + +// this.rect_matrix4X = strJson.matrix4.x +// this.rect_matrix4Y = strJson.matrix4.y +// this.rect_matrix4Z = strJson.matrix4.z + + return this.rect_value = { + "width": this.rect_width, "height": this.rect_height, + "localOffsetX": this.rect_localOffsetX, "localOffsetY": this.rect_localOffsetY, + "windowOffsetX": this.rect_windowOffsetX, "windowOffsetY": this.rect_windowOffsetY, + "screenOffsetX": this.rect_screenOffsetX, "screenOffsetY": this.rect_screenOffsetX +// , +// "matrix4X": this.rect_matrix4X, "matrix4Y": this.rect_matrix4Y, +// "matrix4Z": this.rect_matrix4Z + } + } + +} \ No newline at end of file diff --git a/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/test/getcomponent.test.ets b/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/test/getcomponent.test.ets new file mode 100644 index 000000000..1383b8ae2 --- /dev/null +++ b/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/ets/test/getcomponent.test.ets @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import Utils from './common/Utils' +import router from '@system.router'; + +export default function ActsgetcomponentTest() { + describe('ActsgetcomponentTest', function () { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(function () { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(async function (done) { + console.info("flex beforeEach start"); + let options = { + uri: 'TestAbility/pages/getcomponent', + } + try { + router.clear(); + let pages = router.getState(); + console.info("get getcomponent state success " + JSON.stringify(pages)); + if (!("getcomponent" == pages.name)) { + console.info("get getcomponent state success " + JSON.stringify(pages.name)); + let result = await router.push(options); + console.info("push getcomponent page success " + JSON.stringify(result)); + } + } catch (err) { + console.error("push getcomponent page error: " + err); + } + done() + }); + afterEach(function () { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(function () { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + it('ArkUX_Get_component_0010', 0, async function (done) { + console.info('ArkUX_Get_component_0010 START'); + setTimeout(()=>{ + try{ + let strJson = Utils.getComponentRect('ArkUX_Get_component_0010'); + expect(parseInt(strJson.width)).assertEqual(252); + expect(parseInt(strJson.height)).assertEqual(56); + expect(parseInt(strJson.localOffsetX)).assertEqual(234); + expect(parseInt(strJson.localOffsetY)).assertEqual(30); + expect(parseInt(strJson.windowOffsetX)).assertEqual(234); + expect(parseInt(strJson.windowOffsetY)).assertEqual(102); + expect(parseInt(strJson.screenOffsetX)).assertEqual(234); + expect(parseInt(strJson.screenOffsetY)).assertEqual(234); + console.info('ArkUX_Get_component_0010 END '); + } catch(err) { + expect().assertFail() + console.info('ArkUX_Get_component_0010 ERR '+ JSON.stringify(err)); + } + done(); + },500) + }); + + it('ArkUX_Get_component_0020', 0, async function (done) { + console.info('ArkUX_Get_component_0020 START'); + setTimeout(()=>{ + try{ + let strJson = Utils.getComponentRect('ArkUX_Get_component_0020'); + expect(parseInt(strJson.width)).assertEqual(30); + expect(parseInt(strJson.height)).assertEqual(30); + expect(parseInt(strJson.localOffsetX)).assertEqual(345); + expect(parseInt(strJson.localOffsetY)).assertEqual(100); + expect(parseInt(strJson.windowOffsetX)).assertEqual(345); + expect(parseInt(strJson.windowOffsetY)).assertEqual(172); + expect(parseInt(strJson.screenOffsetX)).assertEqual(345); + expect(parseInt(strJson.screenOffsetY)).assertEqual(345); + console.info('ArkUX_Get_component_0020 END '); + } catch(err) { + expect().assertFail() + console.info('ArkUX_Get_component_0020 ERR '+ JSON.stringify(err)); + } + done(); + },500) + }); + + it('ArkUX_Get_component_0030', 0, async function (done) { + console.info('ArkUX_Get_component_0030 START'); + setTimeout(()=>{ + try{ + let strJson = Utils.getComponentRect('ArkUX_Get_component_0030'); + expect(parseInt(strJson.width)).assertEqual(165); + expect(parseInt(strJson.height)).assertEqual(165); + expect(parseInt(strJson.localOffsetX)).assertEqual(277); + expect(parseInt(strJson.localOffsetY)).assertEqual(144); + expect(parseInt(strJson.windowOffsetX)).assertEqual(277); + expect(parseInt(strJson.windowOffsetY)).assertEqual(216); + expect(parseInt(strJson.screenOffsetX)).assertEqual(277); + expect(parseInt(strJson.screenOffsetY)).assertEqual(277); + console.info('ArkUX_Get_component_0030 END '); + } catch(err) { + expect().assertFail() + console.info('ArkUX_Get_component_0030 ERR '+ JSON.stringify(err)); + } + done(); + },500) + }); + + it('ArkUX_Get_component_0040', 0, async function (done) { + console.info('ArkUX_Get_component_0040 START'); + setTimeout(()=>{ + try{ + let strJson = Utils.getComponentRect('ArkUX_Get_component_0040'); + expect(parseInt(strJson.width)).assertEqual(75); + expect(parseInt(strJson.height)).assertEqual(75); + expect(parseInt(strJson.localOffsetX)).assertEqual(322); + expect(parseInt(strJson.localOffsetY)).assertEqual(351); + expect(parseInt(strJson.windowOffsetX)).assertEqual(322); + expect(parseInt(strJson.windowOffsetY)).assertEqual(423); + expect(parseInt(strJson.screenOffsetX)).assertEqual(322); + expect(parseInt(strJson.screenOffsetY)).assertEqual(322); + console.info('ArkUX_Get_component_0040 END '); + } catch(err) { + expect().assertFail() + console.info('ArkUX_Get_component_0040 ERR '+ JSON.stringify(err)); + } + done(); + },500) + }); + + it('ArkUX_Get_component_0050', 0, async function (done) { + console.info('ArkUX_Get_component_0050 START'); + setTimeout(()=>{ + try{ + let strJson = Utils.getComponentRect('ArkUX_Get_component_0050'); + expect(parseInt(strJson.width)).assertEqual(30); + expect(parseInt(strJson.height)).assertEqual(1136); + expect(parseInt(strJson.localOffsetX)).assertEqual(345); + expect(parseInt(strJson.localOffsetY)).assertEqual(1576); + expect(parseInt(strJson.windowOffsetX)).assertEqual(345); + expect(parseInt(strJson.windowOffsetY)).assertEqual(1648); + expect(parseInt(strJson.screenOffsetX)).assertEqual(345); + expect(parseInt(strJson.screenOffsetY)).assertEqual(345); + console.info('ArkUX_Get_component_0050 END '); + } catch(err) { + expect().assertFail() + console.info('ArkUX_Get_component_0050 ERR '+ JSON.stringify(err)); + } + done(); + },500) + }); + + it('ArkUX_Get_component_0060', 0, async function (done) { + console.info('ArkUX_Get_component_0060 START'); + setTimeout(()=>{ + try{ + let strJson = Utils.getComponentRect('ArkUX_Get_component_0060'); + expect(parseInt(strJson.width)).assertEqual(126); + expect(parseInt(strJson.height)).assertEqual(36); + expect(parseInt(strJson.localOffsetX)).assertEqual(297); + expect(parseInt(strJson.localOffsetY)).assertEqual(2712); + expect(parseInt(strJson.windowOffsetX)).assertEqual(297); + expect(parseInt(strJson.windowOffsetY)).assertEqual(2784); + expect(parseInt(strJson.screenOffsetX)).assertEqual(297); + expect(parseInt(strJson.screenOffsetY)).assertEqual(297); + console.info('ArkUX_Get_component_0060 END '); + } catch(err) { + expect().assertFail() + console.info('ArkUX_Get_component_0060 ERR '+ JSON.stringify(err)); + } + done(); + },500) + }); + + it('ArkUX_Get_component_0070', 0, async function (done) { + console.info('ArkUX_Get_component_0070 START'); + setTimeout(()=>{ + try{ + let strJson = Utils.getComponentRect('ArkUX_Get_component_0070'); + expect(parseInt(strJson.width)).assertEqual(421); + expect(parseInt(strJson.height)).assertEqual(88); + expect(parseInt(strJson.localOffsetX)).assertEqual(149); + expect(parseInt(strJson.localOffsetY)).assertEqual(2748); + expect(parseInt(strJson.windowOffsetX)).assertEqual(149); + expect(parseInt(strJson.windowOffsetY)).assertEqual(2820); + expect(parseInt(strJson.screenOffsetX)).assertEqual(149); + expect(parseInt(strJson.screenOffsetY)).assertEqual(149); + console.info('ArkUX_Get_component_0070 END '); + } catch(err) { + expect().assertFail() + console.info('ArkUX_Get_component_0070 ERR '+ JSON.stringify(err)); + } + done(); + },500) + }); + + it('ArkUX_Get_component_0080', 0, async function (done) { + console.info('ArkUX_Get_component_0080 START'); + setTimeout(()=>{ + try{ + let strJson = Utils.getComponentRect('ArkUX_Get_component_0080'); + expect(parseInt(strJson.width)).assertEqual(648); + expect(parseInt(strJson.height)).assertEqual(450); + expect(parseInt(strJson.localOffsetX)).assertEqual(36); + expect(parseInt(strJson.localOffsetY)).assertEqual(2836); + expect(parseInt(strJson.windowOffsetX)).assertEqual(36); + expect(parseInt(strJson.windowOffsetY)).assertEqual(2908); + expect(parseInt(strJson.screenOffsetX)).assertEqual(36); + expect(parseInt(strJson.screenOffsetY)).assertEqual(36); + console.info('ArkUX_Get_component_0080 END '); + } catch(err) { + expect().assertFail() + console.info('ArkUX_Get_component_0080 ERR '+ JSON.stringify(err)); + } + done(); + },500) + }); + + it('ArkUX_Get_component_0090', 0, async function (done) { + console.info('ArkUX_Get_component_0090 START'); + setTimeout(()=>{ + try{ + let strJson = Utils.getComponentRect('ArkUX_Get_component_0090'); + expect(parseInt(strJson.width)).assertEqual(648); + expect(parseInt(strJson.height)).assertEqual(1136); + expect(parseInt(strJson.localOffsetX)).assertEqual(36); + expect(parseInt(strJson.localOffsetY)).assertEqual(3286); + expect(parseInt(strJson.windowOffsetX)).assertEqual(36); + expect(parseInt(strJson.windowOffsetY)).assertEqual(3358); + expect(parseInt(strJson.screenOffsetX)).assertEqual(36); + expect(parseInt(strJson.screenOffsetY)).assertEqual(36); + console.info('ArkUX_Get_component_0090 END '); + } catch(err) { + expect().assertFail() + console.info('ArkUX_Get_component_0090 ERR '+ JSON.stringify(err)); + } + done(); + },500) + }); + + it('ArkUX_Get_component_0100', 0, async function (done) { + console.info('ArkUX_Get_component_0100 START'); + setTimeout(()=>{ + try{ + let strJson = Utils.getComponentRect('ArkUX_Get_component_0100'); + expect(parseInt(strJson.width)).assertEqual(600); + expect(parseInt(strJson.height)).assertEqual(60); + expect(parseInt(strJson.localOffsetX)).assertEqual(60); + expect(parseInt(strJson.localOffsetY)).assertEqual(4452); + expect(parseInt(strJson.windowOffsetX)).assertEqual(60); + expect(parseInt(strJson.windowOffsetY)).assertEqual(4524); + expect(parseInt(strJson.screenOffsetX)).assertEqual(60); + expect(parseInt(strJson.screenOffsetY)).assertEqual(60); + console.info('ArkUX_Get_component_0100 END '); + } catch(err) { + expect().assertFail() + console.info('ArkUX_Get_component_0100 ERR '+ JSON.stringify(err)); + } + done(); + },500) + }); + + }) +} \ No newline at end of file diff --git a/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/resources/base/profile/test_pages.json b/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/resources/base/profile/test_pages.json index 37540ef05..ebae7c4c1 100644 --- a/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/resources/base/profile/test_pages.json +++ b/arkui/ace_ets_component_completion/ace_ets_component_wholeCompletion/src/main/resources/base/profile/test_pages.json @@ -27,6 +27,7 @@ "TestAbility/pages/assemblyCallback", "TestAbility/pages/list", "TestAbility/pages/grid", - "TestAbility/pages/swiper" + "TestAbility/pages/swiper", + "TestAbility/pages/getcomponent" ] } \ No newline at end of file -- GitLab