For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /api/testing-library/fakes/people.md.

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.

await render(Invite);
fireEvent.tap(screen.getByText('Invite a friend'));
answerContactPicker({ name: 'Ada', phones: ['+1 555 0100'] });
await waitForUpdate();

expect(screen.getByText('Inviting Ada at +1 555 0100')).toBeInTheDocument();

A FakeContact is a name, with any of id, phones, emails and postalAddresses.

answerContactPicker()

function answerContactPicker(
  contact: FakeContact | null,
  options?: { value?: string; nameOnly?: boolean },
): void;

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:

  • phone or email: one of the contact's numbers or addresses, its first or value.
    • 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 ContactsError of code failed whose 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: true to answer as Android does for an app that can't: the id and name, with empty lists.

failContactPicker()

function failContactPicker(
  code: 'unavailable' | 'failed',
  message?: string,
): void;

Ends the open picker, or the next one, with a ContactsError of that code.

contactPicker()

function contactPicker(): { select: 'contact' | 'phone' | 'email' } | undefined;

Says whether a picker is open, and what it asked the person to pick.

addContact()

function addContact(
  contact: FakeContact,
  options?: { shared?: boolean },
): Contact;

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()

function setContactsPermission(
  permission: 'granted' | 'limited' | 'denied' | 'undetermined' | 'unsupported',
): void;

Sets what the person answered.

  • limited has getAll() read only the shared contacts.
  • denied rejects it with permission-denied.
  • unsupported rejects it with unavailable, as in an app without permissions.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()

function calendarEvents(): readonly CalendarSheetEvent[];

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.

fireEvent.tap(screen.getByText('Add to calendar'));
await waitForUpdate();

expect(calendarEvents()).toEqual([
  expect.objectContaining({ title: 'Table for 2' }),
]);

answerCalendarSheet()

function answerCalendarSheet(result?: 'saved' | 'canceled' | 'unknown'): void;

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()

function failCalendarSheet(
  code: 'unavailable' | 'failed',
  message?: string,
): void;

Ends the open addEvent(), or the next one, with a CalendarError of code: unavailable for a phone without an editor, or failed.

failCalendarSheet('unavailable');
fireEvent.tap(screen.getByText('Add to calendar'));
await waitForUpdate();

expect(screen.getByText('Email me the booking')).toBeInTheDocument();

Types

TypeDescription
FakeContactA contact for answerContactPicker() and addContact()
AnswerContactPickerOptionsanswerContactPicker()'s options: value and nameOnly
AddContactOptionsaddContact()'s options: shared
FakeContactPickerInfoWhat contactPicker() returns while a picker is open
FakeContactsPermissionWhat setContactsPermission() takes
CalendarSheetEventOne of calendarEvents()
CalendarSheetAnswerWhat answerCalendarSheet() takes
CalendarSheetFailureThe codes failCalendarSheet() takes