Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Allow SessionUseCases to be invoked with session ID
Browse files Browse the repository at this point in the history
  • Loading branch information
csadilek authored and mergify[bot] committed Feb 15, 2021
1 parent c25f24b commit 4a649aa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,16 @@ class SessionUseCases(
return
}

store.state.findTabOrCustomTab(session.id)
invoke(session.id)
}

/**
* Stops the current URL of the provided session from loading.
*
* @param sessionId the ID of the session for which loading should be stopped.
*/
operator fun invoke(sessionId: String) {
store.state.findTabOrCustomTab(sessionId)
?.engineState
?.engineSession
?.stopLoading()
Expand Down Expand Up @@ -219,8 +228,15 @@ class SessionUseCases(
return
}

invoke(session.id)
}

/**
* Navigates forward in the history of the provided session.
*/
operator fun invoke(sessionId: String) {
store.dispatch(EngineAction.GoForwardAction(
session.id
sessionId
))
}
}
Expand Down Expand Up @@ -293,8 +309,15 @@ class SessionUseCases(
return
}

invoke(enable, session.id)
}

/**
* Requests the desktop version of the provides session and reloads the page.
*/
operator fun invoke(enable: Boolean, sessionId: String) {
store.dispatch(EngineAction.ToggleDesktopModeAction(
session.id,
sessionId,
enable
))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class SessionUseCasesTest {
whenever(selectedSession.id).thenReturn(selectedSessionId)
whenever(sessionManager.selectedSessionOrThrow).thenReturn(selectedSession)
whenever(sessionManager.selectedSession).thenReturn(selectedSession)
whenever(sessionManager.findSessionById(selectedSessionId)).thenReturn(selectedSession)
}

@Test
Expand Down Expand Up @@ -136,6 +137,9 @@ class SessionUseCasesTest {

useCases.stopLoading(selectedSession)
verify(engineSession, times(2)).stopLoading()

useCases.stopLoading(selectedSession.id)
verify(engineSession, times(3)).stopLoading()
}

@Test
Expand All @@ -148,6 +152,9 @@ class SessionUseCasesTest {

useCases.goBack()
verify(store, times(2)).dispatch(EngineAction.GoBackAction(selectedSessionId))

useCases.goBack(selectedSession.id)
verify(store, times(3)).dispatch(EngineAction.GoBackAction(selectedSessionId))
}

@Test
Expand All @@ -160,6 +167,9 @@ class SessionUseCasesTest {

useCases.goForward()
verify(store, times(2)).dispatch(EngineAction.GoForwardAction(selectedSessionId))

useCases.goForward(selectedSession.id)
verify(store, times(3)).dispatch(EngineAction.GoForwardAction(selectedSessionId))
}

@Test
Expand Down Expand Up @@ -187,6 +197,12 @@ class SessionUseCasesTest {

useCases.requestDesktopSite(false)
verify(store).dispatch(EngineAction.ToggleDesktopModeAction(selectedSessionId, false))

useCases.requestDesktopSite(true, selectedSessionId)
verify(store, times(2)).dispatch(EngineAction.ToggleDesktopModeAction(selectedSessionId, true))

useCases.requestDesktopSite(false, selectedSessionId)
verify(store, times(2)).dispatch(EngineAction.ToggleDesktopModeAction(selectedSessionId, false))
}

@Test
Expand Down

0 comments on commit 4a649aa

Please sign in to comment.