1import { 2 consumeNavigationStateAsync, 3 getBuildInfoAsync, 4 getCrashReport, 5 installationID, 6} from '../../native-modules/DevLauncherInternal'; 7import { getMenuPreferencesAsync } from '../../native-modules/DevMenuPreferences'; 8import { getDevSessionsAsync } from '../getDevSessionsAsync'; 9import { getInitialData } from '../getInitialData'; 10import { restoreUserAsync } from '../restoreUserAsync'; 11 12jest.mock('../restoreUserAsync', () => { 13 return { 14 restoreUserAsync: jest.fn().mockResolvedValue(null), 15 }; 16}); 17jest.mock('../getDevSessionsAsync', () => { 18 return { 19 getDevSessionsAsync: jest.fn().mockResolvedValue([]), 20 }; 21}); 22 23const mockRestoreUserAsync = restoreUserAsync as jest.Mock; 24 25const mockFns = [ 26 getBuildInfoAsync, 27 getMenuPreferencesAsync, 28 restoreUserAsync, 29 getDevSessionsAsync, 30 getCrashReport, 31 consumeNavigationStateAsync, 32] as jest.Mock[]; 33 34describe('getInitialData()', () => { 35 beforeEach(() => { 36 mockFns.forEach((fn) => fn.mockClear()); 37 }); 38 39 test('calls all the fns we need', async () => { 40 expect(getBuildInfoAsync).not.toHaveBeenCalled(); 41 expect(getMenuPreferencesAsync).not.toHaveBeenCalled(); 42 expect(restoreUserAsync).not.toHaveBeenCalled(); 43 expect(getDevSessionsAsync).not.toHaveBeenCalled(); 44 expect(getCrashReport).not.toHaveBeenCalled(); 45 expect(consumeNavigationStateAsync).not.toHaveBeenCalled(); 46 47 await getInitialData(); 48 49 expect(getDevSessionsAsync).toHaveBeenLastCalledWith( 50 expect.objectContaining({ isAuthenticated: false }) 51 ); 52 53 expect(getDevSessionsAsync).toHaveBeenCalled(); 54 expect(getBuildInfoAsync).toHaveBeenCalled(); 55 expect(getMenuPreferencesAsync).toHaveBeenCalled(); 56 expect(restoreUserAsync).toHaveBeenCalled(); 57 expect(getCrashReport).toHaveBeenCalled(); 58 expect(consumeNavigationStateAsync).toHaveBeenCalled(); 59 }); 60 61 test('queries dev sessions if logged in', async () => { 62 mockRestoreUserAsync.mockResolvedValueOnce({ username: '123' }); 63 expect(getBuildInfoAsync).not.toHaveBeenCalled(); 64 expect(getMenuPreferencesAsync).not.toHaveBeenCalled(); 65 expect(restoreUserAsync).not.toHaveBeenCalled(); 66 expect(getDevSessionsAsync).not.toHaveBeenCalled(); 67 expect(getCrashReport).not.toHaveBeenCalled(); 68 69 await getInitialData(); 70 71 expect(getDevSessionsAsync).toHaveBeenLastCalledWith( 72 expect.objectContaining({ isAuthenticated: true, installationID }) 73 ); 74 75 expect(getBuildInfoAsync).toHaveBeenCalled(); 76 expect(getMenuPreferencesAsync).toHaveBeenCalled(); 77 expect(restoreUserAsync).toHaveBeenCalled(); 78 expect(getCrashReport).toHaveBeenCalled(); 79 }); 80}); 81