ref |> 新增华为默认系统分享
Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
Showing
36 changed files
with
626 additions
and
0 deletions
| @@ -244,6 +244,30 @@ | @@ -244,6 +244,30 @@ | ||
| 244 | ] | 244 | ] |
| 245 | } | 245 | } |
| 246 | ] | 246 | ] |
| 247 | + }, | ||
| 248 | + { | ||
| 249 | + "name": "wdShareBase", | ||
| 250 | + "srcPath": "./commons/wdShareBase", | ||
| 251 | + "targets": [ | ||
| 252 | + { | ||
| 253 | + "name": "default", | ||
| 254 | + "applyToProducts": [ | ||
| 255 | + "default" | ||
| 256 | + ] | ||
| 257 | + } | ||
| 258 | + ] | ||
| 259 | + }, | ||
| 260 | + { | ||
| 261 | + "name": "wdShare", | ||
| 262 | + "srcPath": "./features/wdShare", | ||
| 263 | + "targets": [ | ||
| 264 | + { | ||
| 265 | + "name": "default", | ||
| 266 | + "applyToProducts": [ | ||
| 267 | + "default" | ||
| 268 | + ] | ||
| 269 | + } | ||
| 270 | + ] | ||
| 247 | } | 271 | } |
| 248 | ] | 272 | ] |
| 249 | } | 273 | } |
sight_harmony/commons/wdShareBase/.gitignore
0 → 100644
sight_harmony/commons/wdShareBase/Index.ets
0 → 100644
| 1 | +{ | ||
| 2 | + "apiType": "stageMode", | ||
| 3 | + "buildOption": { | ||
| 4 | + }, | ||
| 5 | + "buildOptionSet": [ | ||
| 6 | + { | ||
| 7 | + "name": "release", | ||
| 8 | + "arkOptions": { | ||
| 9 | + "obfuscation": { | ||
| 10 | + "ruleOptions": { | ||
| 11 | + "enable": true, | ||
| 12 | + "files": [ | ||
| 13 | + "./obfuscation-rules.txt" | ||
| 14 | + ] | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + }, | ||
| 18 | + }, | ||
| 19 | + ], | ||
| 20 | + "targets": [ | ||
| 21 | + { | ||
| 22 | + "name": "default" | ||
| 23 | + } | ||
| 24 | + ] | ||
| 25 | +} |
| 1 | +# Define project specific obfuscation rules here. | ||
| 2 | +# You can include the obfuscation configuration files in the current module's build-profile.json5. | ||
| 3 | +# | ||
| 4 | +# For more details, see | ||
| 5 | +# https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md | ||
| 6 | + | ||
| 7 | +# Obfuscation options: | ||
| 8 | +# -disable-obfuscation: disable all obfuscations | ||
| 9 | +# -enable-property-obfuscation: obfuscate the property names | ||
| 10 | +# -enable-toplevel-obfuscation: obfuscate the names in the global scope | ||
| 11 | +# -compact: remove unnecessary blank spaces and all line feeds | ||
| 12 | +# -remove-log: remove all console.* statements | ||
| 13 | +# -print-namecache: print the name cache that contains the mapping from the old names to new names | ||
| 14 | +# -apply-namecache: reuse the given cache file | ||
| 15 | + | ||
| 16 | +# Keep options: | ||
| 17 | +# -keep-property-name: specifies property names that you want to keep | ||
| 18 | +# -keep-global-name: specifies names that you want to keep in the global scope |
| 1 | + | ||
| 2 | +export const enum ShareType { | ||
| 3 | + System = 0, | ||
| 4 | + WeChat, | ||
| 5 | + QQ, | ||
| 6 | + Weibo, | ||
| 7 | + | ||
| 8 | +} | ||
| 9 | + | ||
| 10 | +export const enum ShareScene { | ||
| 11 | + System = 0, | ||
| 12 | + | ||
| 13 | + WeChatSession, | ||
| 14 | + WeChatTimeline, | ||
| 15 | + | ||
| 16 | + QQFriend, | ||
| 17 | + QQZone, | ||
| 18 | + | ||
| 19 | + Weibo, | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +export const enum ShareContentType { | ||
| 23 | + PrueText = 1, | ||
| 24 | + ImageAndText, | ||
| 25 | + Link, | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +export interface ShareContentText { | ||
| 29 | + text: string | ||
| 30 | +} | ||
| 31 | +export interface ShareContentImageAndText { | ||
| 32 | + title: string | ||
| 33 | + desc?: string | ||
| 34 | + imgURI: string | ||
| 35 | + | ||
| 36 | +} | ||
| 37 | +export interface ShareContentLink { | ||
| 38 | + title: string | ||
| 39 | + desc?: string | ||
| 40 | + link: string | ||
| 41 | + icon?: string | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +export type ShareContent = ShareContentText | ShareContentImageAndText | ShareContentLink |
| 1 | +import { ShareContent, ShareContentImageAndText, ShareContentLink, ShareContentText, | ||
| 2 | + ShareContentType, | ||
| 3 | + ShareScene } from '../Constant'; | ||
| 4 | +import { WDShareInterface } from '../WDShareInterface'; | ||
| 5 | +import { AsyncCallback } from '@kit.BasicServicesKit'; | ||
| 6 | +import { common } from '@kit.AbilityKit'; | ||
| 7 | +import { systemShare } from '@kit.ShareKit'; | ||
| 8 | +import { uniformTypeDescriptor as utd } from '@kit.ArkData'; | ||
| 9 | + | ||
| 10 | +export class WDSystemShare implements WDShareInterface { | ||
| 11 | + | ||
| 12 | + shareContent(scene: ShareScene, content: ShareContent, contentType: ShareContentType): Promise<string> { | ||
| 13 | + | ||
| 14 | + return new Promise((resolve, fail) => { | ||
| 15 | + try { | ||
| 16 | + | ||
| 17 | + let controller: systemShare.ShareController = new systemShare.ShareController(this.getShareData(content, contentType)); | ||
| 18 | + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext | ||
| 19 | + | ||
| 20 | + controller.on('dismiss', () => { | ||
| 21 | + | ||
| 22 | + resolve("dismiss") | ||
| 23 | + }); | ||
| 24 | + | ||
| 25 | + controller.show(context, { | ||
| 26 | + previewMode: systemShare.SharePreviewMode.DEFAULT, | ||
| 27 | + selectionMode: systemShare.SelectionMode.SINGLE | ||
| 28 | + }); | ||
| 29 | + | ||
| 30 | + console.log("分享控制器调用完成") | ||
| 31 | + } catch (e) { | ||
| 32 | + fail(e) | ||
| 33 | + } | ||
| 34 | + }) | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + getShareData(content: ShareContent, contentType: ShareContentType) : systemShare.SharedData { | ||
| 38 | + if (contentType === ShareContentType.PrueText) { | ||
| 39 | + let prueText = content as ShareContentText | ||
| 40 | + console.log("分享纯文本") | ||
| 41 | + return new systemShare.SharedData({ | ||
| 42 | + utd: utd.UniformDataType.PLAIN_TEXT, | ||
| 43 | + content: prueText.text | ||
| 44 | + }); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + if (contentType === ShareContentType.ImageAndText) { | ||
| 48 | + let imageAndText = content as ShareContentImageAndText | ||
| 49 | + console.log("分享图片和文本") | ||
| 50 | + let data: systemShare.SharedData = new systemShare.SharedData({ | ||
| 51 | + utd: utd.UniformDataType.PLAIN_TEXT, | ||
| 52 | + content: imageAndText.title | ||
| 53 | + }); | ||
| 54 | + data.addRecord({ | ||
| 55 | + utd: utd.UniformDataType.PNG, | ||
| 56 | + uri: imageAndText.imgURI | ||
| 57 | + }); | ||
| 58 | + return data | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + console.log("分享链接和文本") | ||
| 62 | + let link = content as ShareContentLink | ||
| 63 | + let data: systemShare.SharedData = new systemShare.SharedData({ | ||
| 64 | + utd: utd.UniformDataType.PLAIN_TEXT, | ||
| 65 | + content: link.title | ||
| 66 | + }); | ||
| 67 | + data.addRecord({ | ||
| 68 | + utd: utd.UniformDataType.HYPERLINK, | ||
| 69 | + uri: link.link | ||
| 70 | + }); | ||
| 71 | + return data | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + | ||
| 75 | +} |
| 1 | +import { ShareContent, ShareContentType, ShareScene, ShareType } from './Constant' | ||
| 2 | +import { HashMap } from '@kit.ArkTS' | ||
| 3 | +import { WDShareInterface } from './WDShareInterface' | ||
| 4 | +import { WDSystemShare } from './System/WDSystemShare' | ||
| 5 | + | ||
| 6 | +export interface WDShareObject { | ||
| 7 | + to: ShareType, | ||
| 8 | + scene: ShareScene, | ||
| 9 | + type: ShareContentType, | ||
| 10 | + obj: ShareContent | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +export class WDShareBase { | ||
| 14 | + | ||
| 15 | + private static instance?: WDShareBase | ||
| 16 | + static getInstance() : WDShareBase { | ||
| 17 | + if (!WDShareBase.instance) { | ||
| 18 | + WDShareBase.instance = new WDShareBase() | ||
| 19 | + WDShareBase.instance.register() | ||
| 20 | + } | ||
| 21 | + return WDShareBase.instance | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + private handles: HashMap<ShareType, WDShareInterface> = new HashMap() | ||
| 25 | + | ||
| 26 | + register() { | ||
| 27 | + this.handles.set(ShareType.System, new WDSystemShare()) | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + share(obj: WDShareObject) : null | Promise<string> { | ||
| 31 | + let shareHandler: WDShareInterface = this.handles.get(obj.to) | ||
| 32 | + if (shareHandler) { | ||
| 33 | + return shareHandler.shareContent(obj.scene, obj.obj, obj.type) | ||
| 34 | + } | ||
| 35 | + return null | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + | ||
| 39 | + | ||
| 40 | + | ||
| 41 | +} |
| 1 | +import { ShareContent, ShareContentType, ShareScene } from './Constant' | ||
| 2 | +import { AsyncCallback } from '@kit.BasicServicesKit' | ||
| 3 | + | ||
| 4 | +export interface WDShareInterface { | ||
| 5 | + // shareContent(scene:ShareScene, content: ShareContent, callback: AsyncCallback<void>): void | ||
| 6 | + shareContent(scene:ShareScene, content: ShareContent, contentType: ShareContentType): Promise<string> | ||
| 7 | + | ||
| 8 | + | ||
| 9 | + | ||
| 10 | +} |
| 1 | +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; | ||
| 2 | + | ||
| 3 | +export default function localUnitTest() { | ||
| 4 | + describe('localUnitTest',() => { | ||
| 5 | + // Defines a test suite. Two parameters are supported: test suite name and test suite function. | ||
| 6 | + beforeAll(() => { | ||
| 7 | + // Presets an action, which is performed only once before all test cases of the test suite start. | ||
| 8 | + // This API supports only one parameter: preset action function. | ||
| 9 | + }); | ||
| 10 | + beforeEach(() => { | ||
| 11 | + // Presets an action, which is performed before each unit test case starts. | ||
| 12 | + // The number of execution times is the same as the number of test cases defined by **it**. | ||
| 13 | + // This API supports only one parameter: preset action function. | ||
| 14 | + }); | ||
| 15 | + afterEach(() => { | ||
| 16 | + // Presets a clear action, which is performed after each unit test case ends. | ||
| 17 | + // The number of execution times is the same as the number of test cases defined by **it**. | ||
| 18 | + // This API supports only one parameter: clear action function. | ||
| 19 | + }); | ||
| 20 | + afterAll(() => { | ||
| 21 | + // Presets a clear action, which is performed after all test cases of the test suite end. | ||
| 22 | + // This API supports only one parameter: clear action function. | ||
| 23 | + }); | ||
| 24 | + it('assertContain', 0, () => { | ||
| 25 | + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. | ||
| 26 | + let a = 'abc'; | ||
| 27 | + let b = 'b'; | ||
| 28 | + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. | ||
| 29 | + expect(a).assertContain(b); | ||
| 30 | + expect(a).assertEqual(a); | ||
| 31 | + }); | ||
| 32 | + }); | ||
| 33 | +} |
| @@ -16,5 +16,6 @@ | @@ -16,5 +16,6 @@ | ||
| 16 | "wdConstant": "file:../../commons/wdConstant", | 16 | "wdConstant": "file:../../commons/wdConstant", |
| 17 | "wdDetailPlayApi": "file:../../features/wdDetailPlayApi", | 17 | "wdDetailPlayApi": "file:../../features/wdDetailPlayApi", |
| 18 | // "wdComponent": "file:../../features/wdComponent" | 18 | // "wdComponent": "file:../../features/wdComponent" |
| 19 | + "wdShare": "file:../../features/wdShare" | ||
| 19 | } | 20 | } |
| 20 | } | 21 | } |
| @@ -11,6 +11,7 @@ import { SPHelper, ToastUtils, NumberFormatterUtils } from 'wdKit'; | @@ -11,6 +11,7 @@ import { SPHelper, ToastUtils, NumberFormatterUtils } from 'wdKit'; | ||
| 11 | import { WDPlayerController } from 'wdPlayer/Index'; | 11 | import { WDPlayerController } from 'wdPlayer/Index'; |
| 12 | import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'; | 12 | import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'; |
| 13 | import { SpConstants } from 'wdConstant/Index' | 13 | import { SpConstants } from 'wdConstant/Index' |
| 14 | +import { WDShare } from "wdShare" | ||
| 14 | 15 | ||
| 15 | interface ILikeStyleResp { | 16 | interface ILikeStyleResp { |
| 16 | url: Resource; | 17 | url: Resource; |
| @@ -336,6 +337,8 @@ export struct PlayerRightView { | @@ -336,6 +337,8 @@ export struct PlayerRightView { | ||
| 336 | .aspectRatio(1) | 337 | .aspectRatio(1) |
| 337 | .onClick((event: ClickEvent) => { | 338 | .onClick((event: ClickEvent) => { |
| 338 | ToastUtils.showToast('分享为公共方法,待开发', 1000); | 339 | ToastUtils.showToast('分享为公共方法,待开发', 1000); |
| 340 | + | ||
| 341 | + this.share() | ||
| 339 | }) | 342 | }) |
| 340 | Text('分享') | 343 | Text('分享') |
| 341 | .width('100%') | 344 | .width('100%') |
| @@ -349,4 +352,9 @@ export struct PlayerRightView { | @@ -349,4 +352,9 @@ export struct PlayerRightView { | ||
| 349 | } | 352 | } |
| 350 | .margin({ bottom: 20 }) | 353 | .margin({ bottom: 20 }) |
| 351 | } | 354 | } |
| 355 | + | ||
| 356 | + share() { | ||
| 357 | + | ||
| 358 | + WDShare.shareContent(this.contentDetailData) | ||
| 359 | + } | ||
| 352 | } | 360 | } |
sight_harmony/features/wdShare/.gitignore
0 → 100644
sight_harmony/features/wdShare/Index.ets
0 → 100644
| 1 | +{ | ||
| 2 | + "apiType": "stageMode", | ||
| 3 | + "buildOption": { | ||
| 4 | + }, | ||
| 5 | + "buildOptionSet": [ | ||
| 6 | + { | ||
| 7 | + "name": "release", | ||
| 8 | + "arkOptions": { | ||
| 9 | + "obfuscation": { | ||
| 10 | + "ruleOptions": { | ||
| 11 | + "enable": true, | ||
| 12 | + "files": [ | ||
| 13 | + "./obfuscation-rules.txt" | ||
| 14 | + ] | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + }, | ||
| 18 | + }, | ||
| 19 | + ], | ||
| 20 | + "targets": [ | ||
| 21 | + { | ||
| 22 | + "name": "default" | ||
| 23 | + } | ||
| 24 | + ] | ||
| 25 | +} |
sight_harmony/features/wdShare/hvigorfile.ts
0 → 100644
| 1 | +# Define project specific obfuscation rules here. | ||
| 2 | +# You can include the obfuscation configuration files in the current module's build-profile.json5. | ||
| 3 | +# | ||
| 4 | +# For more details, see | ||
| 5 | +# https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md | ||
| 6 | + | ||
| 7 | +# Obfuscation options: | ||
| 8 | +# -disable-obfuscation: disable all obfuscations | ||
| 9 | +# -enable-property-obfuscation: obfuscate the property names | ||
| 10 | +# -enable-toplevel-obfuscation: obfuscate the names in the global scope | ||
| 11 | +# -compact: remove unnecessary blank spaces and all line feeds | ||
| 12 | +# -remove-log: remove all console.* statements | ||
| 13 | +# -print-namecache: print the name cache that contains the mapping from the old names to new names | ||
| 14 | +# -apply-namecache: reuse the given cache file | ||
| 15 | + | ||
| 16 | +# Keep options: | ||
| 17 | +# -keep-property-name: specifies property names that you want to keep | ||
| 18 | +# -keep-global-name: specifies names that you want to keep in the global scope |
| 1 | +{ | ||
| 2 | + "meta": { | ||
| 3 | + "stableOrder": true | ||
| 4 | + }, | ||
| 5 | + "lockfileVersion": 3, | ||
| 6 | + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", | ||
| 7 | + "specifiers": { | ||
| 8 | + "@ohos/axios@^2.1.1": "@ohos/axios@2.2.0", | ||
| 9 | + "wdBean@../wdBean": "wdBean@../wdBean", | ||
| 10 | + "wdConstant@../../commons/wdConstant": "wdConstant@../../commons/wdConstant", | ||
| 11 | + "wdKit@../../commons/wdKit": "wdKit@../../commons/wdKit", | ||
| 12 | + "wdNetwork@../../commons/wdNetwork": "wdNetwork@../../commons/wdNetwork", | ||
| 13 | + "wdRouter@../../commons/wdRouter": "wdRouter@../../commons/wdRouter", | ||
| 14 | + "wdShareBase@../../commons/wdShareBase": "wdShareBase@../../commons/wdShareBase" | ||
| 15 | + }, | ||
| 16 | + "packages": { | ||
| 17 | + "@ohos/axios@2.2.0": { | ||
| 18 | + "name": "@ohos/axios", | ||
| 19 | + "integrity": "sha512-v1QBWk6DfcN8wUW3D0ieFbHTR1taSI5cOgxp5l6B5cegXuNYhSc8ggKlAIXe6h/14LsfM+NW0ZGfSXcNEIM5yA==", | ||
| 20 | + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/axios/-/axios-2.2.0.har", | ||
| 21 | + "registryType": "ohpm" | ||
| 22 | + }, | ||
| 23 | + "wdBean@../wdBean": { | ||
| 24 | + "name": "wdbean", | ||
| 25 | + "resolved": "../wdBean", | ||
| 26 | + "registryType": "local" | ||
| 27 | + }, | ||
| 28 | + "wdConstant@../../commons/wdConstant": { | ||
| 29 | + "name": "wdconstant", | ||
| 30 | + "resolved": "../../commons/wdConstant", | ||
| 31 | + "registryType": "local" | ||
| 32 | + }, | ||
| 33 | + "wdKit@../../commons/wdKit": { | ||
| 34 | + "name": "wdkit", | ||
| 35 | + "resolved": "../../commons/wdKit", | ||
| 36 | + "registryType": "local" | ||
| 37 | + }, | ||
| 38 | + "wdNetwork@../../commons/wdNetwork": { | ||
| 39 | + "name": "wdnetwork", | ||
| 40 | + "resolved": "../../commons/wdNetwork", | ||
| 41 | + "registryType": "local", | ||
| 42 | + "dependencies": { | ||
| 43 | + "wdConstant": "file:../wdConstant", | ||
| 44 | + "wdKit": "file:../wdKit", | ||
| 45 | + "@ohos/axios": "^2.1.1" | ||
| 46 | + } | ||
| 47 | + }, | ||
| 48 | + "wdRouter@../../commons/wdRouter": { | ||
| 49 | + "name": "wdrouter", | ||
| 50 | + "resolved": "../../commons/wdRouter", | ||
| 51 | + "registryType": "local", | ||
| 52 | + "dependencies": { | ||
| 53 | + "wdKit": "file:../wdKit", | ||
| 54 | + "wdBean": "file:../../features/wdBean", | ||
| 55 | + "wdNetwork": "file:../../commons/wdNetwork", | ||
| 56 | + "wdConstant": "file:../../commons/wdConstant" | ||
| 57 | + } | ||
| 58 | + }, | ||
| 59 | + "wdShareBase@../../commons/wdShareBase": { | ||
| 60 | + "name": "wdsharebase", | ||
| 61 | + "resolved": "../../commons/wdShareBase", | ||
| 62 | + "registryType": "local", | ||
| 63 | + "packageType": "InterfaceHar" | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | +} |
| 1 | +{ | ||
| 2 | + "name": "wdshare", | ||
| 3 | + "version": "1.0.0", | ||
| 4 | + "description": "Please describe the basic information.", | ||
| 5 | + "main": "Index.ets", | ||
| 6 | + "author": "", | ||
| 7 | + "license": "Apache-2.0", | ||
| 8 | + "packageType": "InterfaceHar", | ||
| 9 | + "dependencies": { | ||
| 10 | + "wdKit": "file:../../commons/wdKit", | ||
| 11 | + "wdBean": "file:../../features/wdBean", | ||
| 12 | + "wdRouter": "file:../../commons/wdRouter", | ||
| 13 | + "wdShareBase": "file:../../commons/wdShareBase" | ||
| 14 | + } | ||
| 15 | +} |
| 1 | +import { ContentDetailDTO, ContentDTO, PageInfoDTO } from 'wdBean/Index'; | ||
| 2 | +import { ShareScene, ShareType, WDShareBase } from 'wdShareBase/Index'; | ||
| 3 | +import { ShareContentType } from 'wdShareBase/src/main/ets/Constant'; | ||
| 4 | + | ||
| 5 | +export class WDShare { | ||
| 6 | + | ||
| 7 | + static shareContent(content: ContentDetailDTO, pageName: string ="", pageId: string = "") { | ||
| 8 | + | ||
| 9 | + //TODO: 处理分享弹框交互和 海报逻辑 | ||
| 10 | + | ||
| 11 | + WDShareBase.getInstance().share({ | ||
| 12 | + to: ShareType.System, | ||
| 13 | + scene: ShareScene.System, | ||
| 14 | + type: ShareContentType.Link, | ||
| 15 | + obj: { | ||
| 16 | + title: content.shareInfo.shareTitle, | ||
| 17 | + desc: content.shareInfo.shareSummary, | ||
| 18 | + link: content.shareInfo.shareUrl, | ||
| 19 | + } | ||
| 20 | + }) | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + static shareProgram(program: ContentDTO, pageName: string ="", pageId: string = "") { | ||
| 24 | + | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + static shareSubject(subject: PageInfoDTO) { | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | +} |
| 1 | +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; | ||
| 2 | + | ||
| 3 | +export default function localUnitTest() { | ||
| 4 | + describe('localUnitTest',() => { | ||
| 5 | + // Defines a test suite. Two parameters are supported: test suite name and test suite function. | ||
| 6 | + beforeAll(() => { | ||
| 7 | + // Presets an action, which is performed only once before all test cases of the test suite start. | ||
| 8 | + // This API supports only one parameter: preset action function. | ||
| 9 | + }); | ||
| 10 | + beforeEach(() => { | ||
| 11 | + // Presets an action, which is performed before each unit test case starts. | ||
| 12 | + // The number of execution times is the same as the number of test cases defined by **it**. | ||
| 13 | + // This API supports only one parameter: preset action function. | ||
| 14 | + }); | ||
| 15 | + afterEach(() => { | ||
| 16 | + // Presets a clear action, which is performed after each unit test case ends. | ||
| 17 | + // The number of execution times is the same as the number of test cases defined by **it**. | ||
| 18 | + // This API supports only one parameter: clear action function. | ||
| 19 | + }); | ||
| 20 | + afterAll(() => { | ||
| 21 | + // Presets a clear action, which is performed after all test cases of the test suite end. | ||
| 22 | + // This API supports only one parameter: clear action function. | ||
| 23 | + }); | ||
| 24 | + it('assertContain', 0, () => { | ||
| 25 | + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. | ||
| 26 | + let a = 'abc'; | ||
| 27 | + let b = 'b'; | ||
| 28 | + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. | ||
| 29 | + expect(a).assertContain(b); | ||
| 30 | + expect(a).assertEqual(a); | ||
| 31 | + }); | ||
| 32 | + }); | ||
| 33 | +} |
-
Please register or login to post a comment