Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .maestro/auth/login-with-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
- launchApp
- runFlow:
when:
visible: Obytes Starter
visible: React Native Template
file: ../utils/onboarding.yaml
- assertVisible: Sign In
- assertVisible:
Expand Down
6 changes: 3 additions & 3 deletions .maestro/auth/onboarding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ appId: ${APP_ID}
---
- clearState
- launchApp
- assertVisible: Obytes Starter
- assertVisible: "Let's Get Started "
- tapOn: "Let's Get Started "
- assertVisible: React Native Template
- assertVisible: "Let's Get Started"
- tapOn: "Let's Get Started"
- assertVisible: Sign In
2 changes: 2 additions & 0 deletions .maestro/config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
flows:
- auth/*
- app/*
- deep-links/*

excludeTags:
- util
- universal-link # needs a verified host, run with `maestro test --include-tags=universal-link -e UL_HOST=<host>`

executionOrder:
continueOnFailure: false # default is true
Expand Down
21 changes: 21 additions & 0 deletions .maestro/deep-links/first-launch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
appId: ${APP_ID}
env:
LINK: ${SCHEME}://feed/42?ref=email&utm=a%20b
---
# A link opened on a fresh install goes through onboarding and sign-in before it opens
# A password manager prompt left by a previous run would cover the app
- runFlow: ../utils/dismiss-password-prompt.yaml
- clearState
- openLink: ${LINK}
- assertVisible: React Native Template
- tapOn: Let's Get Started
- assertVisible:
id: login-notice
- runFlow: ../utils/submit-login.yaml
- runFlow: ../utils/assert-post-opened.yaml
- assertVisible:
id: post-params
text: '.*ref.*email.*'
- assertVisible:
id: post-params
text: '.*utm.*a b.*'
50 changes: 50 additions & 0 deletions .maestro/deep-links/return-to.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
appId: ${APP_ID}
env:
LINK: ${SCHEME}://feed/42?ref=email&utm=a%20b
---
# A prompt left by a previous run would cover the app
- runFlow: ../utils/dismiss-password-prompt.yaml
- clearState
# Finish onboarding, then close the app so the link below is a cold start
- launchApp
- runFlow: ../utils/onboarding.yaml
- assertVisible: Sign In
- stopApp

# Logged out, cold start: sign-in asks for the login, then opens the post with its params
- openLink: ${LINK}
- assertVisible:
id: login-notice
- runFlow: ../utils/submit-login.yaml
- runFlow: ../utils/assert-post-opened.yaml
- assertVisible:
id: post-params
text: '.*ref.*email.*'
- assertVisible:
id: post-params
text: '.*utm.*a b.*'

# Logged in: the same link opens the post straight away
- stopApp
- openLink: ${LINK}
- assertVisible:
id: post-id
text: 'id: 42'
- assertNotVisible:
id: login-notice

# Logged out, warm start: log out, open the link while the app is running
- launchApp
- tapOn:
id: settings-tab
- scroll
- tapOn: Logout
- assertVisible: Sign In
- openLink: ${LINK}
- assertVisible:
id: login-notice
- runFlow: ../utils/submit-login.yaml
- runFlow: ../utils/assert-post-opened.yaml
- assertVisible:
id: post-params
text: '.*ref.*email.*'
25 changes: 25 additions & 0 deletions .maestro/deep-links/universal-link.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
appId: ${APP_ID}
env:
LINK: https://${UL_HOST}/feed/42?ref=email&utm=a%20b
tags:
- universal-link
---
# Needs a host verified for the app (assetlinks.json / apple-app-site-association hosted there), passed with -e UL_HOST=<host>
# A password manager prompt left by a previous run would cover the app
- runFlow: ../utils/dismiss-password-prompt.yaml
- clearState
- launchApp
- runFlow: ../utils/onboarding.yaml
- assertVisible: Sign In
- stopApp
- openLink: ${LINK}
- assertVisible:
id: login-notice
- runFlow: ../utils/submit-login.yaml
- runFlow: ../utils/assert-post-opened.yaml
- assertVisible:
id: post-params
text: '.*ref.*email.*'
- assertVisible:
id: post-params
text: '.*utm.*a b.*'
13 changes: 13 additions & 0 deletions .maestro/utils/assert-post-opened.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
appId: ${APP_ID}
tags:
- util
---
# A password prompt can appear at any moment after login and hide the app,
# so dismiss it and assert again instead of waiting a fixed time
- retry:
maxRetries: 3
commands:
- runFlow: ../utils/dismiss-password-prompt.yaml
- assertVisible:
id: post-id
text: 'id: 42'
15 changes: 15 additions & 0 deletions .maestro/utils/dismiss-password-prompt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
appId: ${APP_ID}
tags:
- util
---
# Password managers and the OS can show a "save password" prompt that covers the app
- runFlow:
when:
visible: No, thanks
commands:
- tapOn: No, thanks
- runFlow:
when:
visible: Not Now
commands:
- tapOn: Not Now
2 changes: 1 addition & 1 deletion .maestro/utils/onboarding-and-login.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tags:
---
- runFlow:
when:
visible: Obytes Starter
visible: React Native Template
file: onboarding.yaml
- runFlow:
when:
Expand Down
6 changes: 3 additions & 3 deletions .maestro/utils/onboarding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ appId: ${APP_ID}
tags:
- util
---
- assertVisible: Obytes Starter
- assertVisible: "Let's Get Started "
- tapOn: "Let's Get Started "
- assertVisible: React Native Template
- assertVisible: "Let's Get Started"
- tapOn: "Let's Get Started"
- assertVisible: Sign In
15 changes: 15 additions & 0 deletions .maestro/utils/submit-login.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
appId: ${APP_ID}
tags:
- util
---
# EMAIL and PASSWORD must be passed with `maestro test -e EMAIL=... -e PASSWORD=...`
- tapOn:
id: email-input
- inputText: ${EMAIL}
- runFlow: ../utils/hide-keyboard.yaml
- tapOn:
id: password-input
- inputText: ${PASSWORD}
- runFlow: ../utils/hide-keyboard.yaml
- tapOn:
id: login-button
4 changes: 3 additions & 1 deletion REVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Code review guidelines for human teammates and AI agents. All categories are gro

- Auth state and token management must not live in screen components. Business logic belongs in `src/components/providers/auth.tsx`; routing guards belong in `src/app/_layout.tsx`.
- Tokens must be stored exclusively via `storeTokens()` and read via `getTokenDetails()` from `src/components/providers/auth.tsx`. Never store auth tokens in plain React state, `AsyncStorage`, or the general `storage` instance from `src/lib/storage.tsx`.
- All routes that require a logged-in user must be inside the `(app)/` group, wrapped in `Stack.Protected` with `guard={isAuthenticated}` in `src/app/_layout.tsx`. Never replicate this guard inside individual screen files.
- All routes that require a logged-in user must be declared under the `Stack.Protected` with `guard={isAuthenticated}` in `src/app/_layout.tsx`, either through the `(app)/` group or as a stack screen of their own (e.g. `feed/[id]`). Never replicate this guard inside individual screen files.
- Screens under the authenticated and logged-out guards are rendered from `AUTHENTICATED_SCREENS` / `AUTH_SCREENS` in `src/lib/auth/deep-link-path.ts`. Add, move or remove a guarded screen there (and its options in `GUARDED_SCREEN_OPTIONS` in `src/app/_layout.tsx`), never as a hand-written `Stack.Screen` inside those guards.
- Pending deep links are only stored by `rememberProtectedLink()` in `src/app/+native-intent.tsx` (called by `redirectSystemPath` on native, and once at startup from `src/app/_layout.tsx` on web) and only opened by `useOpenPendingDeepLink` in `src/app/_layout.tsx`, which pushes them on top of the tabs once the user is authenticated. Always store and push the path `toReturnToPath()` returns, never the raw link, so the screen that opens is the one that was checked. The guards always redirect an authenticated user to `/`, never to the pending link, so the linked screen keeps a back stack. For a logged-out user, `+native-intent` must return the guard's fallback route instead of a protected link, so the protected screen is never pushed; the `Stack.Protected` guards alone redirect only after the screen is mounted. Never navigate to a pending link directly from a screen. Only routes listed in `AUTHENTICATED_SCREENS` or `APP_TAB_SCREENS` can become a return-to target, so a new route file must be added to one of those lists, `AUTH_SCREENS`, or the public list in the route classification test.
- Verify that API calls are not triggered before `ready === true` from `AuthProvider`. Until `ready` is true, the auth state is not yet hydrated from MMKV.
- Token expiry must be evaluated using `dayjs` comparison against the ISO string stored in `authStorage` — do not compare raw Unix timestamps or use `Date` directly.

Expand Down
32 changes: 1 addition & 31 deletions __tests__/app/_layout.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SplashScreen, Tabs } from 'expo-router';
import { Tabs } from 'expo-router';

import TabLayout from '@/app/(app)/_layout';
import { useAuth } from '@/components/providers/auth';
Expand Down Expand Up @@ -30,9 +30,6 @@ jest.mock('expo-router', () => {
},
Tabs: MockTabs,
Link: ({ children }: { children: React.ReactNode }) => children,
SplashScreen: {
hideAsync: jest.fn().mockResolvedValue(undefined),
},
};
});

Expand All @@ -46,7 +43,6 @@ const mockUseAuth = useAuth as jest.MockedFunction<typeof useAuth>;
const mockUseIsFirstTime = useIsFirstTime as jest.MockedFunction<
typeof useIsFirstTime
>;
const mockSplashScreen = SplashScreen as jest.Mocked<typeof SplashScreen>;
const mockTabsScreen = Tabs.Screen as unknown as jest.Mock;

const tabOptions = (name: string) =>
Expand Down Expand Up @@ -110,32 +106,6 @@ describe('TabLayout', () => {
expect(mockUseAuth).toHaveBeenCalled();
});

it('should hide splash screen when auth is not ready', () => {
mockUseIsFirstTime.mockReturnValue([false, jest.fn()]);
mockUseAuth.mockReturnValue({
token: 'mock-token',
isAuthenticated: true,
loading: false,
ready: false,
logout: jest.fn(),
});
render(<TabLayout />);
expect(mockSplashScreen.hideAsync).toHaveBeenCalled();
});

it('should not hide splash screen when auth is ready', () => {
mockUseIsFirstTime.mockReturnValue([false, jest.fn()]);
mockUseAuth.mockReturnValue({
token: 'mock-token',
isAuthenticated: true,
loading: false,
ready: true,
logout: jest.fn(),
});
render(<TabLayout />);
expect(mockSplashScreen.hideAsync).not.toHaveBeenCalled();
});

it('should call useAuth and useIsFirstTime hooks', () => {
setupAuthenticatedUser();
render(<TabLayout />);
Expand Down
23 changes: 23 additions & 0 deletions __tests__/app/feed-post.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { cleanup, render, screen } from '@/lib/test-utils';

import Post from '@/app/feed/[id]';

const mockParams = jest.fn();

jest.mock('expo-router', () => ({
Stack: { Screen: () => null },
useIsFocused: () => true,
useLocalSearchParams: () => mockParams(),
}));

afterEach(cleanup);

describe('post screen', () => {
it('shows the id and the rest of the params', () => {
mockParams.mockReturnValue({ id: '42', ref: 'email', utm: 'a b', tag: ['x', 'y'] });
render(<Post />);

expect(screen.getByTestId('post-id')).toHaveTextContent('id: 42');
expect(screen.getByTestId('post-params')).toHaveTextContent('params: {"ref":"email","utm":"a b","tag":["x","y"]}');
});
});
Loading
Loading