• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { paramMock } from "../utils"
17
18export function mockReminderAgent() {
19  const infoMock = {
20    reminderId: "[PC preview] unknown reminderId",
21    info: "[PC preview] unknown info"
22  }
23  const reminderReq = {
24    reminderType: "[PC preview] unknown reminderType",
25    actionButton: [
26      {
27        title: "[PC preview] unknown title",
28        type: "[PC preview] unknown type"
29      }
30    ],
31    wantAgent: {
32      pkgName: "[PC preview] unknown pkg nam",
33      abilityName: "[PC preview] unknown ability name"
34    },
35    maxScreenWantAgent: {
36      pkgName: "[PC preview] unknown pkg name",
37      abilityName: "[PC preview] unknown ability name"
38    },
39    ringDuration: "[PC preview] unknown ringDuration",
40    snoozeTimes: "[PC preview] unknown snoozeTimes",
41    timeInterval: "[PC preview] unknown timeInterval",
42    title: "[PC preview] unknown title",
43    content: "[PC preview] unknown content",
44    expiredContent: "[PC preview] unknown expiredContent",
45    snoozeContent: "[PC preview] unknown snoozeContent",
46    notificationId: "[PC preview] unknown notificationId",
47    slotType: "[PC preview] unknown slotType"
48  }
49  const reminderReqs = [
50    reminderReq
51  ]
52  const ActionButton = {
53    title: "[PC preview] unknown title",
54    type: "[PC preview] unknown type"
55  }
56  const WantAgent = {
57    pkgName: "[PC preview] unknown pkgName",
58    abilityName: "[PC preview] unknown abilityName"
59  }
60  const MaxScreenWantAgent = {
61    pkgName: "[PC preview] unknown pkgName",
62    abilityName: "[PC preview] unknown abilityName"
63  }
64  const ReminderRequest = {
65    reminderType: "[PC preview] unknown reminderType",
66    actionButton: ActionButton,
67    wantAgent: WantAgent,
68    maxScreenWantAgent: MaxScreenWantAgent,
69    ringDuration: "[PC preview] unknown ringDuration",
70    snoozeTimes: "[PC preview] unknown snoozeTimes",
71    timeInterval: "[PC preview] unknown timeInterval",
72    title: "[PC preview] unknown title",
73    content: "[PC preview] unknown content",
74    expiredContent: "[PC preview] unknown expiredContent",
75    snoozeContent: "[PC preview] unknown snoozeContent",
76    notificationId: "[PC preview] unknown notificationId",
77    slotType: "[PC preview] unknown slotType"
78  }
79  const ReminderRequestCalendar = {
80    dateTime: LocalDateTime,
81    repeatMonths: "[PC preview] unknown repeatMonths",
82    repeatDays: "[PC preview] unknown repeatDays"
83  }
84  const ReminderRequestAlarm = {
85    hour: "[PC preview] unknown hour",
86    minute: "[PC preview] unknown minute",
87    daysOfWeek: "[PC preview] unknown daysOfWeek"
88  }
89  const ReminderRequestTimer = {
90    triggerTimeInSeconds: "[PC preview] unknown triggerTimeInSeconds"
91  }
92  const LocalDateTime = {
93    year: "[PC preview] unknown year",
94    month: "[PC preview] unknown month",
95    day: "[PC preview] unknown day",
96    hour: "[PC preview] unknown hour",
97    minute: "[PC preview] unknown minute",
98    second: "[PC preview] unknown second"
99  }
100  const reminderAgent = {
101    ActionButtonType: {
102      ACTION_BUTTON_TYPE_CLOSE: 0,
103      ACTION_BUTTON_TYPE_SNOOZE: 1
104    },
105    ReminderType: {
106      REMINDER_TYPE_TIMER: 0,
107      REMINDER_TYPE_CALENDAR: 1,
108      REMINDER_TYPE_ALARM: 2
109    },
110    publishReminder: function (...args) {
111      console.warn("reminderAgent.publishReminder interface mocked in the Previewer." +
112        "How this interface works on the Previewer may be different from that on a real device.")
113      const len = args.length
114      if (typeof args[len - 1] === 'function') {
115        args[len - 1].call(this, paramMock.businessErrorMock, infoMock.reminderId)
116      } else {
117        return new Promise((resolve) => {
118          resolve(infoMock.reminderId)
119        });
120      }
121    },
122    getValidReminders: function (...args) {
123      console.warn("reminderAgent.getValidReminders interface mocked in the Previewer." +
124        "How this interface works on the Previewer may be different from that on a real device.")
125      const len = args.length
126      if (typeof args[len - 1] === 'function') {
127        args[len - 1].call(this, paramMock.businessErrorMock, reminderReqs)
128      } else {
129        return new Promise((resolve) => {
130          resolve(reminderReqs)
131        });
132      }
133    },
134    cancelReminder: function (...args) {
135      console.warn("reminderAgent.cancelReminder interface mocked in the Previewer." +
136        "How this interface works on the Previewer may be different from that on a real device.")
137      const len = args.length
138      if (typeof args[len - 1] === 'function') {
139        args[len - 1].call(this, paramMock.businessErrorMock)
140      } else {
141        return new Promise((resolve) => {
142          resolve()
143        });
144      }
145    },
146    cancelAllReminders: function (...args) {
147      console.warn("reminderAgent.cancelAllReminders interface mocked in the Previewer." +
148        "How this interface works on the Previewer may be different from that on a real device.")
149      const len = args.length
150      if (typeof args[len - 1] === 'function') {
151        args[len - 1].call(this, paramMock.businessErrorMock)
152      } else {
153        return new Promise((resolve) => {
154          resolve()
155        });
156      }
157    },
158    addNotificationSlot: function (...args) {
159      console.warn("reminderAgent.addNotificationSlot interface mocked in the Previewer." +
160        "How this interface works on the Previewer may be different from that on a real device.")
161      const len = args.length
162      if (typeof args[len - 1] === 'function') {
163        args[len - 1].call(this, paramMock.businessErrorMock)
164      } else {
165        return new Promise((resolve) => {
166          resolve()
167        });
168      }
169    },
170    removeNotificationSlot: function (...args) {
171      console.warn("reminderAgent.removeNotificationSlot interface mocked in the Previewer." +
172        "How this interface works on the Previewer may be different from that on a real device.")
173      const len = args.length
174      if (typeof args[len - 1] === 'function') {
175        args[len - 1].call(this, paramMock.businessErrorMock)
176      } else {
177        return new Promise((resolve) => {
178          resolve()
179        });
180      }
181    }
182  }
183  return reminderAgent
184}