jest.mock("@/app/i18n/api", () => require("../../__mocks__/api.ts")); import { renderRouter } from "expo-router/testing-library"; import React from "react"; import { act, fireEvent, render, screen, waitFor, } from "@testing-library/react-native"; import { NavigationContainer, createNavigationContainerRef, } from "@react-navigation/native"; import TTNavStack from "../TTNavStack"; import { migrateDb } from "@/app/lib/db"; describe("Navigation", () => { beforeEach(async () => { await migrateDb("development", "up"); // Reset the navigation state before each test jest.useFakeTimers(); }); afterEach(async () => { await migrateDb("development", "down"); jest.clearAllMocks(); jest.useRealTimers(); }); it("Navigates to ConversationThread on language selection", async () => { const MockComponent = jest.fn(() => ); renderRouter( { index: MockComponent, }, { initialUrl: "/", } ); const languageSelectionText = await waitFor(() => screen.getByText(/.*I Speak French.*/i) ); act(() => { fireEvent.press(languageSelectionText); }); expect(await screen.findByText("Conversation Thread")).toBeOnTheScreen(); }); it("Navigates to Settings on settings selection", async () => { const MockComponent = jest.fn(() => ); renderRouter( { index: MockComponent, }, { initialUrl: "/", } ); const settingsButton = await waitFor(() => screen.getByText(/.*Settings.*/i) ); fireEvent.press(settingsButton); expect( await waitFor(() => screen.getByText(/Settings/i)) ).toBeOnTheScreen(); // expect(waitFor(() => screen.getByText(/Settings/i))).toBeTruthy() expect(screen.getByText("Settings")).toBeOnTheScreen(); }); });