• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 mockContact() {
19  const ContactClass = class Contact {
20    constructor() {
21      console.warn('contact.Contact.constructor interface mocked in the Previewer. How this interface' +
22        ' works on the Previewer may be different from that on a real device.');
23      this.id = "[PC Preview] unknow id";
24      this.key = "[PC Preview] unknow key";
25      this.contactAttributes = "[PC Preview] unknow contactAttributes";
26      this.emails = "[PC Preview] unknow emails";
27      this.events = "[PC Preview] unknow events";
28      this.groups = "[PC Preview] unknow groups";
29      this.imAddresses = "[PC Preview] unknow imAddresses";
30      this.phoneNumbers = "[PC Preview] unknow phoneNumbers";
31      this.portrait = "[PC Preview] unknow portrait";
32      this.postalAddresses = "[PC Preview] unknow postalAddresses";
33      this.relations = "[PC Preview] unknow relations";
34      this.sipAddresses = "[PC Preview] unknow sipAddresses";
35      this.websites = "[PC Preview] unknow websites";
36      this.name = "[PC Preview] unknow name";
37      this.nickName = "[PC Preview] unknow nickName";
38      this.note = "[PC Preview] unknow note";
39      this.organization = "[PC Preview] unknow organization";
40    }
41  }
42  ContactClass.INVALID_CONTACT_ID = -1;
43
44  const ContactAttributesClass = class ContactAttributes {
45    constructor() {
46      console.warn('contact.ContactAttributes.constructor interface mocked in the Previewer. How this interface' +
47        ' works on the Previewer may be different from that on a real device.');
48      this.attributes = ["[PC Preview] unknow Attribute"]
49    }
50  }
51  const EmailClass = class Email {
52    constructor() {
53      console.warn('contact.Email.constructor interface mocked in the Previewer. How this interface' +
54        ' works on the Previewer may be different from that on a real device.');
55      this.CUSTOM_LABEL = 0;
56      this.EMAIL_HOME = 1;
57      this.EMAIL_WORK = 2;
58      this.EMAIL_OTHER = 3;
59      this.INVALID_LABEL_ID = -1;
60      this.email = "[PC Preview] unknow email";
61      this.labelName = "[PC Preview] unknow labelName";
62      this.displayName = "[PC Preview] unknow displayName";
63      this.labelId = "[PC Preview] unknow labelId";
64    }
65  }
66  const EventClass = class Event {
67    constructor() {
68      console.warn('contact.Event.constructor interface mocked in the Previewer. How this interface' +
69        ' works on the Previewer may be different from that on a real device.');
70      this.CUSTOM_LABEL = 0;
71      this.EVENT_ANNIVERSARY = 1;
72      this.EVENT_OTHER = 2;
73      this.EVENT_BIRTHDAY = 3;
74      this.INVALID_LABEL_ID = -1;
75      this.eventDate = "[PC Preview] unknow eventDate";
76      this.labelName = "[PC Preview] unknow labelName";
77      this.labelId = "[PC Preview] unknow labelId";
78    }
79  }
80  const GroupClass = class Group {
81    constructor() {
82      console.warn('contact.Group.constructor interface mocked in the Previewer. How this interface' +
83        ' works on the Previewer may be different from that on a real device.');
84      this.groupId = "[PC Preview] unknow groupId";
85      this.title = "[PC Preview] unknow title";
86    }
87  }
88  const HolderClass = class Holder {
89    constructor() {
90      console.warn('contact.Holder.constructor interface mocked in the Previewer. How this interface' +
91        ' works on the Previewer may be different from that on a real device.');
92      this.bundleName = "[PC Preview] unknow bundleName";
93      this.displayName = "[PC Preview] unknow displayName";
94      this.holderId = "[PC Preview] unknow holderId";
95    }
96  }
97  const ImAddressClass = class ImAddress {
98    constructor() {
99      console.warn('contact.ImAddress.constructor interface mocked in the Previewer. How this interface' +
100        ' works on the Previewer may be different from that on a real device.');
101      this.CUSTOM_LABEL = -1;
102      this.IM_AIM = 0;
103      this.IM_MSN = 1;
104      this.IM_YAHOO = 2;
105      this.IM_SKYPE = 3;
106      this.IM_QQ = 4;
107      this.IM_ICQ = 6;
108      this.IM_JABBER = 7;
109      this.INVALID_LABEL_ID = -2;
110      this.imAddress = "[PC Preview] unknow imAddress";
111      this.labelName = "[PC Preview] unknow labelName";
112      this.labelId = "[PC Preview] unknow labelId";
113    }
114  }
115  const NameClass = class Name {
116    constructor() {
117      console.warn('contact.Name.constructor interface mocked in the Previewer. How this interface' +
118        ' works on the Previewer may be different from that on a real device.');
119      this.familyName = "[PC Preview] unknow familyName";
120      this.familyNamePhonetic = "[PC Preview] unknow familyNamePhonetic";
121      this.fullName = "[PC Preview] unknow fullName";
122      this.givenName = "[PC Preview] unknow givenName";
123      this.givenNamePhonetic = "[PC Preview] unknow givenNamePhonetic";
124      this.middleNamePhonetic = "[PC Preview] unknow middleNamePhonetic";
125      this.namePrefix = "[PC Preview] unknow namePrefix";
126      this.nameSuffix = "[PC Preview] unknow nameSuffix";
127      this.middleName = "[PC Preview] unknow middleName";
128    }
129  }
130  const NickNameClass = class NickName {
131    constructor() {
132      console.warn('contact.NickName.constructor interface mocked in the Previewer. How this interface' +
133        ' works on the Previewer may be different from that on a real device.');
134      this.nickName = "[PC Preview] unknow nickName";
135    }
136  }
137  const NoteClass = class Note {
138    constructor() {
139      console.warn('contact.Note.constructor interface mocked in the Previewer. How this interface' +
140        ' works on the Previewer may be different from that on a real device.');
141      this.noteContent = "[PC Preview] unknow noteContent";
142    }
143  }
144  const OrganizationClass = class Organization {
145    constructor() {
146      console.warn('contact.Organization.constructor interface mocked in the Previewer. How this interface' +
147        ' works on the Previewer may be different from that on a real device.');
148      this.name = "[PC Preview] unknow name";
149      this.title = "[PC Preview] unknow title";
150    }
151  }
152  const PhoneNumberClass = class PhoneNumber {
153    constructor() {
154      console.warn('contact.PhoneNumber.constructor interface mocked in the Previewer. How this interface' +
155        ' works on the Previewer may be different from that on a real device.');
156      this.CUSTOM_LABEL = 0;
157      this.NUM_HOME = 1;
158      this.NUM_MOBILE = 2;
159      this.NUM_WORK = 3;
160      this.NUM_FAX_WORK = 4;
161      this.NUM_FAX_HOME = 5;
162      this.NUM_PAGER = 6;
163      this.NUM_OTHER = 7;
164      this.NUM_CALLBACK = 8;
165      this.NUM_CAR = 9;
166      this.NUM_COMPANY_MAIN = 10;
167      this.NUM_ISDN = 11;
168      this.NUM_MAIN = 12;
169      this.NUM_OTHER_FAX = 13;
170      this.NUM_RADIO = 14;
171      this.NUM_TELEX = 15;
172      this.NUM_TTY_TDD = 16;
173      this.NUM_WORK_MOBILE = 17;
174      this.NUM_WORK_PAGER = 18;
175      this.NUM_ASSISTANT = 19;
176      this.NUM_MMS = 20;
177      this.INVALID_LABEL_ID = -1;
178      this.phoneNumber = "[PC Preview] unknow phoneNumber";
179      this.labelName = "[PC Preview] unknow labelName";
180      this.labelId = "[PC Preview] unknow labelId";
181    }
182  }
183  const PortraitClass = class Portrait {
184    constructor() {
185      console.warn('contact.Portrait.constructor interface mocked in the Previewer. How this interface' +
186        ' works on the Previewer may be different from that on a real device.');
187      this.uri = "[PC Preview] unknow uri";
188    }
189  }
190  const PostalAddressClass = class PostalAddress {
191    constructor() {
192      console.warn('contact.PostalAddress.constructor interface mocked in the Previewer. How this interface' +
193        ' works on the Previewer may be different from that on a real device.');
194      this.CUSTOM_LABEL = 0;
195      this.ADDR_HOME = 1;
196      this.ADDR_WORK = 2;
197      this.ADDR_OTHER = 3;
198      this.INVALID_LABEL_ID = -1;
199      this.city = "[PC Preview] unknow city";
200      this.country = "[PC Preview] unknow country";
201      this.labelName = "[PC Preview] unknow labelName";
202      this.neighborhood = "[PC Preview] unknow neighborhood";
203      this.pobox = "[PC Preview] unknow pobox";
204      this.postalAddress = "[PC Preview] unknow postalAddress";
205      this.postcode = "[PC Preview] unknow postcode";
206      this.region = "[PC Preview] unknow region";
207      this.street = "[PC Preview] unknow street";
208      this.labelId = "[PC Preview] unknow labelId";
209    }
210  }
211  const RelationClass = class Relation {
212    constructor() {
213      console.warn('contact.Relation.constructor interface mocked in the Previewer. How this interface' +
214        ' works on the Previewer may be different from that on a real device.');
215      this.CUSTOM_LABEL = 0;
216      this.RELATION_ASSISTANT = 1;
217      this.RELATION_BROTHER = 2;
218      this.RELATION_CHILD = 3;
219      this.RELATION_DOMESTIC_PARTNER = 4;
220      this.RELATION_FATHER = 5;
221      this.RELATION_FRIEND = 6;
222      this.RELATION_MANAGER = 7;
223      this.RELATION_MOTHER = 8;
224      this.RELATION_PARENT = 9;
225      this.RELATION_PARTNER = 10;
226      this.RELATION_REFERRED_BY = 11;
227      this.RELATION_RELATIVE = 12;
228      this.RELATION_SISTER = 13;
229      this.RELATION_SPOUSE = 14;
230      this.INVALID_LABEL_ID = -1;
231      this.relationName = "[PC Preview] unknow relationName";
232      this.labelName = "[PC Preview] unknow labelName";
233      this.labelId = "[PC Preview] unknow labelId";
234    }
235  }
236  const SipAddressClass = class SipAddress {
237    constructor() {
238      console.warn('contact.SipAddress.constructor interface mocked in the Previewer. How this interface' +
239        ' works on the Previewer may be different from that on a real device.');
240      this.CUSTOM_LABEL = 0;
241      this.SIP_HOME = 1;
242      this.SIP_WORK = 2;
243      this.SIP_OTHER = 3;
244      this.INVALID_LABEL_ID = -1;
245      this.sipAddress = "[PC Preview] unknow sipAddress";
246      this.labelName = "[PC Preview] unknow labelName";
247      this.labelId = "[PC Preview] unknow labelId";
248    }
249  }
250  const WebsiteClass = class Website {
251    constructor() {
252      console.warn('contact.Website.constructor interface mocked in the Previewer. How this interface' +
253        ' works on the Previewer may be different from that on a real device.');
254      this.website = "[PC Preview] unknow website";
255    }
256  }
257  const contact = {
258    Contact: ContactClass,
259    ContactAttributes: ContactAttributesClass,
260    Email: EmailClass,
261    Event: EventClass,
262    Group: GroupClass,
263    Holder: HolderClass,
264    ImAddress: ImAddressClass,
265    Name: NameClass,
266    NickName: NickNameClass,
267    Note: NoteClass,
268    Organization: OrganizationClass,
269    PhoneNumber: PhoneNumberClass,
270    Portrait: PortraitClass,
271    PostalAddress: PostalAddressClass,
272    Relation: RelationClass,
273    SipAddress: SipAddressClass,
274    Website: WebsiteClass,
275    Attribute:{
276      ATTR_CONTACT_EVENT: "[PC Preview] unknow ATTR_CONTACT_EVENT",
277      ATTR_EMAIL: "[PC Preview] unknow ATTR_EMAIL",
278      ATTR_GROUP_MEMBERSHIP: "[PC Preview] unknow ATTR_GROUP_MEMBERSHIP",
279      ATTR_IM: "[PC Preview] unknow ATTR_IM",
280      ATTR_NAME: "[PC Preview] unknow ATTR_NAME",
281      ATTR_NICKNAME: "[PC Preview] unknow ATTR_NICKNAME",
282      ATTR_NOTE: "[PC Preview] unknow ATTR_NOTE",
283      ATTR_ORGANIZATION: "[PC Preview] unknow ATTR_ORGANIZATION",
284      ATTR_PHONE: "[PC Preview] unknow ATTR_PHONE",
285      ATTR_PORTRAIT: "[PC Preview] unknow ATTR_PORTRAIT",
286      ATTR_POSTAL_ADDRESS: "[PC Preview] unknow ATTR_POSTAL_ADDRESS",
287      ATTR_RELATION: "[PC Preview] unknow ATTR_RELATION",
288      ATTR_SIP_ADDRESS: "[PC Preview] unknow ATTR_SIP_ADDRESS",
289      ATTR_WEBSITE: "[PC Preview] unknow ATTR_WEBSITE",
290    },
291    addContact: function (...args) {
292      console.warn("contact.addContact interface mocked in the Previewer. How this interface works on the" +
293        " Previewer may be different from that on a real device.")
294      const len = args.length
295      if (typeof args[len - 1] === 'function') {
296        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
297      } else {
298        return new Promise((resolve) => {
299          resolve(paramMock.paramNumberMock)
300        });
301      }
302    },
303    selectContact: function (...args) {
304      console.warn("contact.selectContact interface mocked in the Previewer. How this interface works on the" +
305        " Previewer may be different from that on a real device.")
306      var array = new Array();
307      array.push(new ContactClass());
308      const len = args.length
309      if (typeof args[len - 1] === 'function') {
310        args[len - 1].call(this, paramMock.businessErrorMock, array)
311      } else {
312        return new Promise((resolve) => {
313          resolve(array)
314        });
315      }
316    },
317    deleteContact: function (...args) {
318      console.warn("contact.deleteContact interface mocked in the Previewer. How this interface works on the" +
319        " Previewer may be different from that on a real device.")
320      const len = args.length
321      if (typeof args[len - 1] === 'function') {
322        args[len - 1].call(this, paramMock.businessErrorMock)
323      } else {
324        return new Promise((resolve) => {
325          resolve()
326        });
327      }
328    },
329    queryContact: function (...args) {
330      console.warn("contact.queryContact interface mocked in the Previewer. How this interface works on the" +
331        " Previewer may be different from that on a real device.")
332      const len = args.length
333      if (typeof args[len - 1] === 'function') {
334        args[len - 1].call(this, paramMock.businessErrorMock, new ContactClass())
335      } else {
336        return new Promise((resolve) => {
337          resolve(new ContactClass())
338        });
339      }
340    },
341    queryContacts: function (...args) {
342      console.warn("contact.queryContacts interface mocked in the Previewer. How this interface works on the" +
343        " Previewer may be different from that on a real device.")
344      var array = new Array();
345      array.push(new ContactClass());
346      const len = args.length
347      if (typeof args[len - 1] === 'function') {
348        args[len - 1].call(this, paramMock.businessErrorMock, array)
349      } else {
350        return new Promise((resolve) => {
351          resolve(array)
352        });
353      }
354    },
355    queryContactsByEmail: function (...args) {
356      console.warn("contact.queryContactsByEmail interface mocked in the Previewer. How this interface works on the" +
357        " Previewer may be different from that on a real device.")
358      var array = new Array();
359      array.push(new ContactClass());
360      const len = args.length
361      if (typeof args[len - 1] === 'function') {
362        args[len - 1].call(this, paramMock.businessErrorMock, array)
363      } else {
364        return new Promise((resolve) => {
365          resolve(array)
366        });
367      }
368    },
369    queryContactsByPhoneNumber: function (...args) {
370      console.warn("contact.queryContactsByPhoneNumber interface mocked in the Previewer. How this interface works on the" +
371        " Previewer may be different from that on a real device.")
372      var array = new Array();
373      array.push(new ContactClass());
374      const len = args.length
375      if (typeof args[len - 1] === 'function') {
376        args[len - 1].call(this, paramMock.businessErrorMock, array)
377      } else {
378        return new Promise((resolve) => {
379          resolve(array)
380        });
381      }
382    },
383    queryGroups: function (...args) {
384      console.warn("contact.queryGroups interface mocked in the Previewer. How this interface works on the" +
385        " Previewer may be different from that on a real device.")
386      var array = new Array();
387      array.push(new GroupClass());
388      const len = args.length
389      if (typeof args[len - 1] === 'function') {
390        args[len - 1].call(this, paramMock.businessErrorMock, array)
391      } else {
392        return new Promise((resolve) => {
393          resolve(array)
394        });
395      }
396    },
397    queryHolders: function (...args) {
398      console.warn("contact.queryHolders interface mocked in the Previewer. How this interface works on the" +
399        " Previewer may be different from that on a real device.")
400      var array = new Array();
401      array.push(new HolderClass());
402      const len = args.length
403      if (typeof args[len - 1] === 'function') {
404        args[len - 1].call(this, paramMock.businessErrorMock, array)
405      } else {
406        return new Promise((resolve) => {
407          resolve(array)
408        });
409      }
410    },
411    queryKey: function (...args) {
412      console.warn("contact.queryKey interface mocked in the Previewer. How this interface works on the" +
413        " Previewer may be different from that on a real device.")
414      const len = args.length
415      if (typeof args[len - 1] === 'function') {
416        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock)
417      } else {
418        return new Promise((resolve) => {
419          resolve(paramMock.paramStringMock)
420        });
421      }
422    },
423    queryMyCard: function (...args) {
424      console.warn("contact.queryMyCard interface mocked in the Previewer. How this interface works on the" +
425        " Previewer may be different from that on a real device.")
426      var array = new Array();
427      array.push(new ContactClass());
428      const len = args.length
429      if (typeof args[len - 1] === 'function') {
430        args[len - 1].call(this, paramMock.businessErrorMock, array)
431      } else {
432        return new Promise((resolve) => {
433          resolve(array)
434        });
435      }
436    },
437    updateContact: function (...args) {
438      console.warn("contact.updateContact interface mocked in the Previewer. How this interface works on the" +
439        " Previewer may be different from that on a real device.")
440      const len = args.length
441      if (typeof args[len - 1] === 'function') {
442        args[len - 1].call(this, paramMock.businessErrorMock)
443      } else {
444        return new Promise((resolve) => {
445          resolve()
446        });
447      }
448    },
449    isLocalContact: function (...args) {
450      console.warn("contact.isLocalContact interface mocked in the Previewer. How this interface works on the" +
451        " Previewer may be different from that on a real device.")
452      const len = args.length
453      if (typeof args[len - 1] === 'function') {
454        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
455      } else {
456        return new Promise((resolve) => {
457          resolve(paramMock.paramBooleanMock)
458        });
459      }
460    },
461    isMyCard: function (...args) {
462      console.warn("contact.isMyCard interface mocked in the Previewer. How this interface works on the" +
463        " Previewer may be different from that on a real device.")
464      const len = args.length
465      if (typeof args[len - 1] === 'function') {
466        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
467      } else {
468        return new Promise((resolve) => {
469          resolve(paramMock.paramBooleanMock)
470        });
471      }
472    }
473  }
474  return contact
475}
476