|
| 1 | +/** |
| 2 | + * E2E test — App Navigation |
| 3 | + * |
| 4 | + * Validates the 5-tab layout renders all tabs correctly and each |
| 5 | + * tab screen displays its expected content. |
| 6 | + */ |
| 7 | +import React from "react"; |
| 8 | +import { render } from "@testing-library/react-native"; |
| 9 | + |
| 10 | +/* ---- Mocks ---- */ |
| 11 | + |
| 12 | +jest.mock("expo-router", () => ({ |
| 13 | + useRouter: () => ({ push: jest.fn(), replace: jest.fn(), back: jest.fn() }), |
| 14 | + useSegments: () => [], |
| 15 | + useLocalSearchParams: () => ({}), |
| 16 | + Link: ({ children }: { children: React.ReactNode }) => children, |
| 17 | + Stack: { Screen: () => null }, |
| 18 | + Tabs: Object.assign( |
| 19 | + ({ children }: { children: React.ReactNode }) => children, |
| 20 | + { Screen: () => null }, |
| 21 | + ), |
| 22 | +})); |
| 23 | + |
| 24 | +jest.mock("~/lib/auth-client", () => ({ |
| 25 | + authClient: { |
| 26 | + useSession: () => ({ data: { user: { name: "Test User", email: "test@example.com" } } }), |
| 27 | + signOut: jest.fn().mockResolvedValue(undefined), |
| 28 | + }, |
| 29 | + reinitializeAuthClient: jest.fn(), |
| 30 | + getAuthBaseURL: () => "http://localhost:3000", |
| 31 | +})); |
| 32 | + |
| 33 | +jest.mock("~/hooks/useAppDiscovery", () => ({ |
| 34 | + useAppDiscovery: () => ({ |
| 35 | + apps: [ |
| 36 | + { id: "app_1", name: "CRM", label: "CRM", description: "Customer Relationship Management" }, |
| 37 | + { id: "app_2", name: "Inventory", label: "Inventory", description: "Inventory Management" }, |
| 38 | + ], |
| 39 | + isLoading: false, |
| 40 | + error: null, |
| 41 | + refetch: jest.fn(), |
| 42 | + }), |
| 43 | +})); |
| 44 | + |
| 45 | +jest.mock("~/hooks/useNotifications", () => ({ |
| 46 | + useNotifications: () => ({ |
| 47 | + notifications: [], |
| 48 | + unreadCount: 0, |
| 49 | + isLoading: false, |
| 50 | + error: null, |
| 51 | + fetchMore: jest.fn(), |
| 52 | + hasMore: false, |
| 53 | + markRead: jest.fn(), |
| 54 | + markAllRead: jest.fn(), |
| 55 | + registerDevice: jest.fn(), |
| 56 | + getPreferences: jest.fn(), |
| 57 | + updatePreferences: jest.fn(), |
| 58 | + refetch: jest.fn(), |
| 59 | + }), |
| 60 | +})); |
| 61 | + |
| 62 | +import HomeScreen from "~/app/(tabs)/index"; |
| 63 | +import SearchScreen from "~/app/(tabs)/search"; |
| 64 | +import AppsScreen from "~/app/(tabs)/apps"; |
| 65 | +import NotificationsScreen from "~/app/(tabs)/notifications"; |
| 66 | +import MoreScreen from "~/app/(tabs)/more"; |
| 67 | + |
| 68 | +describe("E2E: App Navigation — Tab Screens", () => { |
| 69 | + it("renders Home tab with dashboard cards", () => { |
| 70 | + const { getByText } = render(<HomeScreen />); |
| 71 | + |
| 72 | + expect(getByText("Dashboard")).toBeTruthy(); |
| 73 | + expect(getByText("Welcome back. Here's your overview.")).toBeTruthy(); |
| 74 | + expect(getByText("Monthly Sales")).toBeTruthy(); |
| 75 | + expect(getByText("Active Users")).toBeTruthy(); |
| 76 | + expect(getByText("Orders")).toBeTruthy(); |
| 77 | + expect(getByText("Revenue Growth")).toBeTruthy(); |
| 78 | + }); |
| 79 | + |
| 80 | + it("renders Home tab with metric values and trends", () => { |
| 81 | + const { getByText } = render(<HomeScreen />); |
| 82 | + |
| 83 | + expect(getByText("$120,000")).toBeTruthy(); |
| 84 | + expect(getByText("+12%")).toBeTruthy(); |
| 85 | + expect(getByText("8,420")).toBeTruthy(); |
| 86 | + expect(getByText("1,340")).toBeTruthy(); |
| 87 | + expect(getByText("-2.1%")).toBeTruthy(); |
| 88 | + }); |
| 89 | + |
| 90 | + it("renders Search tab with search input", () => { |
| 91 | + const { getByPlaceholderText, getByText } = render(<SearchScreen />); |
| 92 | + |
| 93 | + expect( |
| 94 | + getByPlaceholderText("Search objects, records..."), |
| 95 | + ).toBeTruthy(); |
| 96 | + expect( |
| 97 | + getByText("Search across all your objects and records"), |
| 98 | + ).toBeTruthy(); |
| 99 | + expect(getByText("Type to start searching")).toBeTruthy(); |
| 100 | + }); |
| 101 | + |
| 102 | + it("renders Apps tab with installed apps", () => { |
| 103 | + const { getByText } = render(<AppsScreen />); |
| 104 | + |
| 105 | + expect(getByText("Apps")).toBeTruthy(); |
| 106 | + expect(getByText("2 apps installed")).toBeTruthy(); |
| 107 | + expect(getByText("CRM")).toBeTruthy(); |
| 108 | + expect(getByText("Customer Relationship Management")).toBeTruthy(); |
| 109 | + expect(getByText("Inventory")).toBeTruthy(); |
| 110 | + }); |
| 111 | + |
| 112 | + it("renders Notifications tab with empty state", () => { |
| 113 | + const { getByText } = render(<NotificationsScreen />); |
| 114 | + |
| 115 | + expect(getByText("No Notifications")).toBeTruthy(); |
| 116 | + expect( |
| 117 | + getByText( |
| 118 | + "You're all caught up. New notifications will appear here.", |
| 119 | + ), |
| 120 | + ).toBeTruthy(); |
| 121 | + }); |
| 122 | + |
| 123 | + it("renders More tab with menu sections", () => { |
| 124 | + const { getByText } = render(<MoreScreen />); |
| 125 | + |
| 126 | + expect(getByText("Test User")).toBeTruthy(); |
| 127 | + expect(getByText("test@example.com")).toBeTruthy(); |
| 128 | + expect(getByText("Preferences")).toBeTruthy(); |
| 129 | + expect(getByText("Appearance")).toBeTruthy(); |
| 130 | + expect(getByText("Language")).toBeTruthy(); |
| 131 | + expect(getByText("Security")).toBeTruthy(); |
| 132 | + expect(getByText("Security & Privacy")).toBeTruthy(); |
| 133 | + expect(getByText("Settings")).toBeTruthy(); |
| 134 | + expect(getByText("Support")).toBeTruthy(); |
| 135 | + expect(getByText("Help & Support")).toBeTruthy(); |
| 136 | + expect(getByText("About")).toBeTruthy(); |
| 137 | + expect(getByText("Sign Out")).toBeTruthy(); |
| 138 | + }); |
| 139 | +}); |
0 commit comments