Contact and calendar fakes
Pick a contact, fill the address book or answer the calendar's event editor in a unit test. import { answerContactPicker, addContact, answerCalendarSheet } from '@blotch/angular-lynx-testing-library';
Contacts
Fakes LynxContacts' two native modules: the address book and the picker.
Each test starts with an empty address book and no picker open. The person hasn't been asked yet: the first getAll() asks, and they allow it.
A FakeContact is a name, with any of id, phones, emails and postalAddresses.
answerContactPicker()
Closes the open picker as the person would, or queues the answer for the next one. null closes it without picking.
It picks as the phones do, for the select the app asked for:
phoneoremail: one of the contact's numbers or addresses, its first orvalue.- It throws for a contact without one, which the real picker won't let the person tap.
- A queued answer can't throw in the spec. The picker it answers fails instead, with a
ContactsErrorof codefailedwhose message says why.
contact: the whole contact, as iOS hands it over, and Android to an app that may read the address book.- Pass
nameOnly: trueto answer as Android does for an app that can't: the id and name, with empty lists.
- Pass
failContactPicker()
Ends the open picker, or the next one, with a ContactsError of that code.
contactPicker()
Says whether a picker is open, and what it asked the person to pick.
addContact()
Adds a contact to the address book getAll() reads. It returns the contact as the app gets it, with an id of its own unless it has one.
shared marks one the person shared under iOS 18's limited access.
setContactsPermission()
Sets what the person answered.
limitedhasgetAll()read only thesharedcontacts.deniedrejects it withpermission-denied.unsupportedrejects it withunavailable, as in an app withoutpermissions.contacts.- The picker needs no permission, so this doesn't change it.
- Set it before rendering.
permission()reads it at startup, and each time the app comes back.
Calendar
Fakes the event editor LynxCalendar.addEvent() opens. Until a spec answers it, the editor stays open.
calendarEvents()
The events the app opened the event editor with in this test, oldest first. Each test starts with none.
Each has title, start and end (as Dates), and allDay. It has location and notes when the app gave them.
answerCalendarSheet()
Closes the event editor as the person would: the open addEvent() resolves with result, saved by default.
- Called before the editor opens, it closes the next one as soon as it opens.
- Each call answers one editor, in order.
failCalendarSheet()
Ends the open addEvent(), or the next one, with a CalendarError of code: unavailable for a phone without an editor, or failed.
