Skip to content

Commit

Permalink
add second language availability label
Browse files Browse the repository at this point in the history
  • Loading branch information
frett committed Mar 6, 2024
1 parent 78b8951 commit b5aa779
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ internal fun AvailableInLanguage(
)
Icon(
painterResource(if (available) R.drawable.ic_language_available else R.drawable.ic_language_unavailable),
contentDescription = null,
contentDescription = when {
available -> stringResource(R.string.tool_card_accessibility_language_available)
else -> null
},
modifier = Modifier
.padding(start = 4.dp)
.size(with(LocalDensity.current) { (LocalTextStyle.current.fontSize * 0.65).toDp() })
Expand Down
27 changes: 9 additions & 18 deletions app/src/main/kotlin/org/cru/godtools/ui/tools/VariantToolCard.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package org.cru.godtools.ui.tools

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Text
Expand All @@ -20,7 +14,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.unit.dp
import org.cru.godtools.R
Expand All @@ -34,6 +27,8 @@ internal fun VariantToolCard(state: ToolCard.State, modifier: Modifier = Modifie
val translation by rememberUpdatedState(state.translation)
val appLanguage by rememberUpdatedState(state.appLanguage)
val appTranslation by rememberUpdatedState(state.appTranslation)
val secondLanguage by rememberUpdatedState(state.secondLanguage)
val secondTranslation by rememberUpdatedState(state.secondTranslation)
val languageCount by rememberUpdatedState(state.availableLanguages)

val eventSink by rememberUpdatedState(state.eventSink)
Expand Down Expand Up @@ -65,25 +60,21 @@ internal fun VariantToolCard(state: ToolCard.State, modifier: Modifier = Modifie
}

ToolCardInfoContent {
Row(
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically,
Column(
horizontalAlignment = Alignment.End,
modifier = Modifier
.align(Alignment.End)
.padding(16.dp)
) {
Text(pluralStringResource(R.plurals.label_tools_languages, languageCount, languageCount))

Spacer(
modifier = Modifier
.padding(horizontal = 4.dp)
.size(4.dp)
.clip(CircleShape)
.background(LocalContentColor.current)
)

// TODO: I believe we need to suppress the "Unavailable in" prefix for this phrase
AvailableInLanguage(appLanguage, available = appTranslation != null)

if (secondLanguage != null) {
// TODO: I believe we need to suppress the "Unavailable in" prefix for this phrase
AvailableInLanguage(secondLanguage, available = secondTranslation != null)
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings_dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ An online version can be found at https://knowgod.com/</string>
<string name="tools_list_remove_favorite_dialog_confirm">Remove</string>
<string name="tools_list_remove_favorite_dialog_dismiss">Cancel</string>
<string name="tool_card_label_language_unavailable">Not available in %1$s</string>
<string name="tool_card_accessibility_language_available">Available</string>
<string name="action_tools_about">Details</string>
<string name="action_tools_open">Open</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ import android.app.Application
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.test.SemanticsMatcher.Companion.expectValue
import androidx.compose.ui.test.assertContentDescriptionEquals
import androidx.compose.ui.test.assertIsNotSelected
import androidx.compose.ui.test.assertIsSelected
import androidx.compose.ui.test.filterToOne
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.onSiblings
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.printToString
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.slack.circuit.test.TestEventSink
import java.util.Locale
import java.util.UUID
import kotlin.test.Test
import org.cru.godtools.model.Language
import org.cru.godtools.model.randomTool
import org.cru.godtools.model.randomTranslation
import org.junit.Rule
Expand Down Expand Up @@ -80,4 +86,79 @@ class VariantToolCardTest {
events.assertEvent(ToolCard.Event.Click)
}
// endregion VariantToolCard - isSelected

// region VariantToolCard - App Language
@Test
fun `VariantToolCard - App Language - Available`() {
composeTestRule.setContent {
VariantToolCard(
state = ToolCard.State(
tool = randomTool(),
appLanguage = Language(Locale.ENGLISH),
appTranslation = randomTranslation(),
),
)
}

composeTestRule.onNodeWithText("English", useUnmergedTree = true)
.onSiblings()
.filterToOne(expectValue(SemanticsProperties.Role, Role.Image))
.assertContentDescriptionEquals("Available")
}

@Test
fun `VariantToolCard - App Language - Not Available`() {
composeTestRule.setContent {
VariantToolCard(
state = ToolCard.State(
tool = randomTool(),
appLanguage = Language(Locale.ENGLISH),
appTranslation = null,
),
)
}

composeTestRule.onNodeWithText("Not available in English").assertExists()
}
// endregion VariantToolCard - App Language

// region VariantToolCard - Second Language
@Test
fun `VariantToolCard - Second Language - Available`() {
composeTestRule.setContent {
VariantToolCard(
state = ToolCard.State(
tool = randomTool(),
appLanguage = Language(Locale.ENGLISH),
appTranslation = null,
secondLanguage = Language(Locale.FRENCH),
secondTranslation = randomTranslation(),
),
)
}

composeTestRule.onNodeWithText("French", useUnmergedTree = true)
.onSiblings()
.filterToOne(expectValue(SemanticsProperties.Role, Role.Image))
.assertContentDescriptionEquals("Available")
.printToString().let { println(it) }
}

@Test
fun `VariantToolCard - Second Language - Not Available`() {
composeTestRule.setContent {
VariantToolCard(
state = ToolCard.State(
tool = randomTool(),
appLanguage = Language(Locale.ENGLISH),
appTranslation = randomTranslation(),
secondLanguage = Language(Locale.FRENCH),
secondTranslation = null,
),
)
}

composeTestRule.onNodeWithText("Not available in French").assertExists()
}
// endregion VariantToolCard - Second Language
}

0 comments on commit b5aa779

Please sign in to comment.