From 3f4555d10109042af76feabc49ef91779d4e70f9 Mon Sep 17 00:00:00 2001 From: hekun Date: Wed, 19 Jul 2023 18:00:48 +0800 Subject: [PATCH] fix the code Signed-off-by: hekun --- .../ets/MainAbility/pages/lazyForEach.ets | 2 +- .../MainAbility/pages/GridColoffsetPage.ets | 59 +++++++++++++++ .../ets/test/GridColoffsetJsunit.test.ets | 71 +++++++++++++++++++ .../entry/src/main/ets/test/List.test.ets | 2 + .../resources/base/profile/main_pages.json | 3 +- 5 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/GridColoffsetPage.ets create mode 100644 arkui/ace_ets_component_ui/entry/src/main/ets/test/GridColoffsetJsunit.test.ets diff --git a/arkui/ace_ets_component_apilack/entry/src/main/ets/MainAbility/pages/lazyForEach.ets b/arkui/ace_ets_component_apilack/entry/src/main/ets/MainAbility/pages/lazyForEach.ets index 76da45be3..0d76cdcf4 100644 --- a/arkui/ace_ets_component_apilack/entry/src/main/ets/MainAbility/pages/lazyForEach.ets +++ b/arkui/ace_ets_component_apilack/entry/src/main/ets/MainAbility/pages/lazyForEach.ets @@ -67,7 +67,7 @@ class BasicDataSource implements IDataSource { } class MyDataSource extends BasicDataSource { - private dataArray: string[] = ['/path/image0', '/path/image1', '/path/image2', '/path/image3'] + private dataArray: string[] = ['/path/image0'] public totalCount(): number { return this.dataArray.length diff --git a/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/GridColoffsetPage.ets b/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/GridColoffsetPage.ets new file mode 100644 index 000000000..b25eb4be6 --- /dev/null +++ b/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/GridColoffsetPage.ets @@ -0,0 +1,59 @@ +/** + * 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 {MessageManager,Callback} from '../utils/MessageManager'; +@Entry +@Component +struct GridColOffSetExample { + @State bgColors: Color[] = [Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Pink, Color.Grey, Color.Blue, Color.Brown] + @State currentBp: string = 'unknown' + @State gridColoffsetValue : number = -3; + messageManager:MessageManager = new MessageManager() + onPageShow() { + console.info('GridColOffset onPageShow') + globalThis.value = { + name:'messageManager',message:this.messageManager + } + let callback:Callback = (message:any) => { + console.error('message = ' + message.name + "--" + message.value) + if (message.name == 'gridColoffset') { + this.gridColoffsetValue = message.value + } + } + this.messageManager.registerCallback(callback) + + } + build() { + Column() { + GridRow({ + columns: 5, + gutter: { x: 5, y: 10 }, + breakpoints: { value: ["400vp", "600vp", "800vp"], + reference: BreakpointsReference.WindowSize }, + direction: GridRowDirection.Row + }) { + ForEach(this.bgColors, (color,index) => { + GridCol({ span: { xs: 1, sm: 2, md: 3, lg: 4 } }) { + Row().width("100%").height("20vp") + }.borderColor(color).borderWidth(2).gridColOffset(this.gridColoffsetValue).key('keykey'+index) + }) + }.width("100%").height("100%") + + .onBreakpointChange((breakpoint) => { + this.currentBp = breakpoint + }) + }.width('80%').margin({ left: 10, top: 5, bottom: 5 }).height(200) + .border({ color: '#880606', width: 2 }) + } +} \ No newline at end of file diff --git a/arkui/ace_ets_component_ui/entry/src/main/ets/test/GridColoffsetJsunit.test.ets b/arkui/ace_ets_component_ui/entry/src/main/ets/test/GridColoffsetJsunit.test.ets new file mode 100644 index 000000000..52c80ef0e --- /dev/null +++ b/arkui/ace_ets_component_ui/entry/src/main/ets/test/GridColoffsetJsunit.test.ets @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2022 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 "@ohos/hypium" +import router from '@system.router'; +import {UiComponent, UiDriver, Component, Driver, UiWindow, ON, BY, MatchPattern, DisplayRotation, ResizeDirection, WindowMode, PointerMatrix} from '@ohos.UiTest'; +import CommonFunc from '../MainAbility/utils/Common'; +import {MessageManager,Callback} from '../MainAbility/utils/MessageManager'; + + +export default function GridColOffsetJsunit() { + describe('GridColOffsetJsunit', function () { + beforeEach(async function (done) { + console.info("GridColOffsetJsunit beforeEach start"); + let options = { + uri: 'MainAbility/pages/GridColoffsetPage', + } + try { + router.clear(); + let pages = router.getState(); + console.info("get GridColOffsetJsunit state pages: " + JSON.stringify(pages)); + if (!("GridColoffsetPage" == pages.name)) { + console.info("get GridColOffsetJsunit state pages.name: " + JSON.stringify(pages.name)); + let result = await router.push(options); + await CommonFunc.sleep(2000); + console.info("push GridColOffsetJsunit success: " + JSON.stringify(result)); + } + } catch (err) { + console.error("push GridColOffsetJsunit page error: " + err); + expect().assertFail(); + } + done(); + }); + + it('GridColOffsetJsunit_0100', 0, async function (done) { + // Get the information of the GridCol component + let strJson = getInspectorByKey('keykey2'); + let obj = JSON.parse(strJson); + expect(obj.$type).assertEqual('GridCol'); + console.info("[GridColOffsetJsunit_0100] component strJson:" + JSON.stringify(obj.$attrs.gridColOffset)); + expect(obj.$attrs.gridColOffset).assertEqual("0"); + done(); + }); + + it('GridColOffsetJsunit_0200', 0, async function (done) { + // Modify the properties of component GridCol + console.info('[GridColOffsetJsunit_0200] START'); + await CommonFunc.sleep(200); + globalThis.value.message.notify({name:'gridColoffset',value:2}); + await CommonFunc.sleep(200); + let strJson = getInspectorByKey('keykey2'); + let obj = JSON.parse(strJson); + expect(obj.$type).assertEqual('GridCol'); + console.info("[GridColOffsetJsunit_0100] component strJson:" + JSON.stringify(obj.$attrs.gridColOffset)); + expect(obj.$attrs.gridColOffset).assertEqual("2"); + done(); + }); + + }) +} diff --git a/arkui/ace_ets_component_ui/entry/src/main/ets/test/List.test.ets b/arkui/ace_ets_component_ui/entry/src/main/ets/test/List.test.ets index a5cc89687..85d546a9e 100644 --- a/arkui/ace_ets_component_ui/entry/src/main/ets/test/List.test.ets +++ b/arkui/ace_ets_component_ui/entry/src/main/ets/test/List.test.ets @@ -55,6 +55,7 @@ import ToggleJsunit from './ToggleJsunit.test.ets'; import NavDestinationJsunit from './NavDestinationJsunit.test.ets'; import GridItemJsunit from './GridItemJsunit.test.ets'; import NavigationJsunit from './NavigationJsunit.test.ets'; +import GridColOffsetJsunit from './GridColoffsetJsunit.test.ets'; export default function testsuite() { blankJsunit(); @@ -99,4 +100,5 @@ export default function testsuite() { NavDestinationJsunit(); GridItemJsunit(); NavigationJsunit(); + GridColOffsetJsunit(); } \ No newline at end of file diff --git a/arkui/ace_ets_component_ui/entry/src/main/resources/base/profile/main_pages.json b/arkui/ace_ets_component_ui/entry/src/main/resources/base/profile/main_pages.json index 30d60bbdf..a77ea7508 100644 --- a/arkui/ace_ets_component_ui/entry/src/main/resources/base/profile/main_pages.json +++ b/arkui/ace_ets_component_ui/entry/src/main/resources/base/profile/main_pages.json @@ -45,6 +45,7 @@ "MainAbility/pages/TogglePage", "MainAbility/pages/NavDestinationPage", "MainAbility/pages/NavigationPage", - "MainAbility/pages/GridItemPage" + "MainAbility/pages/GridItemPage", + "MainAbility/pages/GridColoffsetPage" ] } \ No newline at end of file -- GitLab