diff --git a/function/notification/entry/src/ohosTest/ets/test/notificationtest.ets b/function/notification/entry/src/ohosTest/ets/test/notificationtest.ets new file mode 100644 index 0000000000000000000000000000000000000000..bf29bffc6863c0969209522d5c75dd13ccf56799 --- /dev/null +++ b/function/notification/entry/src/ohosTest/ets/test/notificationtest.ets @@ -0,0 +1,533 @@ +/** + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 '@ohos.hilog'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import Base from '@ohos.base'; +import notificationManager from '@ohos.notificationManager'; +import notification from '@ohos.notification'; +import notificationSubscribe from '@ohos.notificationSubscribe'; +import commonEventManager from '@ohos.commonEventManager'; +import promptAction from '@ohos.promptAction'; +import { BusinessError } from '@ohos.base' + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + /* + * @tc.number Sub_Noticication_Ans_Publish_IntelligentAggregation_0055 + * @tc.name PublishinasBundle The user calls the PublishinasBundle interface, without adding the unifiedGroupInfo parameter, and informs that the publication is successful. + */ + it('Sub_Noticication_Ans_Publish_IntelligentAggregation_0055', 3, () => { + hilog.info(0x0055, 'testTag', '%{public}s', 'test55 it begin'); + let representativeBundle: notificationManager.BundleOption = { + bundle: "bundleName1", + }; + let request: notificationManager.NotificationRequest = { + id: 1, + content: { + notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } + }; + try{ + notificationManager.publishAsBundle(representativeBundle, request).then(() => { + hilog.info(0x0056, 'testTag', '%{public}s', 'publishAsBundle success'); + }) + } + catch(err){ + hilog.info(0x0055, 'testTag', '%{public}s', `publishAsBundle fail! code: ${err.code}, message: ${err.message}`); + expect().assertFail(); + } + hilog.info(0x0055, 'testTag', '%{public}s', 'test55 it end'); + }) + + /* + * @tc.number Sub_Noticication_Ans_Publish_IntelligentAggregation_0056 + * @tc.name [PublishinasBundle] The user calls the PublishinasBundle interface, and adds the unifiedGroupInfo parameter to inform that the publication is successful. + */ + it('Sub_Noticication_Ans_Publish_IntelligentAggregation_0056', 3, () => { + let representativeBundle: notificationManager.BundleOption = { + bundle: "bundleName1", + }; + let request: notificationManager.NotificationRequest = { + id: 1, + content: { + notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + }, + unifiedGroupInfo:{ + key:"test", + title: "test-title", + content:"test-content", + sceneName:"flight", + extraInfo:{ + 'subScene':'FLIGHT_TICKETED_SUCCESS', + 'wordList':['',''], + 'hashcodeList':[] + } + } + }; + try{ + notificationManager.publishAsBundle(representativeBundle, request).then(() => { + hilog.info(0x0056, 'testTag', '%{public}s', 'publishAsBundle success'); + }) + } + catch(err){ + hilog.info(0x0056, 'testTag', '%{public}s', `publishAsBundle fail! code: ${err.code}, message: ${err.message}`); + expect().assertFail() + } + hilog.info(0x0056, 'testTag', '%{public}s', 'test56 it end'); + }) + + /* + * @tc.number Sub_Notification_Ans_Collaboration_deviceType_001 + */ + it('Sub_Notification_Ans_Collaboration_deviceType_001', 3, () => { + hilog.info(0x0057, 'testTag', '%{public}s', 'test57 it begin'); + let subscribeCallback = (err: Base.BusinessError) => { + if (err) { + console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); + expect(err.code).assertEqual(401); + } else { + console.info("subscribe success"); + expect().assertFail(); + } + } + let onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => { + console.info("Consume callback: " + JSON.stringify(data)); + } + let subscriber: notificationSubscribe.NotificationSubscriber = { + onConsume: onConsumeCallback + }; + let info: notificationSubscribe.NotificationSubscribeInfo = { + bundleNames: ["bundleName1","bundleName2"], + userId:100, + deviceType:null + }; + try{ + notificationSubscribe.subscribe(subscriber, info, subscribeCallback); + } + catch(err){ + hilog.info(0x0057, 'testTag', '%{public}s', `subscribe fail! code: ${err.code}, message: ${err.message}`); + expect(err.code).assertEqual(401); + } + hilog.info(0x0057, 'testTag', '%{public}s', 'test57 it end'); + }) + + /* + * @tc.number Sub_Notification_Ans_Collaboration_deviceType_002 + */ + it('Sub_Notification_Ans_Collaboration_deviceType_002', 3, () => { + let subscribeCallback = (err: Base.BusinessError) => { + if (err) { + console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); + expect(err.code).assertEqual(401); + } else { + console.info("subscribe success"); + expect().assertFail() + } + } + let onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => { + console.info("Consume callback: " + JSON.stringify(data)); + } + let subscriber: notificationSubscribe.NotificationSubscriber = { + onConsume: onConsumeCallback + }; + let info: notificationSubscribe.NotificationSubscribeInfo = { + bundleNames: ["bundleName1","bundleName2"], + userId:100, + deviceType:undefined + }; + try{ + notificationSubscribe.subscribe(subscriber, info, subscribeCallback); + } + catch(err){ + hilog.info(0x0057, 'testTag', '%{public}s', `subscribe fail! code: ${err.code}, message: ${err.message}`); + expect(err.code).assertEqual(401); + } + }) + + /* + * @tc.number Sub_Notification_Ans_Collaboration_deviceType_003 + */ + it('Sub_Notification_Ans_Collaboration_deviceType_003', 3, () => { + let subscribeCallback = (err: Base.BusinessError) => { + if (err) { + console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); + expect(err.code).assertEqual(401); + } else { + console.info("subscribe success"); + expect().assertFail() + } + } + let onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => { + console.info("Consume callback: " + JSON.stringify(data)); + } + let subscriber: notificationSubscribe.NotificationSubscriber = { + onConsume: onConsumeCallback + }; + let info: notificationSubscribe.NotificationSubscribeInfo = { + bundleNames: ["bundleName1","bundleName2"], + userId:100, + deviceType:"" + }; + try{ + notificationSubscribe.subscribe(subscriber, info, subscribeCallback); + } + catch(err){ + hilog.info(0x0057, 'testTag', '%{public}s', `subscribe fail! code: ${err.code}, message: ${err.message}`); + expect(err.code).assertEqual(401); + } + }) + + /* + * @tc.number Sub_Notification_Ans_Collaboration_deviceType_004 + */ + it('Sub_Notification_Ans_Collaboration_deviceType_004', 3, () => { + let subscribeCallback = (err: Base.BusinessError) => { + if (err) { + console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); + expect().assertFail(); + } else { + console.info("subscribe success"); + } + } + let onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => { + console.info("Consume callback: " + JSON.stringify(data)); + } + let subscriber: notificationSubscribe.NotificationSubscriber = { + onConsume: onConsumeCallback + }; + let info: notificationSubscribe.NotificationSubscribeInfo = { + bundleNames: ["bundleName1","bundleName2"], + userId:100, + }; + try{ + notificationSubscribe.subscribe(subscriber, info, subscribeCallback); + } + catch(err){ + hilog.info(0x0057, 'testTag', '%{public}s', `subscribe fail! code: ${err.code}, message: ${err.message}`); + expect().assertFail(); + } + }) + + /* + * @tc.number Sub_Notification_Ans_Collaboration_Query_0800 + */ + it('Sub_Notification_Ans_Collaboration_Query_0800', 3, () => { + hilog.info(0x0062, 'testTag', '%{public}s', 'test62 it begin'); + let bundle: notificationManager.BundleOption = { + bundle: "bundleName1", + uid: 1 + }; + let deviceType: string = ""; + try{ + notificationManager.isDistributedEnabledByBundle(bundle,deviceType) + .then(() => { + expect().assertFail() + }) + } + catch(err){ + hilog.info(0x0062, 'testTag', '%{public}s', `isDistributedEnabledByBundle fail! code: ${err.code}, message: ${err.message}`); + expect(err.code).assertEqual(401); + } + hilog.info(0x0062, 'testTag', '%{public}s', 'test62 it end'); + }) + + /* + * @tc.number Sub_Notification_Ans_Collaboration_Query_1300 + */ + it('Sub_Notification_Ans_Collaboration_Query_1300', 3, () => { + let deviceType: string = ""; + try{ + notificationManager.isSmartReminderEnabled(deviceType) + .then((data: boolean) => { + console.info("isSmartReminderEnabled success, data:" + data); + expect().assertFail() + }) + } + catch(err){ + hilog.info(0x0063, 'testTag', '%{public}s', `isSmartReminderEnabled fail! code: ${err.code}, message: ${err.message}`); + console.info(`isSmartReminderEnabled fail! code: ${err.code}, message: ${err.message}`); + expect(err.code).assertEqual(401); + } + }) + + /* + * @tc.number Sub_Notification_Ans_Delete_SpecifiedGroup_4200 + */ + it('Sub_Notification_Ans_Delete_SpecifiedGroup_4200', 3, () => { + let removeGroupByBundleCallback = (err: Base.BusinessError): void => { + if (err) { + console.error(`removeGroupByBundle failed, code is ${err.code}, message is ${err.message}`); + expect().assertFail() + } else { + console.info("removeGroupByBundle success"); + } + } + let bundleOption: notificationManager.BundleOption = { bundle: "com.example.myapplication" }; + let groupName: string = ""; + try{ + notificationManager.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback); + } + catch(err){ + hilog.info(0x0065, 'testTag', '%{public}s', `removeGroupByBundle fail! code: ${err.code}, message: ${err.message}`); + expect().assertFail(); + } + }) + + /* + * @tc.number Sub_Notification_Ans_Delete_SpecifiedGroup_5550 + */ + it('Sub_Notification_Ans_Delete_SpecifiedGroup_5550', 3, () => { + let removeGroupByBundleCallback = (err: Base.BusinessError): void => { + if (err) { + console.error(`removeGroupByBundle failed, code is ${err.code}, message is ${err.message}`); + expect().assertFail() + } else { + console.info("removeGroupByBundle success"); + } + } + let bundleOption: notificationManager.BundleOption = { bundle: "com.example.myapplication" }; + let groupName: string = "groupName1"; + try{ + notificationManager.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback); + } + catch(err){ + hilog.info(0x0065, 'testTag', '%{public}s', `removeGroupByBundle fail! code: ${err.code}, message: ${err.message}`); + expect().assertFail(); + } + }) + + /* + * @tc.number Sub_Notification_Ans_Delete_SpecifiedGroup_5950 + */ + it('Sub_Notification_Ans_Delete_SpecifiedGroup_5950', 3, () => { + let removeGroupByBundleCallback = (err: Base.BusinessError): void => { + if (err) { + console.error(`removeGroupByBundle failed, code is ${err.code}, message is ${err.message}`); + expect().assertFail() + } else { + console.info("removeGroupByBundle success"); + } + } + let bundleOption: notificationManager.BundleOption = { bundle: "com.example.myapplication" }; + let groupName: string = "groupName1"; + try{ + notificationManager.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback); + } + catch(err){ + hilog.info(0x0065, 'testTag', '%{public}s', `removeGroupByBundle fail! code: ${err.code}, message: ${err.message}`); + expect().assertFail(); + } + }) + + /* + * @tc.number Sub_Notification_Ans_Slot_Emergency_0100 + */ + it('Sub_Notification_Ans_Slot_Emergency_0100', 3, () => { + let subscribeCallback = (err: Base.BusinessError) => { + if (err) { + hilog.info(0x0182, 'testTag', '%{public}s', `subscribe failed, code is ${err.code}, message is ${err.message}`); + expect().assertFail() + } else { + hilog.info(0x0182, 'testTag', '%{public}s', "subscribe success"); + } + } + let onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => { + console.info("Consume callback: " + JSON.stringify(data)); + } + let subscriber: notificationSubscribe.NotificationSubscriber = { + onConsume: onConsumeCallback + }; + let info: notificationSubscribe.NotificationSubscribeInfo = { + bundleNames: ["com.example.myapplication"], + userId:100, + deviceType:"phone" + }; + notificationSubscribe.subscribe(subscriber, info, subscribeCallback); + let setNotificationEnableCallback = (err: Base.BusinessError): void => { + if (err) { + hilog.info(0x0182, 'testTag', '%{public}s', `setNotificationEnable failed, code is ${err.code}, message is ${err.message}`); + expect().assertFail() + } else { + hilog.info(0x0182, 'testTag', '%{public}s', "setNotificationEnable success"); + } + } + let bundle: notificationManager.BundleOption = { + bundle: "com.example.myapplication", + }; + notificationManager.setNotificationEnable(bundle, false, setNotificationEnableCallback); + let publishCallback = (err: Base.BusinessError): void => { + if (err) { + hilog.info(0x0182, 'testTag', '%{public}s', `publish failed, code is ${err.code}, message is ${err.message}`); + expect().assertFail() + } else { + hilog.info(0x0182, 'testTag', '%{public}s', "publish success"); + } + } + let notificationRequest: notificationManager.NotificationRequest = { + id: 1, + notificationSlotType: notificationManager.SlotType.EMERGENCY_INFORMATION, + content: { + notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } + }; + notificationManager.publish(notificationRequest,publishCallback) + }) + + /* + * @tc.number Sub_Notification_Ans_Slot_Emergency_0200 + */ + it('Sub_Notification_Ans_Slot_Emergency_0200', 3, () => { + let addSlotCallBack = (err: Base.BusinessError): void => { + if (err) { + console.error(`addSlot failed, code is ${err.code}, message is ${err.message}`); + expect().assertFail() + } else { + console.info("addSlot success"); + } + } + let notificationSlot: notificationManager.NotificationSlot = { + notificationType: notificationManager.SlotType.EMERGENCY_INFORMATION + }; + notificationManager.addSlot(notificationSlot, addSlotCallBack); + let getSlotsCallback = (err: Base.BusinessError, notificationSlot: Array): void => { + if (err) { + console.error(`getSlots failed, code is ${err.code}, message is ${err.message}`); + expect().assertFail() + } else { + console.info(`getSlots success, data is ${JSON.stringify(notificationSlot)}`); + } + } + notificationManager.getSlots(getSlotsCallback); + }) + + /* + * @tc.number Sub_Notification_Ces_StaticEvent_Enable_001 + */ + it('Sub_Notification_Ces_StaticEvent_Enable_001', 3, () => { + let enable:boolean = true; + let Callback = (err: Base.BusinessError): void => { + if (err) { + console.error(`setStaticSubscriberState failed, code is ${err.code}, message is ${err.message}`); + expect().assertFail() + } else { + console.info("setStaticSubscriberState success"); + } + } + commonEventManager.setStaticSubscriberState(enable, Callback); + }) + + /* + * @tc.number Sub_Notification_Ces_StaticEvent_Enable_001 + */ + it('Sub_Notification_Ces_StaticEvent_Enable_002', 3, () => { + let enable:boolean = false; + let Callback = (err: Base.BusinessError): void => { + if (err) { + console.error(`setStaticSubscriberState failed, code is ${err.code}, message is ${err.message}`); + expect().assertFail() + } else { + console.info("setStaticSubscriberState success"); + } + } + commonEventManager.setStaticSubscriberState(enable, Callback); + }) + + /* + * @tc.number Sub_Notification_Ces_StaticEvent_Enable_003 + * @tc.name setStaticSubscriberState(enable: boolean): Promise,enable=true + */ + it('Sub_Notification_Ces_StaticEvent_Enable_003', 3, () => { + let enable:boolean = true; + let evenName: string[] = ['usual.event.SEND_DATA']; + commonEventManager.setStaticSubscriberState(enable, evenName).then(() => { + try { + promptAction.showToast({ + message: 'app.string.static_subscribe_enabled', + duration: 2000, + }); + } catch (error) { + console.error(`showToast error code is ${error.code}, message is ${error.message}`); + } + console.info(`setStaticSubscriberState success, state is ${enable}`); + }).catch((err: BusinessError) => { + console.info(`setStaticSubscriberState failed, errCode: ${err.code}, errMes: ${err.message}`); + expect().assertFail() + }); + }) + + /* + * @tc.number Sub_Notification_Ces_StaticEvent_Enable_004 + * @tc.name setStaticSubscriberState(enable: boolean): Promise,enable=false + */ + it('Sub_Notification_Ces_StaticEvent_Enable_004', 3, () => { + let enable:boolean = false; + let evenName: string[] = ['usual.event.SEND_DATA']; + commonEventManager.setStaticSubscriberState(enable, evenName).then(() => { + try { + promptAction.showToast({ + message: 'app.string.static_subscribe_enabled', + duration: 2000, + }); + } catch (error) { + console.error(`showToast error code is ${error.code}, message is ${error.message}`); + } + console.info(`setStaticSubscriberState success, state is ${enable}`); + }).catch((err: BusinessError) => { + console.info(`setStaticSubscriberState failed, errCode: ${err.code}, errMes: ${err.message}`); + expect().assertFail() + }); + }) + + /* + * @tc.number Sub_Notification_Ces_StaticEvent_Enable_014 + * @tc.name setStaticSubscriberState接口,参数enable为null和undefined、特殊字符、中文、数字,调用失败,返回401 + */ + it('Sub_Notification_Ces_StaticEvent_Enable_014', 3, () => { + let enable:boolean = null; + let evenName: string[] = ['usual.event.SEND_DATA']; + commonEventManager.setStaticSubscriberState(enable, evenName).then(() => { + try { + promptAction.showToast({ + message: 'app.string.static_subscribe_enabled', + duration: 2000, + }); + } catch (error) { + console.error(`showToast error code is ${error.code}, message is ${error.message}`); + } + console.info(`setStaticSubscriberState success, state is ${enable}`); + expect().assertFail() + }).catch((err: BusinessError) => { + console.info(`setStaticSubscriberState failed, errCode: ${err.code}, errMes: ${err.message}`); + expect(err.code).assertEqual(401); + }); + }) + }) +} \ No newline at end of file diff --git a/function/notification/entry/src/ohosTest/ets/test/result.jpg b/function/notification/entry/src/ohosTest/ets/test/result.jpg new file mode 100644 index 0000000000000000000000000000000000000000..174604ed66f0035683ee3b7a42f94c752e7b0fe6 Binary files /dev/null and b/function/notification/entry/src/ohosTest/ets/test/result.jpg differ diff --git a/function/notification/entry/src/ohosTest/ets/test/result.md b/function/notification/entry/src/ohosTest/ets/test/result.md new file mode 100644 index 0000000000000000000000000000000000000000..47f644c5d475110250170fcc18b9eaa95f0fe5f4 --- /dev/null +++ b/function/notification/entry/src/ohosTest/ets/test/result.md @@ -0,0 +1,4 @@ +# result + +#### pic +![test_content](result.jpg) \ No newline at end of file