From 9b66bf1bbe1a64013e0807ad26b3c92a41960fac Mon Sep 17 00:00:00 2001 From: lidra <593507091@qq.com> Date: Fri, 25 Oct 2024 14:37:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?samplexts=E5=88=A0=E9=99=A4=EF=BC=8C?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=88=B0hmrouterlibrary=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/ohosTest/ets/test/Ability.test.ets | 50 ---- .../ohosTest/ets/test/HMRouterApiXts.test.ets | 216 ------------------ .../ohosTest/ets/test/HMRouterXts.test.ets | 140 ------------ entry/src/ohosTest/ets/test/List.test.ets | 24 -- .../ohosTest/ets/test/util/CommonTestUtil.ets | 49 ---- entry/src/ohosTest/module.json5 | 13 -- 6 files changed, 492 deletions(-) delete mode 100644 entry/src/ohosTest/ets/test/Ability.test.ets delete mode 100644 entry/src/ohosTest/ets/test/HMRouterApiXts.test.ets delete mode 100644 entry/src/ohosTest/ets/test/HMRouterXts.test.ets delete mode 100644 entry/src/ohosTest/ets/test/List.test.ets delete mode 100644 entry/src/ohosTest/ets/test/util/CommonTestUtil.ets delete mode 100644 entry/src/ohosTest/module.json5 diff --git a/entry/src/ohosTest/ets/test/Ability.test.ets b/entry/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100644 index 6035ebd..0000000 --- a/entry/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2024 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 '@kit.PerformanceAnalysisKit'; -import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium'; - -export default function abilityTest() { - describe('ActsAbilityTest', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // 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(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }); - afterEach(() => { - // 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(() => { - // 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('assertContain', 0, () => { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); - let a = 'abc'; - let b = 'b'; - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b); - expect(a).assertEqual(a); - }); - }); -} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/HMRouterApiXts.test.ets b/entry/src/ohosTest/ets/test/HMRouterApiXts.test.ets deleted file mode 100644 index 032526d..0000000 --- a/entry/src/ohosTest/ets/test/HMRouterApiXts.test.ets +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (c) 2024 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 { beforeAll, describe, expect, it } from '@ohos/hypium'; -import { ON } from '@kit.TestKit'; -import { HMRouterMgr, HMRouterPathCallback, HMRouterPathInfo, IHMLifecycle } from '@hadss/hmrouter'; -import { driver, startAbility } from './util/CommonTestUtil'; -import { ZoomAnimator } from '../../../main/ets/animation/CustomPageAnimator'; -import { LoginStatusInterceptor } from '../../../main/ets/interceptor/LoginStatusInterceptor'; -import { WelcomeLifecycle } from '../../../main/ets/lifecycle/WelcomeLifecycle'; -import { animatorTransitionBuilder } from '../../../main/ets/component/mine/AnimatorTransition'; - -const delayTime = 10; -const navigationId = 'mainNavigationId'; - -export default function HMRouterApiTest() { - beforeAll(async () => { - // 启动ability - await startAbility(); - }); - - describe('HMRouterApiTest', () => { - it('openLog', 0, async () => { - HMRouterMgr.openLog('DEBUG'); - }); - - it('push', 0, async () => { - await driver.assertComponentExist(ON.text('智慧办公')); - HMRouterMgr.push(pathInfo1, callback); - await driver.delayMs(delayTime); - let navPathStack = HMRouterMgr.getPathStack(navigationId); - expect(getLastPathName(navPathStack)).assertEqual('myAccount'); - HMRouterMgr.pop(); - }); - - it('replace', 0, async () => { - await driver.assertComponentExist(ON.text('智慧办公')); - HMRouterMgr.push(pathInfo1); - HMRouterMgr.replace(pathInfo2, callback); - await driver.delayMs(delayTime); - let navPathStack = HMRouterMgr.getPathStack(navigationId); - expect(navPathStack?.size() === 2).assertTrue(); - expect(getLastPathName(navPathStack)).assertEqual('privacyPage'); - HMRouterMgr.pop(); - }); - - it('pop', 0, async () => { - await driver.assertComponentExist(ON.text('智慧办公')); - HMRouterMgr.push(pathInfo1, callback); - await driver.delayMs(delayTime); - HMRouterMgr.pop(homePathInfo); - await driver.delayMs(delayTime); - let navPathStack = HMRouterMgr.getPathStack(navigationId); - expect(navPathStack?.size() === 1).assertTrue(); - expect(getLastPathName(navPathStack)).assertEqual('HomeContent'); - }); - - it('getPathStack', 0, async () => { - await driver.assertComponentExist(ON.text('智慧办公')); - let navPathStack = HMRouterMgr.getPathStack(navigationId); - expect(navPathStack?.size() === 1).assertTrue(); - }); - - it('getCurrentParam', 0, async () => { - await driver.assertComponentExist(ON.text('智慧办公')); - HMRouterMgr.push(pathInfo1); - await driver.delayMs(delayTime); - let param = HMRouterMgr.getCurrentParam() as string; - expect(param).assertEqual('123'); - HMRouterMgr.pop(); - }); - - it('getCurrentLifecycleOwner', 0, async () => { - await driver.assertComponentExist(ON.text('智慧办公')); - let lifecycle = HMRouterMgr.getCurrentLifecycleOwner(); - expect(lifecycle !== null).assertTrue(); - }); - - it('generatePageLifecycleId', 0, async () => { - await driver.assertComponentExist(ON.text('智慧办公')); - let pageLifecycleId = HMRouterMgr.generatePageLifecycleId(); - expect(pageLifecycleId === '1_pages/_Index').assertTrue(); - }); - - it('getPageLifecycleById', 0, async () => { - await driver.assertComponentExist(ON.text('智慧办公')); - let pageLifecycle = HMRouterMgr.getPageLifecycleById('1_pages/_Index'); - expect(pageLifecycle !== null).assertTrue(); - }); - - it('request', 0, async () => { - await driver.assertComponentExist(ON.text('智慧办公')); - let result = HMRouterMgr.request('testFunWithReturn'); - expect(result.code === 0).assertTrue(); - }); - - it('registerGlobalInterceptor', 0, async () => { - await driver.assertComponentExist(ON.text('智慧办公')); - HMRouterMgr.registerGlobalInterceptor({ - interceptor: new LoginStatusInterceptor(), - interceptorName: 'testLoginStatusInterceptor', - priority: 9 - }); - let result = HMRouterMgr.unRegisterGlobalInterceptor('testLoginStatusInterceptor'); - - expect(result).assertTrue(); - }); - - it('registerGlobalLifecycle', 0, async () => { - await driver.assertComponentExist(ON.text('智慧办公')); - HMRouterMgr.registerGlobalLifecycle({ - lifecycle: new WelcomeLifecycle(), - lifecycleName: 'testWelcomeLifecycle', - priority: 9 - }); - let result = HMRouterMgr.unRegisterGlobalLifecycle('testWelcomeLifecycle'); - - expect(result).assertTrue(); - }); - - it('registerPageBuilder', 0, async () => { - await driver.assertComponentExist(ON.text('智慧办公')); - HMRouterMgr.registerPageBuilder({ - builder: wrapBuilder(animatorTransitionBuilder), - pageUrl: 'animatorTransition' - }); - HMRouterMgr.push({ - navigationId: navigationId, - pageUrl: 'animatorTransition' - }); - await driver.delayMs(delayTime); - let navPathStack = HMRouterMgr.getPathStack(navigationId); - expect(navPathStack?.size() === 2).assertTrue(); - expect(getLastPathName(navPathStack)).assertEqual('animatorTransition'); - HMRouterMgr.pop(); - }); - - it('testLifecycle', 0, async () => { - await driver.assertComponentExist(ON.text('智慧办公')); - let testLifecycle = new TestLifecycle(); - HMRouterMgr.registerGlobalLifecycle({ - lifecycle: testLifecycle, - lifecycleName: 'testLifecycle', - priority: 9 - }); - HMRouterMgr.push(pathInfo1); - HMRouterMgr.push(pathInfo2); - await driver.pressBack(); - HMRouterMgr.pop(); - HMRouterMgr.unRegisterGlobalLifecycle('testLifecycle'); - }); - }); -} - -function getLastPathName(navPathStack: NavPathStack | null) { - let pathNames = navPathStack?.getAllPathName(); - if(pathNames) { - return pathNames[pathNames.length-1]; - } else { - return ''; - } -} - -const callback: HMRouterPathCallback = { - onResult: (popInfo: PopInfo) => { - console.log('test callback onResult'); - }, - onArrival: () => { - console.log('test callback onArrival'); - }, - onLost: () => { - console.log('test callback onLost'); - } -}; - -const pathInfo1: HMRouterPathInfo = { - navigationId: navigationId, - pageUrl: 'myAccount', - param: '123', - interceptors: [new LoginStatusInterceptor()], - animator: new ZoomAnimator(), - skipAllInterceptor: false -}; - -const pathInfo2: HMRouterPathInfo = { - navigationId: navigationId, - pageUrl: 'privacyPage', - param: '123', - interceptors: [new LoginStatusInterceptor()], - animator: new ZoomAnimator(), - skipAllInterceptor: false -}; - -const homePathInfo: HMRouterPathInfo = { - navigationId: navigationId, - pageUrl: 'HomeContent', - param: '123', - interceptors: [new LoginStatusInterceptor()], - animator: new ZoomAnimator(), - skipAllInterceptor: false -}; - -class TestLifecycle implements IHMLifecycle { -} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/HMRouterXts.test.ets b/entry/src/ohosTest/ets/test/HMRouterXts.test.ets deleted file mode 100644 index 0399300..0000000 --- a/entry/src/ohosTest/ets/test/HMRouterXts.test.ets +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2024 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 { beforeAll, describe, it } from '@ohos/hypium'; -import { ON } from '@kit.TestKit'; -import { - driver, - findAndClickComponent, - findAndClickComponentById, - pressBack, - startAbility -} from './util/CommonTestUtil'; - -async function exitAndReturnHome() { - // 退出登录 - await findAndClickComponent('我的'); - await findAndClickComponent('小艺'); - await findAndClickComponent('退出登录'); - await findAndClickComponent('退出'); - await driver.assertComponentExist(ON.text('点击登录')); // 校验是否已退出 - - // 并返回首页 - await findAndClickComponent('首页'); - await driver.assertComponentExist(ON.text('智慧办公')); // 校验是否跳转到首页 -} - -export default function HMRouterTest() { - beforeAll(async () => { - // 启动ability - await startAbility(); - }); - - describe('HMRouterTest', () => { - // 登录和退出登录 - it('accountLogin', 0, async () => { - // 登录 - await findAndClickComponent('我的'); - await findAndClickComponent('点击登录'); - await findAndClickComponent('登录'); - if(!!!AppStorage.get('isPrivacy')) { - await findAndClickComponent('同意'); - await findAndClickComponent('登录'); - } - await driver.assertComponentExist(ON.text('小艺')); // 校验是否已登录 - - // 切换全局动画 - await findAndClickComponent('转场动画设置'); - await findAndClickComponentById('customAnimationButton'); - await driver.assertComponentExist(ON.text('缩放')); // 校验是否到全局动画页面 - await findAndClickComponent('缩放'); - await findAndClickComponentById('systemAnimationButton'); - - await pressBack(); - await exitAndReturnHome(); - }); - - // 商品详情页面购买 - it('productDetailPageShopping', 0, async () => { - // 首页跳转到商品详情 - await findAndClickComponentById('homeLivePicture'); - - await driver.assertComponentExist(ON.id('liveHome')); // 校验是否跳转到详情页 - - // 直播页面点击 - await findAndClickComponentById('liveHome'); - await findAndClickComponentById('comments'); - await pressBack(); - await pressBack(); - - await driver.assertComponentExist(ON.id('liveHome')); // 校验是否跳转到详情页 - - // 详情页购买 - await findAndClickComponent('购买'); - await findAndClickComponent('立即支付'); - - // 购物登录拦截 - if(!!!AppStorage.get('isLogin')) { - await driver.assertComponentExist(ON.text('登录')); // 校验是否跳转到登录页 - await findAndClickComponent('登录'); - if(!!!AppStorage.get('isPrivacy')) { - await findAndClickComponent('同意'); - await findAndClickComponent('登录'); - } - await findAndClickComponent('立即支付'); - } - - await findAndClickComponent('确认支付'); - await driver.assertComponentExist(ON.text('返回首页')); // 校验是否跳转到支付成功页面 - - await findAndClickComponentById('returnButton'); - await driver.assertComponentExist(ON.text('已支付')); // 校验是否跳转到详情支付页面 - - await pressBack(); - await pressBack(); - await driver.assertComponentExist(ON.text('智慧办公')); // 校验是否跳转到首页 - await exitAndReturnHome(); - }); - - // 购物袋页面购买 - it('shoppingBagShopping', 0, async () => { - await findAndClickComponent('购物袋'); - - // 购物登录拦截 - if(!!!AppStorage.get('isLogin')) { - await driver.assertComponentExist(ON.text('登录')); // 校验是否跳转到登录页 - await findAndClickComponent('登录'); - if(!!!AppStorage.get('isPrivacy')) { - await findAndClickComponent('同意'); - await findAndClickComponent('登录'); - } - } - - await driver.assertComponentExist(ON.id('payWithVoucher')); // 校验是否跳转到购物袋页面 - - // 通过购物袋购物 - await findAndClickComponentById('【现货速发】HUAWEI Mate X5 12GB+512GB 幻影紫'); - await findAndClickComponentById('payWithVoucher'); - await pressBack(); - await findAndClickComponent('再看看'); - await findAndClickComponent('确认支付'); - - await driver.assertComponentExist(ON.text('返回首页')); // 校验是否跳转到支付成功页面 - await findAndClickComponent('返回首页'); - await driver.assertComponentExist(ON.text('智慧办公')); // 校验是否跳转到首页 - await exitAndReturnHome(); - }); - }); -} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/List.test.ets b/entry/src/ohosTest/ets/test/List.test.ets deleted file mode 100644 index 0d89755..0000000 --- a/entry/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2024 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 abilityTest from './Ability.test'; -import HMRouterTest from './HMRouterXts.test'; -import HMRouterApiTest from './HMRouterApiXts.test'; - -export default function testsuite() { - abilityTest(); - HMRouterTest(); - HMRouterApiTest(); -} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/util/CommonTestUtil.ets b/entry/src/ohosTest/ets/test/util/CommonTestUtil.ets deleted file mode 100644 index 81c94ff..0000000 --- a/entry/src/ohosTest/ets/test/util/CommonTestUtil.ets +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2024 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 { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); - -const want: Want = { - bundleName: 'com.huawei.hadss.hmrouter', - abilityName: 'EntryAbility' -}; - -export const driver = Driver.create(); - -export async function startAbility() { - await delegator.startAbility(want); -} - -const delayTime = 500; - -export async function findAndClickComponent(componentName: string): Promise { - let button = await driver.findComponent(ON.text(componentName)); - await button.click(); - await driver.delayMs(delayTime); -} - -export async function findAndClickComponentById(componentId: string): Promise { - let button = await driver.findComponent(ON.id(componentId)); - await button.click(); - await driver.delayMs(delayTime); -} - -export async function pressBack(): Promise { - await driver.pressBack(); - await driver.delayMs(delayTime); -} diff --git a/entry/src/ohosTest/module.json5 b/entry/src/ohosTest/module.json5 deleted file mode 100644 index 55725a9..0000000 --- a/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,13 +0,0 @@ -{ - "module": { - "name": "entry_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} -- Gitee From 68cfae7d271b64d350b93da1567dbcb04cdc8120 Mon Sep 17 00:00:00 2001 From: lidra <593507091@qq.com> Date: Fri, 25 Oct 2024 16:16:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=EF=BC=8C=E6=8B=89=E8=B5=B7=E5=B0=8F=E8=89=BA=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=B3=95=E5=8F=B3=E4=B8=8B=E8=A7=92=E6=96=87=E6=A1=88=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/component/live/LiveCommentFooter.ets | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/entry/src/main/ets/component/live/LiveCommentFooter.ets b/entry/src/main/ets/component/live/LiveCommentFooter.ets index 22683fc..0676cfe 100644 --- a/entry/src/main/ets/component/live/LiveCommentFooter.ets +++ b/entry/src/main/ets/component/live/LiveCommentFooter.ets @@ -24,7 +24,8 @@ export struct LiveCommentFooter { src: $r('app.media.ic_s_search') }) .layoutWeight(1) - .margin({left: 10, top: 10, bottom: 10}); + .margin({left: 10, top: 10, bottom: 10}) + .enterKeyType(EnterKeyType.Send); Image($r('app.media.paperplane')) .width(25) .margin({left: 16, right: 16}); -- Gitee