From 7d0973dd675c0c84d4311a39f2dfc869b0b76dd1 Mon Sep 17 00:00:00 2001 From: wangguan Date: Fri, 25 Aug 2023 17:23:56 +0800 Subject: [PATCH] =?UTF-8?q?fixed=207bc3d11=20from=20https://gitee.com/kung?= =?UTF-8?q?e-hub/xts=5Facts/pulls/9875=20=E5=BC=B9=E7=AA=97=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E5=A4=9A=E4=B8=AA=E6=8C=89=E9=92=AE=E5=B1=9E=E6=80=A7?= =?UTF-8?q?XTS=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangguan --- .../main/ets/MainAbility/pages/DialogPage.ets | 202 ++++++++++++++++++ .../src/main/ets/test/DialogJsunit.test.ets | 83 +++++++ .../entry/src/main/ets/test/List.test.ets | 2 + .../resources/base/profile/main_pages.json | 3 +- 4 files changed, 289 insertions(+), 1 deletion(-) create mode 100644 arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/DialogPage.ets create mode 100644 arkui/ace_ets_component_ui/entry/src/main/ets/test/DialogJsunit.test.ets diff --git a/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/DialogPage.ets b/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/DialogPage.ets new file mode 100644 index 000000000..591bad0c7 --- /dev/null +++ b/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/DialogPage.ets @@ -0,0 +1,202 @@ +/** + * 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 DialogPage { + @State title: string = 'title' + @State message: string = "This is the message of alertdialog" + @State autoCancel: boolean = true + @State buttonName: string = 'ButtonHORIZONTAL' + @State buttonName1: string = 'ButtonVERTICAL' + @State buttonName2: string = 'ButtonAuto' + messageManager: MessageManager = new MessageManager() + + onPageShow() { + console.info('DialogPage onPageShow') + globalThis.value = { + name: 'messageManager', message: this.messageManager + } + + let callback: Callback = (message: any) => { + console.error('message = ' + message.name + "--" + message.value) + if (message.name == 'autoCancel') { + this.autoCancel = message.value + } + } + this.messageManager.registerCallback(callback) + } + + build() { + Column({ space: 40 }) { + Button(this.buttonName) + .key('button') + .onClick(() => { + this.buttonName = 'threeButtonHor:succ' + this.showThreeButtonHORIZONTAL() + }).backgroundColor(0x317aff) + + Button(this.buttonName1) + .key('button1') + .onClick(() => { + this.buttonName1 = 'threeButtonVer:succ' + this.showThreeButtonVERTICAL() + }).backgroundColor(0x317aff) + + Button(this.buttonName2) + .key('button2') + .onClick(() => { + this.buttonName2 = 'threeButtonAuto:succ' + this.showThreeButtonAUTO() + }).backgroundColor(0x317aff) + + }.width("100%").margin({ top: 150 }) + } + + private showThreeButtonHORIZONTAL() { + AlertDialog.show( + { + title: this.title, + message: this.message, + autoCancel: this.autoCancel, + buttonDirection:DialogButtonDirection.HORIZONTAL, + + buttons: [ + { + value: this.buttonName, + fontColor: 0xffffff, + backgroundColor: 0x317aff, + action: () => { + this.buttonName = "OneButton3:succ" + console.info("Button AlertDialog Button-Clicking callback") + } + }, + { + value: this.buttonName1, + fontColor: 0xffffff, + backgroundColor: 0x317aff, + action: () => { + this.buttonName1 = "OneButton3:succ" + console.info("Button AlertDialog Button-Clicking callback") + } + }, + { + value: this.buttonName2, + fontColor: 0xffffff, + backgroundColor: 0x317aff, + action: () => { + this.buttonName2 = "OneButton3:succ" + console.info("Button AlertDialog Button-Clicking callback") + } + }, + ], + cancel: () => { + console.info('Closed callbacks') + } + } + ) + } + private showThreeButtonVERTICAL() { + AlertDialog.show( + { + title: this.title, + message: this.message, + autoCancel: this.autoCancel, + buttonDirection:DialogButtonDirection.VERTICAL, + + buttons: [ + { + value: this.buttonName, + fontColor: 0xffffff, + backgroundColor: 0x317aff, + action: () => { + this.buttonName = "OneButton3:succ" + console.info("Button AlertDialog Button-Clicking callback") + } + }, + { + value: this.buttonName1, + fontColor: 0xffffff, + backgroundColor: 0x317aff, + action: () => { + this.buttonName1 = "OneButton3:succ" + console.info("Button AlertDialog Button-Clicking callback") + } + }, + { + value: this.buttonName2, + fontColor: 0xffffff, + backgroundColor: 0x317aff, + action: () => { + this.buttonName2 = "OneButton3:succ" + console.info("Button AlertDialog Button-Clicking callback") + } + }, + ], + + cancel: () => { + console.info('Closed callbacks') + } + } + ) + } + + private showThreeButtonAUTO() { + AlertDialog.show( + { + title: this.title, + message: this.message, + autoCancel: this.autoCancel, + buttonDirection:DialogButtonDirection.AUTO, + + + + buttons: [ + { + value: this.buttonName, + fontColor: 0xffffff, + backgroundColor: 0x317aff, + action: () => { + this.buttonName = "OneButton3:succ" + console.info("Button AlertDialog Button-Clicking callback") + } + }, + { + value: this.buttonName1, + fontColor: 0xffffff, + backgroundColor: 0x317aff, + action: () => { + this.buttonName1 = "OneButton3:succ" + console.info("Button AlertDialog Button-Clicking callback") + } + }, + { + value: this.buttonName2, + fontColor: 0xffffff, + backgroundColor: 0x317aff, + action: () => { + this.buttonName2 = "OneButton3:succ" + console.info("Button AlertDialog Button-Clicking callback") + } + }, + ], + cancel: () => { + console.info('Closed callbacks') + } + } + ) + } +} \ No newline at end of file diff --git a/arkui/ace_ets_component_ui/entry/src/main/ets/test/DialogJsunit.test.ets b/arkui/ace_ets_component_ui/entry/src/main/ets/test/DialogJsunit.test.ets new file mode 100644 index 000000000..3c55e2176 --- /dev/null +++ b/arkui/ace_ets_component_ui/entry/src/main/ets/test/DialogJsunit.test.ets @@ -0,0 +1,83 @@ +/** + * 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 { 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 DialogJsunit() { + describe('DialogJsunit', function () { + beforeEach(async function (done) { + console.info("DialogJsunit beforeEach start"); + let options = { + uri: 'MainAbility/pages/DialogPage', + } + try { + router.clear(); + let pages = router.getState(); + console.info("get DialogJsunit state pages: " + JSON.stringify(pages)); + if (!("DialogPage" == pages.name)) { + console.info("get DialogJsunit state pages.name: " + JSON.stringify(pages.name)); + let result = await router.push(options); + await CommonFunc.sleep(2000); + console.info("push DialogJsunit success: " + JSON.stringify(result)); + } + } catch (err) { + console.error("push DialogJsunit page error: " + err); + expect().assertFail(); + } + done(); + }); + it('DialogJsunit_0100', 0, async function (done) { + + console.info('[DialogJsunit_0100] START'); + await CommonFunc.sleep(1000); + + let driver = await UiDriver.create() + let button = await driver.findComponent(BY.key('button')); + await button.click(); + await CommonFunc.sleep(1000); + let strJson = getInspectorByKey('button'); + let obj = JSON.parse(strJson); + console.info('[DialogJsunit_0100] button component obj is: ' + obj.$attrs.label); + expect(obj.$attrs.label).assertEqual('threeButtonHor:succ'); + await driver.pressBack(); + await CommonFunc.sleep(500); + + let button1 = await driver.findComponent(BY.key('button1')); + await button1.click(); + await CommonFunc.sleep(1000); + let strJson1 = getInspectorByKey('button1'); + let obj1 = JSON.parse(strJson1); + console.info('[DialogJsunit_0100] button1 component obj is: ' + obj1.$attrs.label); + expect(obj1.$attrs.label).assertEqual('threeButtonVer:succ'); + await driver.pressBack(); + await CommonFunc.sleep(500); + + let button2 = await driver.findComponent(BY.key('button2')); + await button2.click(); + await CommonFunc.sleep(1000); + let strJson2 = getInspectorByKey('button2'); + let obj2 = JSON.parse(strJson2); + console.info('[DialogJsunit_0100] button2 component obj is: ' + obj2.$attrs.label); + expect(obj2.$attrs.label).assertEqual('threeButtonAuto:succ'); + await driver.pressBack(); + await CommonFunc.sleep(500); + console.info('[DialogJsunit_0100] END'); + done(); + }); + }) +} \ No newline at end of file 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 d1dbd1fba..b1b9a7f1b 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 @@ -60,8 +60,10 @@ import ApiCommponentAddJsunit from './ApiCommponentAddJsunit.test.ets'; import fontJsunit from './fontJsunit.test.ets'; import PanGestureEventJsunit from './PanGestureEventJsunit.test.ets'; import RenderFitJsunit from './RenderFitJsunit.test.ets'; +import DialogJsunit from './DialogJsunit.test.ets'; export default function testsuite() { + DialogJsunit(); blankJsunit(); buttonJsunit(); checkBoxGroupUIJsunit(); 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 3c138fe21..73ff93f5c 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 @@ -93,6 +93,7 @@ "MainAbility/pages/navition3", "MainAbility/pages/DragController", "MainAbility/pages/richEditor", - "MainAbility/pages/richEditorCustomKeyBoard" + "MainAbility/pages/richEditorCustomKeyBoard", + "MainAbility/pages/DialogPage" ] } \ No newline at end of file -- GitLab