From ded2b68d8369a3556feed53ffeda603e6a993af8 Mon Sep 17 00:00:00 2001 From: nan-xiansen Date: Tue, 25 Jan 2022 17:03:04 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=85=A8=E5=B1=80=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E8=B0=83=E5=BA=A6=E5=AD=90=E7=B3=BB=E7=BB=9F=E3=80=91=E3=80=90?= =?UTF-8?q?master=E3=80=91=E5=A2=9E=E5=8A=A0=E4=BB=A3=E7=90=86=E6=8F=90?= =?UTF-8?q?=E9=86=92=E7=B1=BBJS=20API=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nan-xiansen Change-Id: I069eec606c07acdb242062703cd06d5a429cca07 --- .../reminderagent/Test.json | 2 +- .../reminderagent/src/main/config.json | 6 +- .../src/main/js/default/i18n/zh-CN.json | 2 +- .../js/default/test/ReminderAgentJs.test.js | 622 +++++++++++++++++- 4 files changed, 591 insertions(+), 41 deletions(-) diff --git a/resourceschedule/resourceschedule_standard/reminderagent/Test.json b/resourceschedule/resourceschedule_standard/reminderagent/Test.json index 396326d74..8ed82b955 100644 --- a/resourceschedule/resourceschedule_standard/reminderagent/Test.json +++ b/resourceschedule/resourceschedule_standard/reminderagent/Test.json @@ -3,7 +3,7 @@ "driver": { "type": "JSUnitTest", "test-timeout": "300000", - "package": "ohos.acts.resourceschedule.reminderagentjs.function", + "package": "ohos.acts.resourceschedule.reminderagent.js.function", "shell-timeout": "60000" }, "kits": [ diff --git a/resourceschedule/resourceschedule_standard/reminderagent/src/main/config.json b/resourceschedule/resourceschedule_standard/reminderagent/src/main/config.json index 1c063ee9a..acc08fd68 100644 --- a/resourceschedule/resourceschedule_standard/reminderagent/src/main/config.json +++ b/resourceschedule/resourceschedule_standard/reminderagent/src/main/config.json @@ -1,6 +1,6 @@ { "app": { - "bundleName": "ohos.acts.resourceschedule.reminderagentjs.function", + "bundleName": "ohos.acts.resourceschedule.reminderagent.js.function", "vendor": "example", "version": { "code": 1, @@ -13,7 +13,7 @@ }, "deviceConfig": {}, "module": { - "package": "ohos.acts.resourceschedule.reminderagentjs.function", + "package": "ohos.acts.resourceschedule.reminderagent.js.function", "name": ".MyApplication", "deviceType": [ "phone" @@ -36,7 +36,7 @@ ] } ], - "name": "ohos.acts.resourceschedule.reminderagentjs.function.MainAbility", + "name": "ohos.acts.resourceschedule.reminderagent.js.function.MainAbility", "icon": "$media:icon", "description": "$string:mainability_description", "label": "$string:app_name", diff --git a/resourceschedule/resourceschedule_standard/reminderagent/src/main/js/default/i18n/zh-CN.json b/resourceschedule/resourceschedule_standard/reminderagent/src/main/js/default/i18n/zh-CN.json index de6ee5748..096c4d3d6 100644 --- a/resourceschedule/resourceschedule_standard/reminderagent/src/main/js/default/i18n/zh-CN.json +++ b/resourceschedule/resourceschedule_standard/reminderagent/src/main/js/default/i18n/zh-CN.json @@ -1,6 +1,6 @@ { "strings": { "hello": "您好", - "world": "世界" + "world": "鸿蒙" } } \ No newline at end of file diff --git a/resourceschedule/resourceschedule_standard/reminderagent/src/main/js/default/test/ReminderAgentJs.test.js b/resourceschedule/resourceschedule_standard/reminderagent/src/main/js/default/test/ReminderAgentJs.test.js index 3284b65d6..bd3dd2bb4 100644 --- a/resourceschedule/resourceschedule_standard/reminderagent/src/main/js/default/test/ReminderAgentJs.test.js +++ b/resourceschedule/resourceschedule_standard/reminderagent/src/main/js/default/test/ReminderAgentJs.test.js @@ -15,69 +15,619 @@ // @ts-nocheck import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' -import deviceinfo from '@ohos.deviceInfo' +import router from '@system.router' +import notification from '@ohos.notification' +import reminderAgent from '@ohos.reminderAgent' describe('ReminderAgentTest', function () { - const MAX_CHARACTERS_NUM_ONE = 33; - const MAX_CHARACTERS_NUM_TWO = 65; - const MAX_CHARACTERS_NUM = 0; + const TRIGGER_TIME_IN_SECONDS = 100; - beforeAll(function() { + beforeAll(function () { /* * @tc.setup: setup invoked before all testcases */ - console.info('beforeAll caled') -}) + console.info('beforeAll caled') + }) -afterAll(function() { + afterAll(function () { /* * @tc.teardown: teardown invoked after all testcases */ - console.info('afterAll caled') -}) + console.info('afterAll caled') + }) -beforeEach(function() { + beforeEach(function () { /* * @tc.setup: setup invoked before each testcases */ - console.info('beforeEach caled') -}) + console.info('beforeEach caled') + }) + + afterEach(function () { -afterEach(function() { - /* * @tc.teardown: teardown invoked after each testcases */ - console.info('afterEach caled') -}) + console.info('afterEach caled') + }) console.info('start################################start'); - + /** - * @tc.number SUB_STARTUP_JS_DEVCEINFO_0100 - * @tc.name testGetDeviceType01 - * @tc.desc Get a string representing the device type. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_001 + * @tc.name testPublishReminderNorFun001 + * @tc.desc Publishes an agent-powered reminder with the promise function. */ - it('device_info_test_001', 0, function () { - console.info('device_info_test_001 start'); - let ret = false; - let deviceTypeInfo = deviceinfo.deviceType; - console.info('the value of the deviceType is :' + deviceTypeInfo); - - expect(deviceTypeInfo).assertInstanceOf('String'); - if (deviceTypeInfo != "" && deviceTypeInfo != null && deviceTypeInfo != undefined) { - ret = true; + it('testPublishReminderNorFun001', 0, async function (done) { + let timer = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, + triggerTimeInSeconds: TRIGGER_TIME_IN_SECONDS } - expect(ret).assertTrue() - console.info('device_info_test_001 : end'); + let expectId = -1; + reminderAgent.publishReminder(timer).then((reminderId) => { + expectId = reminderId + 1; + reminderAgent.publishReminder(timer).then((reminderId) => { + if (reminderId === expectId) { + expect(true).assertTrue(); + setTimeout(() => { + done(); + }, 500); + } + }, (error) => { + expect(false).assertTrue(); + setTimeout(() => { + done(); + }, 500); + }); + }); }) -}) + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_002 + * @tc.name testPublishReminderNorFun002 + * @tc.desc Publishes an agent-powered reminder with the callback function. + */ + it('testPublishReminderNorFun002', 0, async function (done) { + let timer = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, + triggerTimeInSeconds: TRIGGER_TIME_IN_SECONDS + } + let expectId = -1; + function reminderCallback(err, reminderId) { + expect(reminderId).assertEqual(expectId); + } + reminderAgent.publishReminder(timer, (err, reminderId) => { + expectId = reminderId + 1; + reminderAgent.publishReminder(timer, reminderCallback); + }) + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_003 + * @tc.name testAddNotificationSlotNorFun001 + * @tc.desc Adds a reminder notification slot with the callback function. + */ + it('testAddNotificationSlotNorFun001', 0, async function (done) { + function reminderCallback(err, data) { + let i = 0; + expect(0).assertEqual(i); + } + reminderAgent.addNotificationSlot(0, reminderCallback); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_004 + * @tc.name testAddNotificationSlotNorFun002 + * @tc.desc Adds a reminder notification slot with the promise function and null mySlot. + */ + it('testAddNotificationSlotNorFun002', 0, async function (done) { + let mySlot = null; + let promise = new Promise((resolve, reject) => { + reminderAgent.addNotificationSlot(mySlot).then((value) => { + resolve(); + }).catch(function (err) { + reject(); + console.info('error: ' + err.code); + } + ); + promise.then(() => { + }, err => { + let i = 0; + expect(0).assertEqual(i); + }).catch(res => { }); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_005 + * @tc.name testAddNotificationSlotNorFun003 + * @tc.desc Adds a reminder notification slot with the promise function and mySlot type 3. + */ + it('testAddNotificationSlotNorFun003', 0, async function (done) { + let mySlot = { + type: 3 + } + reminderAgent.addNotificationSlot(mySlot).then(() => { + expect(true).assertTrue(); + setTimeout(() => { + done(); + }, 500); + }, (error) => { + expect(false).assertTrue(); + setTimeout(() => { + done(); + }, 500); + }); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_006 + * @tc.name testAddNotificationSlotNorFun004 + * @tc.desc Adds a reminder notification slot with the promise function and mySlot more types. + */ + it('testAddNotificationSlotNorFun004', 0, async function (done) { + let mySlot0 = { + type: 0 + } + let mySlot1 = { + type: 1 + } + let mySlot2 = { + type: 2 + } + let mySlot3 = { + type: 3 + } + let mySlot4 = { + type: 4 + } + function reminderCallback(err, data) { + if (err) { + expect(true).assertTrue(); + } else { + expect(false).assertTrue(); + } + setTimeout(() => { + done(); + }, 500); + } + reminderAgent.addNotificationSlot(mySlot0, reminderCallback); + reminderAgent.addNotificationSlot(mySlot1, reminderCallback); + reminderAgent.addNotificationSlot(mySlot2, reminderCallback); + reminderAgent.addNotificationSlot(mySlot3, reminderCallback); + reminderAgent.addNotificationSlot(mySlot4, reminderCallback); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_007 + * @tc.name testGetValidRemindersNorFun001 + * @tc.desc Obtains all valid remindeers set by the current application. + */ + it('testGetValidRemindersNorFun001', 0, async function (done) { + let timer = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, + triggerTimeInSeconds: TRIGGER_TIME_IN_SECONDS + } + reminderAgent.publishReminder(timer).then((reminderId) => { + reminderAgent.getValidReminders().then((reminders) => { }); + setTimeout(() => { + reminderAgent.cancelAllReminders().then(() => { + reminderAgent.getValidReminders().then((reminders) => { + expect(0).assertEqual(reminders.length); + }); + }); + }, 1000); + }); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_008 + * @tc.name testCancelAllRemindersNorFun001 + * @tc.desc test cancel all reminders can cancel all exist reminders + */ + it('testCancelAllRemindersNorFun001', 0, async function (done) { + let timer = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, + triggerTimeInSeconds: TRIGGER_TIME_IN_SECONDS + } + reminderAgent.publishReminder(timer, (error, reminderId) => { + reminderAgent.getValidReminders((err, reminders) => { }); + setTimeout(() => { + reminderAgent.cancelAllReminders((err, data) => { + reminderAgent.getValidReminders().then((reminders) => { + expect(0).assertEqual(reminders.length); + }); + }); + }, 1000); + }); + done(); + }) + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_009 + * @tc.name testCancelRemindersNorFun001 + * @tc.desc test cancelReminder with not exit reminder. + */ + it('testCancelRemindersNorFun001', 0, async function (done) { + let timer = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, + triggerTimeInSeconds: TRIGGER_TIME_IN_SECONDS + } + let id = 1; + let publishlength = -1; + let cancellength = -1; + let firstdiff = -1; + reminderAgent.publishReminder(timer).then(() => { + reminderAgent.getValidReminders().then((reminders) => { + publishlength = reminders.length + }); + setTimeout(() => { + reminderAgent.cancelReminder(id).then(() => { + reminderAgent.getValidReminders().then((reminders) => { + cancellength = reminders.length + firstdiff = publishlength - cancellength; + if (firstdiff === 0) { + expect(0).assertEqual(firstdiff); + } + }); + }); + }, 1000); + }); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_010 + * @tc.name testCancelRemindersNorFun002 + * @tc.desc test cancel reminder with not exit reminder. + */ + it('testCancelRemindersNorFun002', 0, async function (done) { + let timer = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, + triggerTimeInSeconds: TRIGGER_TIME_IN_SECONDS + } + let id = 1; + let publishlength = -1; + let cancellength = -1; + let firstdiff = -1; + reminderAgent.publishReminder(timer).then(() => { + reminderAgent.getValidReminders((err, reminders) => { + publishlength = reminders.length; + }); + setTimeout(() => { + reminderAgent.cancelReminder(id, (err, data) => { + reminderAgent.getValidReminders((err, reminders) => { + cancellength = reminders.length; + firstdiff = publishlength - cancellength; + if (firstdiff === 0) { + expect(0).assertEqual(firstdiff); + } + }); + }); + }, 1000); + }); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_011 + * @tc.name testCancelRemindersNorFun003 + * @tc.desc test cancel reminder with exist reminder. + */ + it('testCancelRemindersNorFun003', 0, async function (done) { + let alarm = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM, + hour: 21, + minute: 14, + title: "this is title", + content: "this is content" + } + let publishlength = -1; + let cancellength = -1; + let firstdiff = -1; + reminderAgent.publishReminder(alarm, (err, reminderId) => { + reminderAgent.getValidReminders((err, reminders) => { + publishlength = reminders.length; + }); + setTimeout(() => { + reminderAgent.cancelReminder(reminderId, (err, data) => { + reminderAgent.getValidReminders((err, reminders) => { + cancellength = reminders.length; + firstdiff = publishlength - cancellength; + if (firstdiff === 0) { + expect(0).assertEqual(firstdiff); + } else if (firstdiff === 1) { + expect(1).assertEqual(firstdiff); + } + }); + }); + }, 1000); + }); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_012 + * @tc.name testCancelRemindersNorFun004 + * @tc.desc test cancel reminder with exist reminder with the promise function. + */ + it('testCancelRemindersNorFun004', 0, async function (done) { + let alarm = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM, + hour: 21, + minute: 14, + title: "this is title", + content: "this is content" + } + let publishlength = -1; + let cancellength = -1; + let firstdiff = -1; + reminderAgent.publishReminder(alarm, (err, reminderId) => { + reminderAgent.getValidReminders((err, reminders) => { + publishlength = reminders.length; + }); + setTimeout(() => { + reminderAgent.cancelReminder(reminderId).then(() => { + reminderAgent.getValidReminders((err, reminders) => { + cancellength = reminders.length; + firstdiff = publishlength - cancellength; + if (firstdiff === 0) { + expect(0).assertEqual(firstdiff); + } else if (firstdiff === 1) { + expect(1).assertEqual(firstdiff); + } + }); + }); + }, 1000); + }); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_013 + * @tc.name testGetValidRemindersNorFun002 + * @tc.desc test get valid reminders verify all the information is correct. + */ + it('testGetValidRemindersNorFun002', 0, async function (done) { + var alarm = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM, + hour: 21, + minute: 14, + title: "this is title", + content: "this is content" + } + var timer = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, + triggerTimeInSeconds: TRIGGER_TIME_IN_SECONDS + } + reminderAgent.publishReminder(timer, (error, reminderId) => { }); + reminderAgent.publishReminder(alarm, (error, reminderId) => { }); + setTimeout(() => { + reminderAgent.getValidReminders().then((reminders) => { + if (reminders.length >= 2) { + let i = 0; + expect(0).assertEqual(i); + } + }); + }, 1000); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_014 + * @tc.name testGetValidRemindersNorFun003 + * @tc.desc test get valid reminders verify all the information is correct with the callback function. + */ + it('testGetValidRemindersNorFun003', 0, async function (done) { + var alarm = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM, + hour: 21, + minute: 14, + title: "this is title", + content: "this is content" + } + var timer = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, + triggerTimeInSeconds: TRIGGER_TIME_IN_SECONDS + } + reminderAgent.publishReminder(timer, (error, reminderId) => { }); + reminderAgent.publishReminder(alarm, (error, reminderId) => { }); + setTimeout(() => { + reminderAgent.getValidReminders((err, reminders) => { + if (reminders.length >= 2) { + let i = 0; + expect(0).assertEqual(i); + } + }); + }, 1000); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_015 + * @tc.name testRemonveNotificationSlotNorFun001 + * @tc.desc test remove notification Slot with not exist slot. + */ + it('testRemonveNotificationSlotNorFun001', 0, async function (done) { + function reminderCallback(err, data) { + let i = 0; + expect(0).assertEqual(i); + } + reminderAgent.removeNotificationSlot(0, reminderCallback); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_016 + * @tc.name testRemonveNotificationSlotNorFun002 + * @tc.desc test remove notification Slot with not exist slot with the promise function. + */ + it('testRemonveNotificationSlotNorFun002', 0, async function (done) { + let promise = new Promise((resolve, reject) => { + reminderAgent.removeNotificationSlot(1).then(() => { + resolve(); + }); + reject(new Error('errr occurred.')); + }); + promise.then(() => { + }, err => { + let i = 0; + expect(0).assertEqual(i); + }).catch(res => { }); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_017 + * @tc.name testRemonveNotificationSlotNorFun003 + * @tc.desc test remove notification Slot with exist slot. + */ + it('testRemonveNotificationSlotNorFun003', 0, async function (done) { + let tarRemoveSlot = { + type: 1 + } + reminderAgent.addNotificationSlot(tarRemoveSlot.type, (err, data) => { + reminderAgent.removeNotificationSlot(tarRemoveSlot.type, (err, data) => { + expect(0).assertEqual(err.code); + }); + }); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_018 + * @tc.name testRemonveNotificationSlotNorFun004 + * @tc.desc test remove notification Slot with exist slot with the promise function. + */ + it('testRemonveNotificationSlotNorFun004', 0, async function (done) { + let tarRemoveSlot = { + type: 1 + } + reminderAgent.addNotificationSlot(tarRemoveSlot.type, (err, data) => { + reminderAgent.removeNotificationSlot(tarRemoveSlot.type).then(() => { + expect(0).assertEqual(err.code); + }); + }); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_019 + * @tc.name testGetValidRemindersNorFun004 + * @tc.desc test get valid reminders with promise function. + */ + it('testGetValidRemindersNorFun004', 0, async function (done) { + let timer = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, + triggerTimeInSeconds: 3 + } + reminderAgent.publishReminder(timer).then((reminderId) => { }); + setTimeout(() => { + reminderAgent.getValidReminders().then((reminders) => { + expect(0).assertEqual(reminders.length); + }); + }, 5000); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_020 + * @tc.name testGetValidRemindersNorFun005 + * @tc.desc test get valid reminders with the callback function. + */ + it('testGetValidRemindersNorFun005', 0, async function (done) { + let timer = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, + triggerTimeInSeconds: 3 + } + reminderAgent.publishReminder(timer).then((reminderId) => { }); + setTimeout(() => { + reminderAgent.getValidReminders((err, reminders) => { + expect(0).assertEqual(reminders.length); + }); + }, 5000); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_021 + * @tc.name testPublishReminderNorAlarmFun001 + * @tc.desc test publish reminder with a nomal alarm promise function. + */ + it('testPublishReminderNorAlarmFun001', 0, async function (done) { + let alarm = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM, + hour: 21, + minute: 14 + } + reminderAgent.publishReminder(alarm).then((reminderId) => { + if (reminderId) { + let i = 0; + expect(0).assertEqual(i); + } + }); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_022 + * @tc.name testPublishReminderNorAlarmFun002 + * @tc.desc test publish reminder with a nomal alarm callback function. + */ + it('testPublishReminderNorAlarmFun002', 0, async function (done) { + let alarm = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM, + hour: 21, + minute: 14 + } + function reminderCallback(err, reminderId) { + if (reminderId) { + let i = 0; + expect(0).assertEqual(i); + } + } + reminderAgent.publishReminder(alarm, reminderCallback); + done(); + }) + + /** + * @tc.number SUB_RESOURCESCHEDULE_REMINDER_AGENT_023 + * @tc.name testPublishReminderAbNorFun001 + * @tc.desc test publish reminder with max number limit of each application. + */ + it('testPublishReminderAbNorFun001', 0, async function (done) { + let timer = { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, + triggerTimeInSeconds: TRIGGER_TIME_IN_SECONDS + } + let maxLimitNumsOfApp = 30; + let firstId = 0; + let secondId = 0; + let diffId = 0 + for (let i = 0; i < maxLimitNumsOfApp; i++) { + (function (i) { + setTimeout(function () { + reminderAgent.publishReminder(timer).then((reminderId) => { + if (i === 0) { + firstId = reminderId + } + if (i === 29) { + secondId = reminderId + diffId = secondId - firstId + expect(29).assertEqual(diffId); + } + }); + }, 500 * i); + })(i); + } + done(); + }) + }) +}) -- GitLab