<commit_before>import * as React from 'react';

import {
  getPendingDeepLink,
  addDeepLinkListener,
  loadApp,
} from '../../../native-modules/DevLauncherInternal';
import { render, act, waitFor, fireEvent } from '../../../test-utils';
import { DevSession } from '../../../types';
import { DeepLinkModal } from '../DeepLinkModal';

const mockGetPendingDeepLink = getPendingDeepLink as jest.Mock;
const mockAddDeepLinkListener = addDeepLinkListener as jest.Mock;
const mockLoadApp = loadApp as jest.Mock;

const fakeLocalDevSession: DevSession = {
  url: 'hello',
  description: 'fakeDevSessionDescription',
  source: 'test',
};

describe('<DeepLinkPrompt />', () => {
  afterEach(() => {
    mockGetPendingDeepLink.mockClear();
    mockAddDeepLinkListener.mockClear();
    mockLoadApp.mockClear();
  });

  test('retrieves pending deep link on mount and displays in modal', async () => {
    const fakeDeepLink = 'testing-testing-123';
    mockGetPendingDeepLink.mockResolvedValueOnce(fakeDeepLink);

    expect(getPendingDeepLink).not.toHaveBeenCalled();

    const { getByText, queryByText } = render(null);

    expect(queryByText(fakeDeepLink)).toBe(null);

    await act(async () => {
      expect(getPendingDeepLink).toHaveBeenCalled();
      await waitFor(() => getByText(fakeDeepLink));
    });
  });

  test('shows dev sessions in modal', async () => {
    const fakeDeepLink = 'testing-testing-123';
    mockGetPendingDeepLink.mockResolvedValueOnce(fakeDeepLink);

    const { getByText } = render(null, {
      initialAppProviderProps: { initialDevSessions: [fakeLocalDevSession] },
    });

    expect(queryByText(fakeLocalDevSession.description)).toBe(null);

    await act(async () => {
      await waitFor(() => getByText(/deep link received/i));
      getByText(fakeLocalDevSession.description);
    });
  });

  test('packagers in modal call loadApp() when pressed', async () => {
    const { getByText } = render(<DeepLinkModal pendingDeepLink="123" />, {
      initialAppProviderProps: { initialDevSessions: [fakeLocalDevSession] },
    });

    await act(async () => {
      expect(loadApp).not.toHaveBeenCalled();

      const button = await waitFor(() => getByText(fakeLocalDevSession.description));
      fireEvent.press(button);

      expect(loadApp).toHaveBeenCalled();
    });<commit_msg>[expo-dev-launcher] fix modal test (#15789)<commit_after>import * as React from 'react';

import {
  getPendingDeepLink,
  addDeepLinkListener,
  loadApp,
} from '../../../native-modules/DevLauncherInternal';
import { render, act, waitFor, fireEvent } from '../../../test-utils';
import { DevSession } from '../../../types';
import { DeepLinkModal } from '../DeepLinkModal';

const mockGetPendingDeepLink = getPendingDeepLink as jest.Mock;
const mockAddDeepLinkListener = addDeepLinkListener as jest.Mock;
const mockLoadApp = loadApp as jest.Mock;

const fakeLocalDevSession: DevSession = {
  url: 'hello',
  description: 'fakeDevSessionDescription',
  source: 'test',
};

describe('<DeepLinkPrompt />', () => {
  afterEach(() => {
    mockGetPendingDeepLink.mockClear();
    mockAddDeepLinkListener.mockClear();
    mockLoadApp.mockClear();
  });

  test('retrieves pending deep link on mount and displays in modal', async () => {
    const fakeDeepLink = 'testing-testing-123';
    mockGetPendingDeepLink.mockResolvedValueOnce(fakeDeepLink);

    expect(getPendingDeepLink).not.toHaveBeenCalled();

    const { getByText, queryByText } = render(null);

    expect(queryByText(fakeDeepLink)).toBe(null);

    await act(async () => {
      expect(getPendingDeepLink).toHaveBeenCalled();
      await waitFor(() => getByText(fakeDeepLink));
    });
  });

  test('shows dev sessions in modal', async () => {
    const fakeDeepLink = 'testing-testing-123';
    mockGetPendingDeepLink.mockResolvedValueOnce(fakeDeepLink);

    const { getByText, queryByText } = render(null, {
      initialAppProviderProps: { initialDevSessions: [fakeLocalDevSession] },
    });

    expect(queryByText(fakeLocalDevSession.description)).toBe(null);

    await act(async () => {
      await waitFor(() => getByText(/deep link received/i));
      getByText(fakeLocalDevSession.description);
    });
  });

  test('packagers in modal call loadApp() when pressed', async () => {
    const { getByText } = render(<DeepLinkModal pendingDeepLink="123" />, {
      initialAppProviderProps: { initialDevSessions: [fakeLocalDevSession] },
    });

    await act(async () => {
      expect(loadApp).not.toHaveBeenCalled();

      const button = await waitFor(() => getByText(fakeLocalDevSession.description));
      fireEvent.press(button);

      expect(loadApp).toHaveBeenCalled();
    });
{'fraction_non_alphanumeric': 0.14453709642933504, 'fraction_numerical': 0.004917682274962583, 'mean_word_length': 4.174778761061947, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4158202', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1385, 'n_words': 269}