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 0000000000000000000000000000000000000000..591bad0c721bea648eef62ed17810f5a0b65942f --- /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 0000000000000000000000000000000000000000..3c55e2176613de6bfc5b285f0588d958800cd9f1 --- /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 d1dbd1fba20323af165018ac51cce85495b5a4bf..b1b9a7f1b1484b662691764666cb2c69d3e8ae3c 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 3c138fe21179c65f41df776dd444621567dd3b68..73ff93f5cd5b08a0079f40a910f90c9c95786abe 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