Skip to content

Commit 4b43089

Browse files
author
Pablo Guardiola
authored
[copilot] start recording as soon as on should start recording is called to include deferred events as part of the current history file session (#6655)
1 parent 05bb93d commit 4b43089

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

libnavigation-copilot/src/main/java/com/mapbox/navigation/copilot/MapboxCopilotImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ internal class MapboxCopilotImpl(
205205
private fun startRecordingHistory(
206206
historyRecordingSessionState: HistoryRecordingSessionState
207207
) {
208+
copilotHistoryRecorder.startRecording()
208209
currentHistoryRecordingSessionState = historyRecordingSessionState
209210
startSessionTime = System.currentTimeMillis()
210211
startedAt = currentUtcTime()
211-
copilotHistoryRecorder.startRecording()
212212
driveId = historyRecordingSessionState.sessionId
213213
driveMode = when (historyRecordingSessionState) {
214214
is ActiveGuidance -> "active-guidance"

libnavigation-copilot/src/test/java/com/mapbox/navigation/copilot/MapboxCopilotImplTest.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import io.mockk.mockkStatic
4040
import io.mockk.slot
4141
import io.mockk.unmockkAll
4242
import io.mockk.verify
43+
import io.mockk.verifyOrder
4344
import org.junit.After
4445
import org.junit.Assert.assertEquals
4546
import org.junit.Assert.assertTrue
@@ -1859,6 +1860,45 @@ class MapboxCopilotImplTest {
18591860
}
18601861
}
18611862

1863+
@Test
1864+
fun `startRecording as soon as onShouldStartRecording`() {
1865+
val mockedMapboxNavigation = prepareBasicMockks()
1866+
prepareLifecycleOwnerMockk()
1867+
val mockedHistoryRecorder = mockk<MapboxHistoryRecorder>(relaxed = true)
1868+
every {
1869+
mockedMapboxNavigation.retrieveCopilotHistoryRecorder()
1870+
} returns mockedHistoryRecorder
1871+
val userFeedbackCallback = slot<UserFeedbackCallback>()
1872+
every { registerUserFeedbackCallback(capture(userFeedbackCallback)) } just Runs
1873+
val historyRecordingStateChangeObserver = slot<HistoryRecordingStateChangeObserver>()
1874+
every {
1875+
mockedMapboxNavigation.registerHistoryRecordingStateChangeObserver(
1876+
capture(historyRecordingStateChangeObserver)
1877+
)
1878+
} just Runs
1879+
val mapboxCopilot = MapboxCopilotImpl(mockedMapboxNavigation)
1880+
mapboxCopilot.start()
1881+
val searchResults =
1882+
SearchResults("mapbox", "https://mapbox.com", null, null, "?query=test1", null)
1883+
mapboxCopilot.push(SearchResultsEvent(searchResults))
1884+
val activeGuidanceHistoryRecordingSessionState =
1885+
mockk<HistoryRecordingSessionState.ActiveGuidance>(relaxed = true)
1886+
historyRecordingStateChangeObserver.captured.onShouldStartRecording(
1887+
activeGuidanceHistoryRecordingSessionState
1888+
)
1889+
val expectedEventJson = """
1890+
{"provider":"mapbox","request":"https://mapbox.com","searchQuery":"?query\u003dtest1"}
1891+
""".trimIndent()
1892+
1893+
verifyOrder {
1894+
mockedHistoryRecorder.startRecording()
1895+
mockedHistoryRecorder.pushHistory(
1896+
SEARCH_RESULTS_EVENT_NAME,
1897+
expectedEventJson,
1898+
)
1899+
}
1900+
}
1901+
18621902
@Test
18631903
fun `SearchResultsEvent is pushed when push - ActiveGuidance`() {
18641904
val mockedMapboxNavigation = prepareBasicMockks()

0 commit comments

Comments
 (0)