|
| 1 | +import normalizePath from '@libs/Navigation/helpers/normalizePath'; |
| 2 | +import {getRouteFromLink} from '@libs/ReportUtils'; |
| 3 | +import SCREENS from '@src/SCREENS'; |
| 4 | + |
| 5 | +/** |
| 6 | + * Regression test for https://github.com/Expensify/App/issues/90880 |
| 7 | + * |
| 8 | + * When a user visits the root URL (new.expensify.com), refreshes, and signs in, |
| 9 | + * React Navigation generates a /Home route (capitalized) because PublicScreens uses |
| 10 | + * SCREENS.HOME ('Home') at the root level without a path mapping. This route doesn't |
| 11 | + * exist in the authenticated navigation tree, causing a "not found" page. |
| 12 | + * |
| 13 | + * The fix in openReportFromDeepLink normalizes /Home to an empty route (same as /). |
| 14 | + * These tests document the behavior that makes the guard necessary. |
| 15 | + */ |
| 16 | +describe('Deeplink route normalization', () => { |
| 17 | + describe('getRouteFromLink with root URLs', () => { |
| 18 | + it('Should return empty string for null URL', () => { |
| 19 | + expect(getRouteFromLink(null)).toBe(''); |
| 20 | + }); |
| 21 | + |
| 22 | + it('Should return empty string for root URL with trailing slash', () => { |
| 23 | + expect(getRouteFromLink('https://new.expensify.com/')).toBe(''); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + describe('Home route normalization guard', () => { |
| 28 | + // This test documents the exact condition checked in openReportFromDeepLink: |
| 29 | + // if (normalizePath(route) === `/${SCREENS.HOME}`) { route = ''; } |
| 30 | + it('Should detect Home route that needs normalization to empty string', () => { |
| 31 | + const route = 'Home'; |
| 32 | + // normalizePath adds leading slash, producing /Home |
| 33 | + expect(normalizePath(route)).toBe('/Home'); |
| 34 | + // The guard matches against /${SCREENS.HOME} |
| 35 | + expect(normalizePath(route)).toBe(`/${SCREENS.HOME}`); |
| 36 | + // This confirms the guard would trigger and reset route to '' |
| 37 | + }); |
| 38 | + |
| 39 | + it('Should not trigger for other valid routes', () => { |
| 40 | + const validRoutes = ['r/123456789', 'settings/profile', 'search']; |
| 41 | + for (const route of validRoutes) { |
| 42 | + expect(normalizePath(route)).not.toBe(`/${SCREENS.HOME}`); |
| 43 | + } |
| 44 | + }); |
| 45 | + |
| 46 | + it('Should not trigger for empty route (already correct)', () => { |
| 47 | + expect(normalizePath('')).not.toBe(`/${SCREENS.HOME}`); |
| 48 | + }); |
| 49 | + }); |
| 50 | +}); |
0 commit comments