Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GT-2314 Track language choices for favorited tools #3792

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ class AllFavoritesPresenter @AssistedInject constructor(
ToolCard.Event.OpenTool -> {
val intent = tool.createToolIntent(
context = context,
languages = listOfNotNull(state.translation?.languageCode),
languages = listOfNotNull(
tool.primaryLocale ?: state.translation?.languageCode,
tool.parallelLocale
),
)

if (intent != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ class HomePresenter @AssistedInject constructor(
ToolCard.Event.OpenTool -> {
val intent = tool.createToolIntent(
context = context,
languages = listOfNotNull(state.translation?.languageCode),
languages = listOfNotNull(
tool.primaryLocale ?: state.translation?.languageCode,
tool.parallelLocale
),
)

if (intent != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ class AllFavoritesPresenterTest {
coVerify { toolsRepository.storeToolOrder(listOf("tool1", "tool3", "tool2", "tool4")) }
}

// region ToolCard.Event.Click
@Test
fun `ToolCard - Event - Click`() = runTest {
val tool = randomTool("tool", Tool.Type.TRACT)
val tool = randomTool("tool", Tool.Type.TRACT, primaryLocale = null, parallelLocale = null)
toolsFlow.value = listOf(tool)
everyComposable { toolCardPresenter.present(tool = tool, eventSink = any()) }.answers {
ToolCard.State(
Expand All @@ -165,6 +166,31 @@ class AllFavoritesPresenterTest {
verifyAll { eventBus.post(OpenAnalyticsActionEvent(ACTION_OPEN_TOOL, tool.code, SOURCE_FAVORITE)) }
}

@Test
fun `ToolCard - Event - Click - Saved Languages`() = runTest {
val tool = randomTool("tool", Tool.Type.TRACT, primaryLocale = Locale.FRENCH, parallelLocale = Locale.GERMAN)
toolsFlow.value = listOf(tool)
everyComposable { toolCardPresenter.present(tool = tool, eventSink = any()) }.answers {
ToolCard.State(
toolCode = firstArg<Tool>().code,
translation = randomTranslation(languageCode = Locale.ENGLISH),
eventSink = arg(4)
)
}

presenter.test {
expectMostRecentItem().tools[0].eventSink(ToolCard.Event.Click)

assertTrue {
assertIs<IntentScreen>(navigator.awaitNextScreen()).intent
.equalsIntent(tool.createToolIntent(context, languages = listOf(Locale.FRENCH, Locale.GERMAN)))
}
}

verifyAll { eventBus.post(OpenAnalyticsActionEvent(ACTION_OPEN_TOOL, tool.code, SOURCE_FAVORITE)) }
}
// endregion ToolCard.Event.Click

@Test
fun `ToolCard - Event - OpenToolDetails`() = runTest {
val tool = randomTool("tool", Tool.Type.TRACT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertIs
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue
import kotlinx.coroutines.flow.MutableSharedFlow
Expand Down Expand Up @@ -60,7 +61,11 @@ class HomePresenterTest {
}
private val toolCardPresenter: ToolCardPresenter = mockk {
everyComposable { present(tool = any(), eventSink = any()) }.answers {
ToolCard.State(toolCode = firstArg<Tool>().code, eventSink = arg(4))
ToolCard.State(
toolCode = firstArg<Tool>().code,
translation = randomTranslation(languageCode = Locale.ENGLISH),
eventSink = arg(4)
)
}
}

Expand Down Expand Up @@ -178,14 +183,6 @@ class HomePresenterTest {
// endregion State.spotlightLessons

// region State.favoriteTools
private val favoriteTool = randomTool(type = Tool.Type.TRACT, isHidden = false)
private val favoriteToolTranslation = randomTranslation(favoriteTool.code, languageCode = Locale.FRENCH)
init {
everyComposable { toolCardPresenter.present(tool = favoriteTool, eventSink = any()) }.answers {
ToolCard.State(toolCode = favoriteTool.code, translation = favoriteToolTranslation, eventSink = arg(4))
}
}

@Test
fun `State - favoriteTools`() = runTest {
val tools = List(3) { randomTool(type = Tool.Type.TRACT, isHidden = false) }
Expand All @@ -211,37 +208,64 @@ class HomePresenterTest {

@Test
fun `State - favoriteTools - Event - Click`() = runTest {
presenter.test {
toolsFlow.emit(listOf(favoriteTool))
expectMostRecentItem().favoriteTools[0].eventSink(ToolCard.Event.Click)
val tool = randomTool(type = Tool.Type.TRACT, primaryLocale = null, parallelLocale = null)

assertIs<IntentScreen>(navigator.awaitNextScreen()).let {
val expected = favoriteTool.createToolIntent(context, listOf(favoriteToolTranslation.languageCode))
assertTrue(expected equalsIntent it.intent)
presenter.test {
toolsFlow.emit(listOf(tool))
assertNotNull(expectMostRecentItem().favoriteTools[0]) { toolState ->
toolState.eventSink(ToolCard.Event.Click)

assertIs<IntentScreen>(navigator.awaitNextScreen()).let { screen ->
val expected = tool.createToolIntent(context, listOf(toolState.translation!!.languageCode))
assertTrue(expected equalsIntent screen.intent)
}
}
}
}

@Test
fun `State - favoriteTools - Event - OpenTool`() = runTest {
val tool = randomTool(type = Tool.Type.TRACT, primaryLocale = null, parallelLocale = null)

presenter.test {
toolsFlow.emit(listOf(favoriteTool))
expectMostRecentItem().favoriteTools[0].eventSink(ToolCard.Event.OpenTool)
toolsFlow.emit(listOf(tool))
assertNotNull(expectMostRecentItem().favoriteTools[0]) { toolState ->
toolState.eventSink(ToolCard.Event.OpenTool)

assertIs<IntentScreen>(navigator.awaitNextScreen()).let { screen ->
val expected = tool.createToolIntent(context, listOf(toolState.translation!!.languageCode))
assertTrue(expected equalsIntent screen.intent)
}
}
}
}

assertIs<IntentScreen>(navigator.awaitNextScreen()).let {
val expected = favoriteTool.createToolIntent(context, listOf(favoriteToolTranslation.languageCode))
assertTrue(expected equalsIntent it.intent)
@Test
fun `State - favoriteTools - Event - OpenTool - Saved Languages`() = runTest {
val tool = randomTool(type = Tool.Type.TRACT, primaryLocale = Locale.GERMAN, parallelLocale = Locale.FRENCH)

presenter.test {
toolsFlow.emit(listOf(tool))
assertNotNull(expectMostRecentItem().favoriteTools[0]) { toolState ->
toolState.eventSink(ToolCard.Event.OpenTool)

assertIs<IntentScreen>(navigator.awaitNextScreen()).let { screen ->
val expected = tool.createToolIntent(context, listOf(Locale.GERMAN, Locale.FRENCH))
assertTrue(expected equalsIntent screen.intent)
}
}
}
}

@Test
fun `State - favoriteTools - Event - OpenToolDetails`() = runTest {
val tool = randomTool(type = Tool.Type.TRACT)

presenter.test {
toolsFlow.emit(listOf(favoriteTool))
toolsFlow.emit(listOf(tool))
expectMostRecentItem().favoriteTools[0].eventSink(ToolCard.Event.OpenToolDetails)

assertEquals(ToolDetailsScreen(favoriteTool.code!!), navigator.awaitNextScreen())
assertEquals(ToolDetailsScreen(tool.code!!), navigator.awaitNextScreen())
}
}
// endregion State.favoriteTools
Expand Down
Loading
Loading