diff --git a/ArkUIKit/FreezeV2/README_zh.md b/ArkUIKit/FreezeV2/README_zh.md index 4988b25d7d1dbcf2561ee6b0700014ce0ff4361f..209786fe3bdf232740960dcdb9600f1e855e2a42 100644 --- a/ArkUIKit/FreezeV2/README_zh.md +++ b/ArkUIKit/FreezeV2/README_zh.md @@ -35,12 +35,15 @@ entry/src/main/ets/ | | |---template3 | | | |---MyNavigationTestStack.ets // 示例3(Navigation) | | |---template4 -| | | |---RepeatVirtualScrollFreeze.ets // 示例4(Repeat) +| | | |---RepeatVirtualScrollFreeze.ets // 示例4(Repeat,开启组件冻结) +| | | |---PageB.ets // 示例4(Repeat,关闭组件冻结) | | |---template5 | | | |---PageA.ets // 示例5(仅子组件开启组件冻结) -| | | |---PageB.ets +| | | |---PageB.ets // 示例5 (Navigation子页面) | | |---template6 | | | |---MyNavigationTestStack.ets // 示例6(混用场景) +| | |---template7 +| | | |---BuilderNode.ets // 示例7(限制条件BuilderNode) |---pages | |---Index.ets // 应用主页面 entry/src/ohosTest/ diff --git a/ArkUIKit/FreezeV2/entry/src/main/ets/pages/Index.ets b/ArkUIKit/FreezeV2/entry/src/main/ets/pages/Index.ets index fc79c0c164c20eb7444769e93e04b4f54496ae78..b8560d1c2068fa1325c1839959ab431a8a32cfaf 100644 --- a/ArkUIKit/FreezeV2/entry/src/main/ets/pages/Index.ets +++ b/ArkUIKit/FreezeV2/entry/src/main/ets/pages/Index.ets @@ -51,8 +51,10 @@ struct AnimateIndex { { name: 'template2/TabContentTest', label: $r('app.string.freeze_to_label2') }, { name: 'template3/MyNavigationTestStack', label: $r('app.string.freeze_to_label3') }, { name: 'template4/RepeatVirtualScrollFreeze', label: $r('app.string.freeze_to_label4') }, + { name: 'template4/PageB', label: $r('app.string.freeze_to_label4_B') }, { name: 'template5/PageA', label: $r('app.string.freeze_to_label5') }, { name: 'template6/MyNavigationTestStack', label: $r('app.string.freeze_to_label6') }, + { name: 'template7/BuilderNode', label: $r('app.string.freeze_to_label7') }, ] } ]; diff --git a/ArkUIKit/FreezeV2/entry/src/main/ets/pages/freeze/template4/PageB.ets b/ArkUIKit/FreezeV2/entry/src/main/ets/pages/freeze/template4/PageB.ets new file mode 100644 index 0000000000000000000000000000000000000000..42a249f452fedb9df45b3721c5dd1d9af8f38ad4 --- /dev/null +++ b/ArkUIKit/FreezeV2/entry/src/main/ets/pages/freeze/template4/PageB.ets @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2025 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. + */ + +@Entry +@ComponentV2 +struct RepeatVirtualScrollFreeze1 { + @Local simpleList: Array = []; + @Local bgColor: Color = Color.Pink; + + aboutToAppear(): void { + for (let i = 0; i < 7; i++) { + this.simpleList.push(`item${i}`); + } + } + + build() { + Column() { + Row() { + Button('Reduce length to 5') + .onClick(() => { + this.simpleList = this.simpleList.slice(0, 5); + }) + Button('Change bgColor') + .onClick(() => { + this.bgColor = this.bgColor == Color.Pink ? Color.Blue : Color.Pink; + }) + } + + List() { + Repeat(this.simpleList) + .each((obj: RepeatItem) => { + }) + .key((item: string, index: number) => item) + .virtualScroll({ totalCount: this.simpleList.length }) + .templateId(() => 'a') + .template('a', (ri) => { + ChildComponent1({ + message: ri.item, + bgColor: this.bgColor + }) + }, { cachedCount: 2 }) + } + .cachedCount(0) + .height(500) + } + .height('100%') + } +} +// [Start freeze_template4_pageB_start] +// 关闭组件冻结 +@ComponentV2({ freezeWhenInactive: false }) +struct ChildComponent1 { + @Param @Require message: string = ''; + @Param @Require bgColor: Color = Color.Pink; + @Monitor('bgColor') + onBgColorChange(monitor: IMonitor) { + // bgColor改变时,缓存池组件也会刷新,并打印日志 + console.info(`repeat---bgColor change from ${monitor.value()?.before} to ${monitor.value()?.now}`); + } + + build() { + Text(`[a]: ${this.message}`) + .fontSize(50) + .backgroundColor(this.bgColor) + } +} +// [End freeze_template4_pageB_start] \ No newline at end of file diff --git a/ArkUIKit/FreezeV2/entry/src/main/ets/pages/freeze/template5/PageA.ets b/ArkUIKit/FreezeV2/entry/src/main/ets/pages/freeze/template5/PageA.ets index 7628b07e5b995cec621528aa56a3c055c8db4114..83835cdf84362e7154f33626f67cd313594fca8b 100644 --- a/ArkUIKit/FreezeV2/entry/src/main/ets/pages/freeze/template5/PageA.ets +++ b/ArkUIKit/FreezeV2/entry/src/main/ets/pages/freeze/template5/PageA.ets @@ -13,7 +13,7 @@ * limitations under the License. */ // [Start freeze_template5_PageA_start] -// Page1.ets +// src/main/ets/pages/freeze/template5/PageA.ets @ObservedV2 class Book { @Trace public name: string = 'TS'; @@ -69,31 +69,4 @@ export struct Child { } } } -// [End freeze_template5_PageA_start] - -// [Start freeze_template5_PageB_start] -@Builder -function page2Builder() { - PageB(); -} - -@ComponentV2 -struct PageB { - pathStack: NavPathStack = new NavPathStack(); - - build() { - NavDestination() { - Column() { - Text('This is the Page2') - - Button('Back').fontSize(30) - .onClick(() => { - this.pathStack.pop(); - }) - } - }.onReady((context: NavDestinationContext) => { - this.pathStack = context.pathStack; - }) - } -} -// [End freeze_template5_PageB_start] \ No newline at end of file +// [End freeze_template5_PageA_start] \ No newline at end of file diff --git a/ArkUIKit/FreezeV2/entry/src/main/ets/pages/freeze/template5/PageB.ets b/ArkUIKit/FreezeV2/entry/src/main/ets/pages/freeze/template5/PageB.ets new file mode 100644 index 0000000000000000000000000000000000000000..0add1765367dee4be83a716b12bb2af0e807c6cc --- /dev/null +++ b/ArkUIKit/FreezeV2/entry/src/main/ets/pages/freeze/template5/PageB.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start freeze_template5_PageB_start] +// src/main/ets/pages/freeze/template5/PageB.ets +@Builder +function pageBBuilder() { + PageB(); +} + +@ComponentV2 +struct PageB { + pathStack: NavPathStack = new NavPathStack(); + + build() { + NavDestination() { + Column() { + Text('This is the PageB') + + Button('Back').fontSize(30) + .onClick(() => { + this.pathStack.pop(); + }) + } + }.onReady((context: NavDestinationContext) => { + this.pathStack = context.pathStack; + }) + } +} +// [End freeze_template5_PageB_start] \ No newline at end of file diff --git a/ArkUIKit/FreezeV2/entry/src/main/ets/pages/freeze/template7/BuilderNode.ets b/ArkUIKit/FreezeV2/entry/src/main/ets/pages/freeze/template7/BuilderNode.ets new file mode 100644 index 0000000000000000000000000000000000000000..d48c331ac7eda74e0fa0759deb44a0eb573ca606 --- /dev/null +++ b/ArkUIKit/FreezeV2/entry/src/main/ets/pages/freeze/template7/BuilderNode.ets @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2025 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. + */ +// [Start freeze_template7_start] +import { BuilderNode, FrameNode, NodeController, UIContext } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const DOMAIN = 0x0000; + +// 定义一个Params类,用于传递参数 +@ObservedV2 +class Params { + // 单例模式,确保只有一个Params实例 + public static singleton_: Params; + + // 获取Params实例的方法 + public static instance() { + if (!Params.singleton_) { + Params.singleton_ = new Params(0); + } + return Params.singleton_; + } + + // 使用@Trace装饰器装饰message属性,以便跟踪其变化 + @Trace public message: string = 'Hello'; + public index: number = 0; + + constructor(index: number) { + this.index = index; + } +} + +// 定义一个buildNodeChild组件,它包含一个message属性和一个index属性 +@ComponentV2 +struct buildNodeChild { + // 使用Params实例作为storage属性 + storage: Params = Params.instance(); + @Param index: number = 0; + + // 使用@Monitor装饰器监听storage.message的变化 + @Monitor('storage.message') + onMessageChange(monitor: IMonitor) { + hilog.info(DOMAIN, 'onMessageChange', + `FreezeBuildNode buildNodeChild message callback func ${this.storage.message}, index:${this.index}`); + } + + build() { + Text(`buildNode Child message: ${this.storage.message}`).fontSize(30) + } +} + +// 定义一个buildText函数,它接收一个Params参数并构建一个Column组件 +@Builder +function buildText(params: Params) { + Column() { + buildNodeChild({ index: params.index }) + } +} + +class TextNodeController extends NodeController { + private textNode: BuilderNode<[Params]> | null = null; + private index: number = 0; + + // 构造函数接收一个index参数 + constructor(index: number) { + super(); + this.index = index; + } + + // 创建并返回一个FrameNode + makeNode(context: UIContext): FrameNode | null { + this.textNode = new BuilderNode(context); + this.textNode.build(wrapBuilder<[Params]>(buildText), new Params(this.index)); + return this.textNode.getFrameNode(); + } +} + +// 定义一个Index组件,它包含一个message属性和一个data数组 +@Entry +@ComponentV2 +struct Index { + // 使用Params实例作为storage属性 + storage: Params = Params.instance(); + private data: number[] = [0, 1]; + + build() { + Row() { + Column() { + Button('change').fontSize(30) + .onClick(() => { + this.storage.message += 'a'; + }) + + Tabs() { + // 使用Repeat重复渲染TabContent组件 + Repeat(this.data) + .each((obj: RepeatItem) => { + TabContent() { + FreezeBuildNode({ index: obj.item }) + .margin({ top: 20 }) + }.tabBar(`tab${obj.item}`) + }) + .key((item: number) => item.toString()) + } + } + } + .width('100%') + .height('100%') + } +} + +// 定义一个FreezeBuildNode组件,它包含一个message属性和一个index属性 +@ComponentV2({ freezeWhenInactive: true }) +struct FreezeBuildNode { + // 使用Params实例作为storage属性 + storage: Params = Params.instance(); + @Param index: number = 0; + + // 使用@Monitor装饰器监听storage.message的变化 + @Monitor('storage.message') + onMessageChange(monitor: IMonitor) { + hilog.info(DOMAIN, 'onMessageChange', + `FreezeBuildNode message callback func ${this.storage.message}, index: ${this.index}`); + } + + build() { + NodeContainer(new TextNodeController(this.index)) + .width('100%') + .height('100%') + .backgroundColor('#FFF0F0F0') + } +} +// [End freeze_template7_start] \ No newline at end of file diff --git a/ArkUIKit/FreezeV2/entry/src/main/resources/base/element/string.json b/ArkUIKit/FreezeV2/entry/src/main/resources/base/element/string.json index 16f5bfe998db0c53afd2f14b72657f79fc8fbcb3..9ef3adcc8ed5899053c6067ec75181c9fa9a5e1b 100644 --- a/ArkUIKit/FreezeV2/entry/src/main/resources/base/element/string.json +++ b/ArkUIKit/FreezeV2/entry/src/main/resources/base/element/string.json @@ -30,7 +30,11 @@ }, { "name": "freeze_to_label4", - "value": "示例4(Repeat)" + "value": "示例4(开启组件冻结)" + }, + { + "name": "freeze_to_label4_B", + "value": "示例4(关闭组件冻结)" }, { "name": "freeze_to_label5", @@ -39,6 +43,10 @@ { "name": "freeze_to_label6", "value": "示例6(混用场景)" + }, + { + "name": "freeze_to_label7", + "value": "示例7(限制条件BuilderNode)" } ] } \ No newline at end of file diff --git a/ArkUIKit/FreezeV2/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/FreezeV2/entry/src/main/resources/base/profile/main_pages.json index 9fc8b495e367cb7e20af0875fbfca19e584cb04c..77e38eebcad885017001ce4636e6a67e9d542fc2 100644 --- a/ArkUIKit/FreezeV2/entry/src/main/resources/base/profile/main_pages.json +++ b/ArkUIKit/FreezeV2/entry/src/main/resources/base/profile/main_pages.json @@ -6,7 +6,9 @@ "pages/freeze/template2/TabContentTest", "pages/freeze/template3/MyNavigationTestStack", "pages/freeze/template4/RepeatVirtualScrollFreeze", + "pages/freeze/template4/PageB", "pages/freeze/template5/PageA", - "pages/freeze/template6/MyNavigationTestStack" + "pages/freeze/template6/MyNavigationTestStack", + "pages/freeze/template7/BuilderNode" ] } \ No newline at end of file diff --git a/ArkUIKit/FreezeV2/entry/src/main/resources/base/profile/router_map.json b/ArkUIKit/FreezeV2/entry/src/main/resources/base/profile/router_map.json index b276af62da4a634defdca58c645f476b0c945853..7cb03685e2acbbce756cb432116bad4d6cf8c0b1 100644 --- a/ArkUIKit/FreezeV2/entry/src/main/resources/base/profile/router_map.json +++ b/ArkUIKit/FreezeV2/entry/src/main/resources/base/profile/router_map.json @@ -2,8 +2,11 @@ "routerMap": [ { "name": "PageB", - "pageSourceFile": "src/main/ets/pages/freeze/template5/PageA.ets", - "buildFunction": "page2Builder" + "pageSourceFile": "src/main/ets/pages/freeze/template5/PageB.ets", + "buildFunction": "pageBBuilder", + "data": { + "description" : "This is the PageB" + } } ] } \ No newline at end of file diff --git a/ArkUIKit/FreezeV2/entry/src/ohosTest/ets/test/Freeze.test.ets b/ArkUIKit/FreezeV2/entry/src/ohosTest/ets/test/Freeze.test.ets index 90144a659bf6d5b511d91dc3339a04d205062341..113fcdff8ab2c1d01c21ae121dbbcab160de993a 100644 --- a/ArkUIKit/FreezeV2/entry/src/ohosTest/ets/test/Freeze.test.ets +++ b/ArkUIKit/FreezeV2/entry/src/ohosTest/ets/test/Freeze.test.ets @@ -24,23 +24,23 @@ const driver = Driver.create(); const BUNDLE = 'Freeze_' const TAG = '[Sample_Freeze]'; const DOMAIN = 0xF811 +const DELAYTIME01 = 1000; +const DELAYTIME02 = 3000; let aimComponent : Component export function FreezeTest() { describe('Freeze_FreezeTest', () => { - beforeAll(async () => { await delegator.startAbility({ bundleName: 'com.samples.freezev2', abilityName: 'EntryAbility' }); - await driver.delayMs(3000); + await driver.delayMs(DELAYTIME02); aimComponent = await driver.findComponent(ON.text(resource.resourceToString($r("app.string.freeze_to_label")))); await aimComponent.click(); - await driver.delayMs(1000); + await driver.delayMs(DELAYTIME01); }) - afterEach(async () => { aimComponent = await driver.findComponent(ON.text('Freezev2')); do { @@ -61,17 +61,16 @@ export function FreezeTest() { hilog.info(DOMAIN, TAG, 'Animation_FreezeTest_001_begin'); aimComponent = await driver.findComponent(ON.text(resource.resourceToString($r("app.string.freeze_to_label1")))); await aimComponent.click(); - await driver.delayMs(1000); - + await driver.delayMs(DELAYTIME01); aimComponent = await driver.findComponent(ON.text('changeBookName')); await aimComponent.click(); - await driver.delayMs(1000); + await driver.delayMs(DELAYTIME01); aimComponent = await driver.findComponent(ON.text('go to next page')); await aimComponent.click(); - await driver.delayMs(1000); + await driver.delayMs(DELAYTIME01); aimComponent = await driver.findComponent(ON.text('Back')); await aimComponent.click(); - await driver.delayMs(3000); + await driver.delayMs(DELAYTIME02); hilog.info(DOMAIN, TAG, 'Animation_FreezeTest_001_end'); }) @@ -87,17 +86,16 @@ export function FreezeTest() { hilog.info(DOMAIN, TAG, 'Animation_FreezeTest_002_begin'); aimComponent = await driver.findComponent(ON.text(resource.resourceToString($r("app.string.freeze_to_label2")))); await aimComponent.click(); - await driver.delayMs(1000); - + await driver.delayMs(DELAYTIME01); aimComponent = await driver.findComponent(ON.text('change message')); await aimComponent.click(); - await driver.delayMs(1000); + await driver.delayMs(DELAYTIME01); aimComponent = await driver.findComponent(ON.text('tab1')); await aimComponent.click(); - await driver.delayMs(1000); + await driver.delayMs(DELAYTIME01); aimComponent = await driver.findComponent(ON.text('tab0')); await aimComponent.click(); - await driver.delayMs(3000); + await driver.delayMs(DELAYTIME02); hilog.info(DOMAIN, TAG, 'Animation_FreezeTest_002_end'); }) @@ -113,17 +111,16 @@ export function FreezeTest() { hilog.info(DOMAIN, TAG, 'Animation_FreezeTest_003_begin'); aimComponent = await driver.findComponent(ON.text(resource.resourceToString($r("app.string.freeze_to_label3")))); await aimComponent.click(); - await driver.delayMs(1000); - + await driver.delayMs(DELAYTIME01); aimComponent = await driver.findComponent(ON.text('Next Page')); await aimComponent.click(); - await driver.delayMs(1000); + await driver.delayMs(DELAYTIME01); aimComponent = await driver.findComponent(ON.text('change message')); await aimComponent.click(); - await driver.delayMs(1000); + await driver.delayMs(DELAYTIME01); aimComponent = await driver.findComponent(ON.text('Back Page')); await aimComponent.click(); - await driver.delayMs(3000); + await driver.delayMs(DELAYTIME02); hilog.info(DOMAIN, TAG, 'Animation_FreezeTest_003_end'); }) @@ -139,14 +136,13 @@ export function FreezeTest() { hilog.info(DOMAIN, TAG, 'Animation_FreezeTest_004_begin'); aimComponent = await driver.findComponent(ON.text(resource.resourceToString($r("app.string.freeze_to_label4")))); await aimComponent.click(); - await driver.delayMs(1000); - + await driver.delayMs(DELAYTIME01); aimComponent = await driver.findComponent(ON.text('Reduce length to 5')); await aimComponent.click(); - await driver.delayMs(1000); + await driver.delayMs(DELAYTIME01); aimComponent = await driver.findComponent(ON.text('Change bgColor')); await aimComponent.click(); - await driver.delayMs(1000); + await driver.delayMs(DELAYTIME01); hilog.info(DOMAIN, TAG, 'Animation_FreezeTest_004_end'); }) @@ -161,14 +157,14 @@ export function FreezeTest() { it(BUNDLE + 'FreezeTest_005', 0, async () => { hilog.info(DOMAIN, TAG, 'Animation_FreezeTest_005_begin'); aimComponent = await driver.findComponent(ON.text(resource.resourceToString($r("app.string.freeze_to_label5")))); - - await driver.delayMs(1000); + await aimComponent.click(); + await driver.delayMs(DELAYTIME01); aimComponent = await driver.findComponent(ON.text('Go to next page')); await aimComponent.click(); - await driver.delayMs(1000); + await driver.delayMs(DELAYTIME01); aimComponent = await driver.findComponent(ON.text('Back')); await aimComponent.click(); - await driver.delayMs(3000); + await driver.delayMs(DELAYTIME02); hilog.info(DOMAIN, TAG, 'Animation_FreezeTest_005_end'); }) @@ -183,11 +179,42 @@ export function FreezeTest() { it(BUNDLE + 'FreezeTest_006', 0, async () => { hilog.info(DOMAIN, TAG, 'Animation_FreezeTest_006_begin'); aimComponent = await driver.findComponent(ON.text(resource.resourceToString($r("app.string.freeze_to_label6")))); - - aimComponent = await driver.findComponent(ON.text(resource.resourceToString($r('change BookName')))); await aimComponent.click(); - await driver.delayMs(1000); + await driver.delayMs(DELAYTIME01); + aimComponent = await driver.findComponent(ON.text('Next Page')); + await aimComponent.click(); + await driver.delayMs(DELAYTIME01); + aimComponent = await driver.findComponent(ON.text('Next Page')); + await aimComponent.click(); + await driver.delayMs(DELAYTIME01); + aimComponent = await driver.findComponent(ON.text('Back Page')); + await aimComponent.click(); + await driver.delayMs(DELAYTIME01); hilog.info(DOMAIN, TAG, 'Animation_FreezeTest_006_end'); }) + /* + * @tc.number: Animation_FreezeTest_007 + * @tc.name: Custom Component Freeze Functionality + * @tc.desc: Custom Component Freeze Functionality + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'FreezeTest_007', 0, async () => { + hilog.info(DOMAIN, TAG, 'Animation_FreezeTest_007_begin'); + aimComponent = await driver.findComponent(ON.text(resource.resourceToString($r("app.string.freeze_to_label7")))); + await aimComponent.click(); + await driver.delayMs(DELAYTIME01); + aimComponent = await driver.findComponent(ON.text('change')); + await aimComponent.click(); + await driver.delayMs(DELAYTIME01); + aimComponent = await driver.findComponent(ON.text('tab1')); + await aimComponent.click(); + await driver.delayMs(DELAYTIME01); + aimComponent = await driver.findComponent(ON.text('change')); + await aimComponent.click(); + await driver.delayMs(DELAYTIME01); + hilog.info(DOMAIN, TAG, 'Animation_FreezeTest_007_end'); + }) }) } \ No newline at end of file diff --git a/FormKit/FormEditDemo/entry/src/ohosTest/ets/test/Ability.test.ets b/FormKit/FormEditDemo/entry/src/ohosTest/ets/test/Ability.test.ets index e815d30f77992301eb2200be097689411fc527e6..ce787e8f54a3a866332b87c833b8195485607f99 100644 --- a/FormKit/FormEditDemo/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/FormKit/FormEditDemo/entry/src/ohosTest/ets/test/Ability.test.ets @@ -20,7 +20,7 @@ import hilog from '@ohos.hilog'; const TAG = '[Sample_FormEditDemo]'; const DOMAIN = 0xF811; -const BUNDLE = 'FormEditDemo_'; +const BUNDLE = 'FormEditDemo'; const DELAYTIME01 = 500; // 等待时长 const DELAYTIME02 = 2000; // 等待时长 diff --git a/FormKit/FormEditUIAbility/entry/src/ohosTest/ets/test/Ability.test.ets b/FormKit/FormEditUIAbility/entry/src/ohosTest/ets/test/Ability.test.ets index db468c95934bca0143950b48a062d683891a7769..c7b76902281a6b0a21a8ff1f28c0a19ba9691fd7 100644 --- a/FormKit/FormEditUIAbility/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/FormKit/FormEditUIAbility/entry/src/ohosTest/ets/test/Ability.test.ets @@ -20,7 +20,7 @@ import hilog from '@ohos.hilog'; const TAG = '[Sample_FormEditUIAbility]'; const DOMAIN = 0xF811; -const BUNDLE = 'FormEditUIAbility_'; +const BUNDLE = 'FormEditUIAbility'; const DELAYTIME01 = 500; // 等待时长 const DELAYTIME02 = 2000; // 等待时长 diff --git a/FormKit/FormEditUIAbility/ohosTest.md b/FormKit/FormEditUIAbility/ohosTest.md index ab3d92773757ec217f21550486b1fb9a9394d7ff..8afbc8c359d20d399c64498be5ecf3872fef4253 100644 --- a/FormKit/FormEditUIAbility/ohosTest.md +++ b/FormKit/FormEditUIAbility/ohosTest.md @@ -1,4 +1,4 @@ -# FormEditDemo测试用例归档 +# FormEditUIAbility测试用例归档 ## 用例表 diff --git a/FormKit/FormLiveDemo/ohosTest.md b/FormKit/FormLiveDemo/ohosTest.md index 8449a9142307d0ba19604ab1261f91b0890604ac..3709bce515ee713d21426320dbe0ad7b0bf3d2c6 100644 --- a/FormKit/FormLiveDemo/ohosTest.md +++ b/FormKit/FormLiveDemo/ohosTest.md @@ -1,4 +1,4 @@ -# FormEditDemo测试用例归档 +# FormLiveDemo测试用例归档 ## 用例表 diff --git a/FormKit/FormStandaloneDemo/entry/src/main/resources/base/element/string.json b/FormKit/FormStandaloneDemo/entry/src/main/resources/base/element/string.json index b7090ade509a9dd7024606333040a1b4dbfa7c05..9a68eaf9756756cd85a7f7297b0c04fc6b0a1f8a 100644 --- a/FormKit/FormStandaloneDemo/entry/src/main/resources/base/element/string.json +++ b/FormKit/FormStandaloneDemo/entry/src/main/resources/base/element/string.json @@ -19,6 +19,18 @@ { "name": "EntryFormAbility_label", "value": "独立卡包" + }, + { + "name": "add_form_to_desktop", + "value": "添加卡片到桌面" + }, + { + "name": "add_to_desktop", + "value": "添加桌面" + }, + { + "name": "app_to_delele", + "value": "卸载" } ] } \ No newline at end of file diff --git a/FormKit/FormStandaloneDemo/entry/src/ohosTest/ets/test/Ability.test.ets b/FormKit/FormStandaloneDemo/entry/src/ohosTest/ets/test/Ability.test.ets index 78bbeb463b828437e4af744a5640ba334f1ef921..3817e226a1b20aee7da7d618d320427e331b9d08 100644 --- a/FormKit/FormStandaloneDemo/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/FormKit/FormStandaloneDemo/entry/src/ohosTest/ets/test/Ability.test.ets @@ -13,8 +13,36 @@ * limitations under the License. */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it } from '@ohos/hypium'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import { Driver, ON, Component, Point } from '@ohos.UiTest'; +import hilog from '@ohos.hilog'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +const TAG = '[Sample_FormStandaloneDemo]' +const DOMAIN = 0xF811 +const DELAYTIME01 = 500; +const DELAYTIME02 = 2000; + + +let driver = Driver.create(); +const delegator = AbilityDelegatorRegistry.getAbilityDelegator(); + +async function getResourceString(resource: Resource): Promise { + let manage = delegator.getAppContext().resourceManager; + let text = await manage.getStringValue(resource); + return text; +} + +async function getCenterPoint(comp: Component, offset: number): Promise { + // 获取文件控件边框 + let rect = await comp.getBounds(); + // 计算文字控件高度 + let height = rect.bottom - rect.top; + // 获取文字控件中心点 + let point: Point = await comp.getBoundsCenter(); + point = {x: point.x, y:point.y - height*offset}; + return point; +} export default function abilityTest() { describe('FormStandaloneTest', () => { @@ -22,6 +50,7 @@ export default function abilityTest() { beforeAll(async () => { // 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. @@ -38,13 +67,28 @@ export default function abilityTest() { // This API supports only one parameter: clear action function. // hilog.info(DOMAIN, TAG, 'Back to first page start'); }) - it('assertContain', 0, () => { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - 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); + + /** + * 应用添加卡片后触发场景动效 + */ + it('FormStandaloneDemo_createStandaloneForm_001', 0, async () => { + // 回到桌面并进入测试应用的服务卡片预览界面 + hilog.info(DOMAIN, TAG, 'Back to desktop and add form start'); + await driver.delayMs(DELAYTIME01); + await driver.pressBack(); + await driver.delayMs(DELAYTIME01); + await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.EntryAbility_label'))).within(ON.type('GridItem'))) + let formEditDemoIcon: Component = await driver.findComponent(ON.text(await getResourceString($r('app.string.EntryAbility_label'))).within(ON.type('GridItem'))); + let point: Point = await getCenterPoint(formEditDemoIcon, 2); + hilog.info(DOMAIN, TAG, 'addForm start'); + // 长按指定位置的应用图标 + await driver.longClick(point.x, point.y); + await driver.delayMs(DELAYTIME02); + await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.app_to_delele'))).within(ON.type('Flex'))).then(()=>{ + hilog.info(DOMAIN, TAG, 'beforeAll find component'); + }) + await driver.pressBack(); + hilog.info(DOMAIN, TAG, 'Back to desktop and add form end'); }); }) } \ No newline at end of file diff --git a/FormKit/FormStandaloneDemo/library/src/ohosTest/ets/test/Ability.test.ets b/FormKit/FormStandaloneDemo/library/src/ohosTest/ets/test/Ability.test.ets index 6d4619c51af8912b20e2e52d3fd1ad2552f73a7f..78bbeb463b828437e4af744a5640ba334f1ef921 100644 --- a/FormKit/FormStandaloneDemo/library/src/ohosTest/ets/test/Ability.test.ets +++ b/FormKit/FormStandaloneDemo/library/src/ohosTest/ets/test/Ability.test.ets @@ -14,54 +14,7 @@ */ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it } from '@ohos/hypium'; -import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; -import { Driver, ON, Component, Point } from '@ohos.UiTest'; -import hilog from '@ohos.hilog'; - -const TAG = '[Sample_FormStandaloneDemo]' -const DOMAIN = 0xF811 -const DELAYTIME01 = 500; -const DELAYTIME02 = 2000; - - -let driver = Driver.create(); -const delegator = AbilityDelegatorRegistry.getAbilityDelegator(); - -async function getResourceString(resource: Resource): Promise { - let manage = delegator.getAppContext().resourceManager; - let text = await manage.getStringValue(resource); - return text; -} - -async function getCenterPoint(comp: Component, offset: number): Promise { - // 获取文件控件边框 - let rect = await comp.getBounds(); - // 计算文字控件高度 - let height = rect.bottom - rect.top; - // 获取文字控件中心点 - let point: Point = await comp.getBoundsCenter(); - point = {x: point.x, y:point.y - height*offset}; - return point; -} - -async function addForm(point: Point) { - hilog.info(DOMAIN, TAG, 'addForm start'); - // 长按指定位置的应用图标 - await driver.longClick(point.x, point.y); - // 点击卡片选项 - await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.add_form_to_desktop')))); - let serviceCard: Component = await driver.findComponent(ON.text(await getResourceString($r('app.string.add_form_to_desktop')))); - await serviceCard.click(); - await driver.delayMs(DELAYTIME01); - // 点击添加至桌面 - await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.add_to_desktop')))); - let addCard: Component = - await driver.findComponent(ON.text(await getResourceString($r('app.string.add_to_desktop')))); - await driver.delayMs(DELAYTIME01); - await addCard.click(); - hilog.info(DOMAIN, TAG, 'addForm finish'); -} +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; export default function abilityTest() { describe('FormStandaloneTest', () => { @@ -69,22 +22,6 @@ export default function abilityTest() { beforeAll(async () => { // 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. - // 回到桌面并进入测试应用的服务卡片预览界面 - hilog.info(DOMAIN, TAG, 'Back to desktop and add form start'); - await driver.delayMs(DELAYTIME01); - await driver.pressBack(); - await driver.delayMs(DELAYTIME01); - // 找到应用位置 - await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.EntryAbility_label'))).within(ON.type('GridItem'))) - let formEditDemoIcon: Component = await driver.findComponent(ON.text(await getResourceString($r('app.string.EntryAbility_label'))).within(ON.type('GridItem'))); - let point: Point = await getCenterPoint(formEditDemoIcon, 2); - await addForm(point); - await driver.delayMs(DELAYTIME02); - // 确认是否存在卡片 - await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.EntryAbility_label'))).within(ON.type('Flex'))).then(()=>{ - hilog.info(DOMAIN, TAG, 'beforeAll find component'); - }) - hilog.info(DOMAIN, TAG, 'Back to desktop and add form end'); }) beforeEach(() => { // Presets an action, which is performed before each unit test case starts. @@ -101,23 +38,13 @@ export default function abilityTest() { // This API supports only one parameter: clear action function. // hilog.info(DOMAIN, TAG, 'Back to first page start'); }) - - /** - * 应用添加卡片后触发场景动效 - */ - it('FormStandaloneDemo_createStandaloneForm_001', 0, async () => { - hilog.info(DOMAIN, TAG, 'FormStandaloneDemo_createStandaloneForm_001 test start'); - // 找到卡片是否存在 - await driver.delayMs(DELAYTIME02); - await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.liveform_click'))).within(ON.type('FormComponent'))).then(()=>{ - hilog.info(DOMAIN, TAG, 'FormStandaloneDemo_createStandaloneForm_001 find component'); - }) - let formComponent: Component = await driver.findComponent(ON.text(await getResourceString($r('app.string.liveform_click'))).within(ON.type('FormComponent'))); - let point: Point = await getCenterPoint(formComponent, 0); - await driver.click(point.x, point.y); - await driver.delayMs(DELAYTIME02); - await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.button_cancle')))); - hilog.info(DOMAIN, TAG, 'FormStandaloneDemo_createStandaloneForm_001 test end'); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + 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