From 75114d6c8825892059c96f0bb72d25ba0037c6d1 Mon Sep 17 00:00:00 2001 From: wangguan Date: Fri, 11 Aug 2023 11:58:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Grid=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E7=9B=B8=E5=85=B3=E7=9A=84XTS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangguan --- .../main/ets/MainAbility/pages/GridPage.ets | 59 +++++++++++++- .../src/main/ets/test/GridJsunit.test.ets | 78 +++++++++++++++++-- 2 files changed, 128 insertions(+), 9 deletions(-) diff --git a/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/GridPage.ets b/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/GridPage.ets index d1772c84b..32286bf2f 100644 --- a/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/GridPage.ets +++ b/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/GridPage.ets @@ -40,6 +40,13 @@ struct GridPage { @State onItemDragMove: string = 'onItemDragMove' @State onItemDragLeave: string = 'onItemDragLeave' @State onItemDrop: string = 'onItemDrop' + @State onScrollText: string = 'onScroll' + @State onScrollIndexText: string = 'onScrollIndex' + @State onReachStartText: string = 'onReachStart' + @State onReachEndText: string = 'onReachEnd' + @State onScrollStartText: string = 'onScrollStart' + @State onScrollStopText: string = 'onScrollStop' + @State onScrollFrameBeginText: string = 'onScrollFrameBegin' @State myKey: number = 0 scroller: Scroller = new Scroller() messageManager:MessageManager = new MessageManager() @@ -144,7 +151,8 @@ struct GridPage { .width('90%') .key('grid1') .backgroundColor(0xFAEEE0) - .height(200) + .height(150) + .edgeEffect(EdgeEffect.Spring) .onItemDragStart((event: ItemDragInfo, itemIndex: number) => { this.onItemDragStart = 'onItemDragStart:succ' console.info('DragInfo_x: ' + event.x + ' DragInfo_y: ' + event.y) @@ -195,7 +203,36 @@ struct GridPage { }) .width('90%') .backgroundColor(0xFAEEE0) - .height(250) + .height(200) + .onScroll((scrollOffset: number, scrollState: ScrollState) => { + this.onScrollText = 'onScroll:succ' + console.info('onScroll scrollOffset:' + scrollOffset.toString() + ' ScrollState:' + ScrollState.toString()) + }) + .onScrollIndex((first: number,last: number) => { + this.onScrollIndexText = "onScrollIndex:succ" + console.info("onScrollIndex first:" + first.toString() + " last:" + last.toString()) + }) + .onReachStart(() => { + this.onReachStartText = 'onReachStart:succ' + console.info('onReachStart !') + }) + .onReachEnd(() => { + this.onReachEndText = 'onReachEnd:succ' + console.info('onReachEnd !') + }) + .onScrollStart(() => { + this.onScrollStartText = 'onScrollStart:succ' + console.info('onScrollStart !') + }) + .onScrollStop(() => { + this.onScrollStopText = 'onScrollStop:succ' + console.info('onScrollStop !') + }) + .onScrollFrameBegin((offset: number, state: ScrollState) => { + this.onScrollFrameBeginText = 'onScrollFrameBegin:succ' + console.info('onScrollFrameBegin offset:' + offset +' state:' + state) + return { offsetRemain: offset } + }) Button(this.buttonName) .key('button') @@ -209,6 +246,22 @@ struct GridPage { Text(this.onItemDragMove).key('onItemDragMove') Text(this.onItemDragLeave).key('onItemDragLeave') Text(this.onItemDrop).key('onItemDrop') + Row() + { + Text(this.onScrollText).margin({right:10}).key('onScrollText') + Text(this.onReachStartText).key('onReachStartText') + } + Row() + { + Text(this.onReachEndText).margin({right:10}).key('onReachEndText') + Text(this.onScrollStartText).key('onScrollStartText') + } + Row() + { + Text(this.onScrollIndexText).margin({right:10}).key('onScrollIndexText') + Text(this.onScrollStopText).key('onScrollStopText') + } + Text(this.onScrollFrameBeginText).key('onScrollFrameBeginText') }.width('100%').margin({ top: 5 }) } -} \ No newline at end of file +} diff --git a/arkui/ace_ets_component_ui/entry/src/main/ets/test/GridJsunit.test.ets b/arkui/ace_ets_component_ui/entry/src/main/ets/test/GridJsunit.test.ets index 546e5e13f..c185bee16 100644 --- a/arkui/ace_ets_component_ui/entry/src/main/ets/test/GridJsunit.test.ets +++ b/arkui/ace_ets_component_ui/entry/src/main/ets/test/GridJsunit.test.ets @@ -139,28 +139,29 @@ export default function GridJsunit() { // Verify the event of the Grid component console.info('[GridJsunit_0400] START'); await CommonFunc.sleep(1000); - + // Verify onScrollIndex event let grid2 = CommonFunc.getComponentRect('grid2'); let top = grid2.top let bottom = grid2.bottom let left = grid2.left let right = grid2.right - let driver = await UiDriver.create() + let driver = await Driver.create() await driver.swipe(Math.round((right - left) / 2), Math.round(bottom - 10), Math.round((right - left) / 2), Math.round(top + 10)); await driver.swipe(Math.round((right - left) / 2), Math.round(bottom - 10), Math.round((right - left) / 2), Math.round(top + 10)); - let onScrollIndex1 = await driver.findComponent(BY.key('onScrollIndex')); + let onScrollIndex1 = await driver.findComponent(ON.text('onScrollIndex')); let text1 = await onScrollIndex1.getText(); expect(text1).assertEqual('onScrollIndex:10'); await CommonFunc.sleep(1000); + await driver.swipe(Math.round((right - left) / 2), Math.round(bottom - 10), Math.round((right - left) / 2), Math.round(top + 10)); await driver.swipe(Math.round((right - left) / 2), Math.round(bottom - 10), Math.round((right - left) / 2), Math.round(top + 10)); - let onScrollIndex2 = await driver.findComponent(BY.key('onScrollIndex')); + let onScrollIndex2 = await driver.findComponent(ON.text('onScrollIndex')); let text2 = await onScrollIndex2.getText(); expect(text2).assertEqual('onScrollIndex:10'); // Verify common attribute click event - let button = await driver.findComponent(BY.key('button')); + let button = await driver.findComponent(ON.text('button')); await button.click(); await CommonFunc.sleep(1000); let strJson = getInspectorByKey('button'); @@ -204,7 +205,7 @@ export default function GridJsunit() { let gridItem2 = CommonFunc.getComponentRect('2'); let top = gridItem2.top expect(top > bottom).assertTrue(); - + // Verify grid componentcan cannot scroll let driver = await UiDriver.create() let grid_1 = await driver.findComponent(BY.key('grid1')); @@ -262,5 +263,70 @@ export default function GridJsunit() { console.info('[GridJsunit_0900] END'); done(); }); + it('GridJsunit_1000', 0, async function (done) { + // Verify Neither rowsTemplate nor columnsTemplate is set + console.info('[GridJsunit_1000] START'); + + let grid2 = CommonFunc.getComponentRect('grid2'); + let top = grid2.top + let bottom = grid2.bottom + let left = grid2.left + let right = grid2.right + let driver = await UiDriver.create() + await driver.swipe(Math.round((right - left)), Math.round(bottom - 60), Math.round((right - left)), Math.round(top + 60)); + await CommonFunc.sleep(200); + + let onReachStartText = await driver.findComponent(BY.key('onReachStartText')); + let text3 = await onReachStartText.getText(); + console.info('[GridJsunit_1000] onReachStartText' + text3); + expect(text3).assertEqual('onReachStart:succ'); + await CommonFunc.sleep(200); + + let onScrollText = await driver.findComponent(BY.key('onScrollText')); + let text4 = await onScrollText.getText(); + console.info('[GridJsunit_1000] onScrollText' + text4); + expect(text4).assertEqual('onScroll:succ'); + + let onScrollIndexText = await driver.findComponent(BY.key('onScrollIndexText')); + let text5 = await onScrollIndexText.getText(); + console.info('[GridJsunit_1000] onScrollIndexText' + text5); + expect(text5).assertEqual('onScrollIndex:succ'); + + let onScrollStartText = await driver.findComponent(BY.key('onScrollStartText')); + let text6 = await onScrollStartText.getText(); + console.info('[GridJsunit_1000] onScrollStartText' + text6); + expect(text6).assertEqual('onScrollStart:succ'); + await CommonFunc.sleep(200); + + let onScrollStopText = await driver.findComponent(BY.key('onScrollStopText')); + let text7 = await onScrollStopText.getText(); + console.info('[GridJsunit_1000] onScrollStopText' + text7); + expect(text7).assertEqual('onScrollStop:succ'); + await CommonFunc.sleep(200); + + let onScrollFrameBeginText = await driver.findComponent(BY.key('onScrollFrameBeginText')); + let text8 = await onScrollFrameBeginText.getText(); + console.info('[GridJsunit_1000] nScrollFrameBeginText ' + text8); + expect(text8).assertEqual('onScrollFrameBegin:succ'); + await CommonFunc.sleep(200); + + await driver.swipe(Math.round((right - left)), Math.round(top + 60), Math.round((right - left)), Math.round(bottom - 60)); + await driver.swipe(Math.round((right - left)), Math.round(top + 60), Math.round((right - left)), Math.round(bottom - 60)); + await driver.swipe(Math.round((right - left)), Math.round(top + 60), Math.round((right - left)), Math.round(bottom - 60)); + await CommonFunc.sleep(1000); + await driver.swipe(Math.round((right - left)), Math.round(top + 60), Math.round((right - left)), Math.round(bottom - 60)); + await driver.swipe(Math.round((right - left)), Math.round(top + 60), Math.round((right - left)), Math.round(bottom - 60)); + await driver.swipe(Math.round((right - left)), Math.round(top + 60), Math.round((right - left)), Math.round(bottom - 60)); + await CommonFunc.sleep(1000); + + let onReachEndText = await driver.findComponent(BY.key('onReachEndText')); + let text9= await onReachEndText.getText(); + console.info("[GridJsunit_1000] onReachEndText: " + text9); + expect(text9).assertEqual('onReachEnd:succ'); + await CommonFunc.sleep(1000); + + console.info('[GridJsunit_1000] END'); + done(); + }); }) } -- GitLab