1/* 2 * Copyright (c) 2021 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 mockCalendar() { 19 const CalendarEntityClass = class CalendarEntity { 20 constructor() { 21 console.warn('calendar.CalendarEntity.constructor interface mocked in the Previewer. How this interface works on' + 22 ' the Previewer may be different from that on a real device.'); 23 this.id = '[PC preview] unknown id'; 24 } 25 }; 26 CalendarEntityClass.ACC_TYPE_LOCAL = 'LOCAL'; 27 CalendarEntityClass.IS_SYNC_ADAPTER = 'caller_is_syncadapter'; 28 const AccountsClass = class Accounts extends CalendarEntityClass { 29 constructor() { 30 super(); 31 console.warn('calendar.Accounts.constructor interface mocked in the Previewer. How this interface works on' + 32 ' the Previewer may be different from that on a real device.'); 33 this.name = '[PC preview] unknown name'; 34 this.accName = '[PC preview] unknown accName'; 35 this.accType = '[PC preview] unknown accType'; 36 this.accColour = '[PC preview] unknown accColour'; 37 this.accDisplayName = '[PC preview] unknown accDisplayName'; 38 this.visible = '[PC preview] unknown visible'; 39 this.accTimezone = '[PC preview] unknown accTimezone'; 40 this.isSyncEvents = '[PC preview] unknown isSyncEvents'; 41 this.remindersType = '[PC preview] unknown remindersType'; 42 this.attendeeTypes = '[PC preview] unknown attendeeTypes'; 43 } 44 }; 45 AccountsClass.NAME = 'name'; 46 const EventsClass = class Events extends CalendarEntityClass { 47 constructor() { 48 super(); 49 console.warn('calendar.Events.constructor interface mocked in the Previewer. How this interface works on' + 50 ' the Previewer may be different from that on a real device.'); 51 this.accId = '[PC preview] unknown accId'; 52 this.title = '[PC preview] unknown title'; 53 this.description = '[PC preview] unknown description'; 54 this.eventPosition = '[PC preview] unknown eventPosition'; 55 this.eventStatus = '[PC preview] unknown eventStatus'; 56 this.eventStartTime = '[PC preview] unknown eventStartTime'; 57 this.eventEndTime = '[PC preview] unknown eventEndTime'; 58 this.duration = '[PC preview] unknown duration'; 59 this.isWholeDay = '[PC preview] unknown isWholeDay'; 60 this.availableStatus = '[PC preview] unknown availableStatus'; 61 this.hasAlarm = '[PC preview] unknown hasAlarm'; 62 this.recurRule = '[PC preview] unknown recurRule'; 63 this.recurDate = '[PC preview] unknown recurDate'; 64 this.initialId = '[PC preview] unknown initialId'; 65 this.hasAttendeeInfo = '[PC preview] unknown hasAttendeeInfo'; 66 } 67 }; 68 const InstancesClass = class Instances extends CalendarEntityClass { 69 constructor() { 70 super(); 71 console.warn('calendar.Instances.constructor interface mocked in the Previewer. How this interface works on' + 72 ' the Previewer may be different from that on a real device.'); 73 this.instanceBegin = '[PC preview] unknown instanceBegin'; 74 this.instanceEnd = '[PC preview] unknown instanceEnd'; 75 this.eventId = '[PC preview] unknown eventId'; 76 this.instanceStartDay = '[PC preview] unknown instanceStartDay'; 77 this.instanceEndDay = '[PC preview] unknown instanceEndDay'; 78 this.instanceStartMinute = '[PC preview] unknown instanceStartMinute'; 79 this.instanceEndMinute = '[PC preview] unknown instanceEndMinute'; 80 } 81 }; 82 const ParticipantsClass = class Participants extends CalendarEntityClass { 83 constructor() { 84 super(); 85 console.warn('calendar.Participants.constructor interface mocked in the Previewer. How this interface works on' + 86 ' the Previewer may be different from that on a real device.'); 87 this.eventId = '[PC preview] unknown eventId'; 88 this.participantName = '[PC preview] unknown participantName'; 89 this.participantEmail = '[PC preview] unknown participantEmail'; 90 this.participantRoleType = '[PC preview] unknown participantRoleType'; 91 this.participantType = '[PC preview] unknown participantType'; 92 this.participantStatus = '[PC preview] unknown participantStatus'; 93 } 94 }; 95 const RemindersClass = class Reminders extends CalendarEntityClass { 96 constructor() { 97 super(); 98 console.warn('calendar.Reminders.constructor interface mocked in the Previewer. How this interface works on' + 99 ' the Previewer may be different from that on a real device.'); 100 this.eventId = '[PC preview] unknown eventId'; 101 this.remindMinutes = '[PC preview] unknown remindMinutes'; 102 this.remindType = '[PC preview] unknown remindType'; 103 this.syncId = '[PC preview] unknown syncId'; 104 } 105 }; 106 const AppletEntityClass = class AppletEntity { 107 constructor() { 108 console.warn('calendar.AppletEntity.constructor interface mocked in the Previewer. How this interface works on' + 109 ' the Previewer may be different from that on a real device.'); 110 this.title = '[PC preview] unknown title'; 111 this.startTime = '[PC preview] unknown startTime'; 112 this.allDay = '[PC preview] unknown allDay'; 113 this.description = '[PC preview] unknown description'; 114 this.location = '[PC preview] unknown location'; 115 this.endTime = '[PC preview] unknown endTime'; 116 this.alarm = '[PC preview] unknown alarm'; 117 this.alarmOffset = '[PC preview] unknown alarmOffset'; 118 this.repeatInterval = '[PC preview] unknown repeatInterval'; 119 this.repeatEndTime = '[PC preview] unknown repeatEndTime'; 120 } 121 }; 122 const AppletRepeatEntityClass = class AppletRepeatEntity extends AppletEntityClass { 123 constructor() { 124 super(); 125 console.warn('calendar.AppletRepeatEntity.constructor interface mocked in the Previewer. How this interface works on' + 126 ' the Previewer may be different from that on a real device.'); 127 this.repeatInterval = '[PC preview] unknown repeatInterval'; 128 this.repeatEndTime = '[PC preview] unknown repeatEndTime'; 129 } 130 }; 131 const CalendarCollectionClass = class CalendarCollection { 132 constructor() { 133 this.handler = '[PC preview] unknown handler'; 134 this.close = function (...args) { 135 console.warn('calendar.CalendarCollection.close interface mocked in the Previewer. How this interface works on' + 136 ' the Previewer may be different from that on a real device.'); 137 }; 138 this.count = function (...args) { 139 console.warn('calendar.CalendarCollection.count interface mocked in the Previewer. How this interface works on the' + 140 ' Previewer may be different from that on a real device.'); 141 return paramMock.paramNumberMock; 142 }; 143 this.next = function (...args) { 144 console.warn('calendar.CalendarCollection.next interface mocked in the Previewer. How this interface works on the' + 145 ' Previewer may be different from that on a real device.'); 146 return new CalendarEntityClass(); 147 }; 148 this.hasNext = function (...args) { 149 console.warn('calendar.CalendarCollection.hasNext interface mocked in the Previewer. How this interface works on the' + 150 ' Previewer may be different from that on a real device.'); 151 return paramMock.paramBooleanMock; 152 }; 153 } 154 }; 155 const CalendarDataHelperClass = class CalendarDataHelper { 156 constructor() { 157 this.name = '[PC preview] unknown queryEntityName'; 158 this.query = function (...args) { 159 console.warn('calendar.CalendarDataHelper.query interface mocked in the Previewer. How this interface works on the' + 160 ' 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, new CalendarCollectionClass()); 164 } else { 165 return new Promise((resolve) => { 166 resolve(new CalendarCollectionClass()); 167 }); 168 } 169 }; 170 this.insert = function (...args) { 171 console.warn('calendar.CalendarDataHelper.insert interface mocked in the Previewer. How this interface works on the' + 172 ' 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, paramMock.paramBooleanMock); 176 } else { 177 return new Promise((resolve) => { 178 resolve(paramMock.paramBooleanMock); 179 }); 180 } 181 }; 182 this.update = function (...args) { 183 console.warn('calendar.CalendarDataHelper.update interface mocked in the Previewer. How this interface works on the' + 184 ' Previewer may be different from that on a real device.'); 185 const len = args.length; 186 if (typeof args[len - 1] === 'function') { 187 args[len - 1].call(this, paramMock.businessErrorMock); 188 } else { 189 return new Promise((resolve) => { 190 resolve(); 191 }); 192 } 193 }; 194 this.delete = function (...args) { 195 console.warn('calendar.CalendarDataHelper.delete interface mocked in the Previewer. How this interface works on the' + 196 ' Previewer may be different from that on a real device.'); 197 const len = args.length; 198 if (typeof args[len - 1] === 'function') { 199 if (typeof args[0] === 'number') { 200 args[len - 1].call(this, paramMock.businessErrorMock); 201 } else if (args[0] instanceof CalendarEntityClass) { 202 args[len - 1].call(this, paramMock.businessErrorMock); 203 } else { 204 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 205 } 206 } else { 207 if (typeof args[0] === 'number') { 208 return new Promise((resolve) => { 209 resolve(); 210 }); 211 } else if (args[0] instanceof CalendarEntityClass) { 212 return new Promise((resolve) => { 213 resolve(); 214 }); 215 } else { 216 return new Promise((resolve) => { 217 resolve(paramMock.paramNumberMock); 218 }); 219 } 220 } 221 }; 222 } 223 }; 224 CalendarDataHelperClass.creator = function (...args) { 225 console.warn('calendar.CalendarDataHelper.creator interface mocked in the Previewer. How this interface works on the' + 226 ' Previewer may be different from that on a real device.'); 227 return new CalendarDataHelperClass(); 228 }; 229 global.systemplugin.calendar = { 230 BaseColumns: { 231 COUNT: "_count", 232 ID: "_id" 233 }, 234 AccountColumns: { 235 ACC_COLOR: "calendar_color", 236 ACC_COLOR_INDEX: "calendar_color_index", 237 ACC_DISPLAY_NAME: "calendar_displayName", 238 VISIBLE: "visible", 239 ACC_TIME_ZONE: "calendar_timezone", 240 IS_SYNC_EVENTS: "sync_events", 241 REMINDERS_TYPE: "allowedReminders", 242 AVAILABILITY_STATUS: "allowedAvailability", 243 ATTENDEE_TYPES: "allowedAttendeeTypes", 244 IS_PRIMARY: "isPrimary" 245 }, 246 AccountSyncColumns: { 247 ACC_SYNC1: "cal_sync1", 248 ACC_SYNC2: "cal_sync2", 249 ACC_SYNC3: "cal_sync3", 250 ACC_SYNC4: "cal_sync4", 251 ACC_SYNC5: "cal_sync5", 252 ACC_SYNC6: "cal_sync6", 253 ACC_SYNC7: "cal_sync7", 254 ACC_SYNC8: "cal_sync8", 255 ACC_SYNC9: "cal_sync9", 256 ACC_SYNC10: "cal_sync10" 257 }, 258 EventsColumns: { 259 ACC_ID: "calendar_id", 260 TITLE: "title", 261 DESCRIPTION: "description", 262 EVENT_POSITION: "eventLocation", 263 EVENT_STATUS: "eventStatus", 264 EVENT_STATUS_TENTATIVE: 0, 265 EVENT_STATUS_CONFIRMED: 1, 266 EVENT_STATUS_CANCELED: 2, 267 OWNER_ATTENDEE_STATUS: "selfAttendeeStatus", 268 EXTEND_DATA1: "sync_data1", 269 EXTEND_DATA2: "sync_data2", 270 EXTEND_DATA3: "sync_data3", 271 EXTEND_DATA4: "sync_data4", 272 EXTEND_DATA5: "sync_data5", 273 EXTEND_DATA6: "sync_data6", 274 D_DATA7: "sync_data7", 275 EXTEND_DATA8: "sync_data8", 276 EXTEND_DATA9: "sync_data9", 277 EXTEND_DATA10: "sync_data10", 278 EVENT_START_TIME: "dtstart", 279 EVENT_END_TIME: "dtend", 280 DURATION: "duration", 281 START_TIMEZONE: "eventTimezone", 282 END_TIMEZONE: "eventEndTimezone", 283 IS_WHOLE_DAY: "allDay", 284 PERMISSION_LEVEL: "accessLevel", 285 PERMISSION_DEFAULT: 0, 286 PERMISSION_CONFIDENTIAL: 1, 287 PERMISSION_PRIVATE: 2, 288 PERMISSION_PUBLIC: 3, 289 AVAILABLE_STATUS: "availability", 290 STATUS_BUSY: 0, 291 STATUS_FREE: 1, 292 STATUS_TENTATIVE: 2, 293 HAS_ALARM: "hasAlarm", 294 HAS_EXTENDED_ATTRIBUTES: "hasExtendedProperties", 295 RECUR_RULE: "rrule", 296 RECUR_DATE: "rdate", 297 INITIAL_ID: "original_id", 298 INITIAL_SYNC_ID: "original_sync_id", 299 HAS_ATTENDEE_INFO: "hasAttendeeData", 300 ORGANIZER_EMAIL: "organizer" 301 }, 302 InstancesColumns: { 303 EVENT_ID: "event_id", 304 INSTANCE_START: "begin", 305 INSTANCE_END: "end", 306 INSTANCE_START_DAY: "startDay", 307 INSTANCE_END_DAY: "endDay", 308 INSTANCE_START_MINUTE: "startMinute", 309 INSTANCE_END_MINUTE: "endMinute" 310 }, 311 ParticipantsColumns: { 312 EVENT_ID: "event_id", 313 PARTICIPANT_NAME: "attendeeName", 314 PARTICIPANT_EMAIL: "attendeeEmail", 315 PARTICIPANT_ROLE_TYPE: "attendeeRelationship", 316 ROLE_NONE: 0, 317 ROLE_ATTENDEE: 1, 318 ROLE_ORGANIZER: 2, 319 ROLE_PERFORMER: 3, 320 ROLE_SPEAKER: 4, 321 PARTICIPANT_TYPE: "attendeeType", 322 TYPE_NONE: 0, 323 TYPE_REQUIRED: 1, 324 TYPE_OPTIONAL: 2, 325 TYPE_RESOURCE: 3, 326 PARTICIPANT_STATUS: "attendeeStatus", 327 PARTICIPANT_STATUS_NONE: 0, 328 PARTICIPANT_STATUS_ACCEPTED: 1, 329 PARTICIPANT_STATUS_DECLINED: 2, 330 PARTICIPANT_STATUS_INVITED: 3, 331 PARTICIPANT_STATUS_TENTATIVE: 4 332 }, 333 RemindersColumns: { 334 EVENT_ID: "event_id", 335 REMIND_MINUTES: "minutes", 336 REMIND_MINUTES_DEFAULT: -1, 337 REMIND_TYPE: "method", 338 TYPE_DEFAULT: 0, 339 TYPE_ALERT: 1, 340 TYPE_EMAIL: 2, 341 TYPE_SMS: 3, 342 TYPE_ALARM: 4 343 }, 344 SyncColumns: { 345 ACC_NAME: "account_name", 346 ACC_TYPE: "account_type", 347 SYNC_ID: "_sync_id", 348 DIRTY: "dirty", 349 CALLING_BUNDLE_NAME: "mutators", 350 DELETED: "deleted" 351 }, 352 queryEntityName: { 353 EVENTS: "EVENTS", 354 ACCOUNTS: "ACCOUNTS", 355 INSTANCES: "INSTANCES", 356 PARTICIPANTS: "PARTICIPANTS", 357 REMINDERS: "REMINDERS" 358 }, 359 CalendarEntity: CalendarEntityClass, 360 Accounts: AccountsClass, 361 Events: EventsClass, 362 Instances: InstancesClass, 363 Participants: ParticipantsClass, 364 Reminders: RemindersClass, 365 AppletEntity: AppletEntityClass, 366 AppletRepeatEntity: AppletRepeatEntityClass, 367 CalendarCollection: CalendarCollectionClass, 368 CalendarDataHelper: CalendarDataHelperClass, 369 addPhoneCalendar: function (...args) { 370 console.warn('calendar.addPhoneCalendar interface mocked in the Previewer. How this interface works on the' + 371 ' Previewer may be different from that on a real device.'); 372 const len = args.length; 373 if (typeof args[len - 1] === 'function') { 374 args[len - 1].call(this, paramMock.businessErrorMock); 375 } else { 376 return new Promise((resolve) => { 377 resolve(); 378 }); 379 } 380 }, 381 addPhoneRepeatCalendar: function (...args) { 382 console.warn('calendar.addPhoneRepeatCalendar interface mocked in the Previewer. How this interface works on the' + 383 ' Previewer may be different from that on a real device.'); 384 const len = args.length; 385 if (typeof args[len - 1] === 'function') { 386 args[len - 1].call(this, paramMock.businessErrorMock); 387 } else { 388 return new Promise((resolve) => { 389 resolve(); 390 }); 391 } 392 } 393 }; 394} 395