@@ -28,6 +28,7 @@ import {
2828 type NavigationController ,
2929 type NavigationViewController ,
3030 type TimeAndDistance ,
31+ type TurnByTurnEvent ,
3132} from '@googlemaps/react-native-navigation-sdk' ;
3233import { Platform } from 'react-native' ;
3334import { delay , roundDown } from './utils' ;
@@ -48,6 +49,9 @@ interface TestTools {
4849 setOnLocationChanged : (
4950 listener : ( ( location : Location ) => void ) | null | undefined
5051 ) => void ;
52+ setOnTurnByTurn : (
53+ listener : ( ( turnByTurnEvents : TurnByTurnEvent [ ] ) => void ) | null | undefined
54+ ) => void ;
5155 passTest : ( ) => void ;
5256 failTest : ( message : string ) => void ;
5357 setDetoxStep : ( stepNumber : number ) => void ;
@@ -1866,3 +1870,104 @@ export const testSetFollowingPerspective = async (testTools: TestTools) => {
18661870
18671871 await initializeNavigation ( navigationController , failTest ) ;
18681872} ;
1873+
1874+ /**
1875+ * Tests that navInfo (turn-by-turn) events can be received after performing
1876+ * a cleanup and re-initialization cycle. This verifies that the NavForwardingManager
1877+ * and LiveData observer are properly restored after cleanup.
1878+ */
1879+ export const testNavInfoEventsAfterCleanup = async ( testTools : TestTools ) => {
1880+ const {
1881+ navigationController,
1882+ setOnNavigationReady,
1883+ setOnLocationChanged,
1884+ setOnTurnByTurn,
1885+ passTest,
1886+ failTest,
1887+ } = testTools ;
1888+
1889+ // Accept ToS first
1890+ if ( ! ( await acceptToS ( navigationController , failTest ) ) ) {
1891+ return ;
1892+ }
1893+
1894+ const startLocation : LatLng = {
1895+ lat : 37.79136614772824 ,
1896+ lng : - 122.41565900473043 ,
1897+ } ;
1898+
1899+ const destination = {
1900+ title : 'Grace Cathedral' ,
1901+ position : {
1902+ lat : 37.791957 ,
1903+ lng : - 122.412529 ,
1904+ } ,
1905+ } ;
1906+
1907+ let phase : 'first' | 'second' = 'first' ;
1908+
1909+ setOnTurnByTurn ( async ( _events : TurnByTurnEvent [ ] ) => {
1910+ if ( phase === 'first' ) {
1911+ // Received navInfo in first session — now cleanup and re-init
1912+ phase = 'second' ;
1913+ setOnTurnByTurn ( null ) ;
1914+
1915+ await navigationController . cleanup ( ) ;
1916+
1917+ // Re-initialize after cleanup
1918+ setOnNavigationReady ( async ( ) => {
1919+ disableVoiceGuidanceForTests ( navigationController ) ;
1920+ navigationController . setTurnByTurnLoggingEnabled ( true ) ;
1921+
1922+ const located2 = await simulateAndWaitForLocation (
1923+ navigationController ,
1924+ setOnLocationChanged ,
1925+ startLocation
1926+ ) ;
1927+ if ( ! located2 ) {
1928+ return failTest (
1929+ 'Timed out waiting for simulated location after re-init'
1930+ ) ;
1931+ }
1932+ await navigationController . setDestination ( destination ) ;
1933+ await navigationController . startGuidance ( ) ;
1934+ await navigationController . simulator . simulateLocationsAlongExistingRoute (
1935+ { speedMultiplier : 5 }
1936+ ) ;
1937+
1938+ // Listen for turn-by-turn events in the second session
1939+ setOnTurnByTurn ( async ( ) => {
1940+ // Received navInfo after cleanup+reinit — test passes
1941+ setOnTurnByTurn ( null ) ;
1942+ await navigationController . cleanup ( ) ;
1943+ passTest ( ) ;
1944+ } ) ;
1945+ } ) ;
1946+
1947+ await initializeNavigation ( navigationController , failTest ) ;
1948+ }
1949+ } ) ;
1950+
1951+ setOnNavigationReady ( async ( ) => {
1952+ disableVoiceGuidanceForTests ( navigationController ) ;
1953+ navigationController . setTurnByTurnLoggingEnabled ( true ) ;
1954+
1955+ const located = await simulateAndWaitForLocation (
1956+ navigationController ,
1957+ setOnLocationChanged ,
1958+ startLocation
1959+ ) ;
1960+ if ( ! located ) {
1961+ return failTest (
1962+ 'Timed out waiting for simulated location to be confirmed'
1963+ ) ;
1964+ }
1965+ await navigationController . setDestination ( destination ) ;
1966+ await navigationController . startGuidance ( ) ;
1967+ await navigationController . simulator . simulateLocationsAlongExistingRoute ( {
1968+ speedMultiplier : 5 ,
1969+ } ) ;
1970+ } ) ;
1971+
1972+ await initializeNavigation ( navigationController , failTest ) ;
1973+ } ;
0 commit comments