Bring allUnitActionsHaveTranslation test up to date (#4688)

* Bring `allUnitActionsHaveTranslation` test up to date

* Bring allUnitActionsHaveTranslation test up to date - revert enum prop
This commit is contained in:
SomeTroglodyte 2021-08-06 13:38:10 +02:00 committed by GitHub
parent 776be5a48a
commit ee32392ecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -61,6 +61,10 @@ data class UnitAction(
* @param key keyboard binding - can be a [KeyCharAndCode], a [Char], or omitted. * @param key keyboard binding - can be a [KeyCharAndCode], a [Char], or omitted.
* @param uncivSound _default_ sound, can be overridden in UnitAction instantiation * @param uncivSound _default_ sound, can be overridden in UnitAction instantiation
*/ */
// Note for Creators of new UnitActions: If your action uses a dynamic label overriding UnitActionType.value,
// then you need to teach [com.unciv.testing.TranslationTests.allUnitActionsHaveTranslation] how to deal with it!
enum class UnitActionType( enum class UnitActionType(
val value: String, val value: String,
val imageGetter: (()-> Actor)?, val imageGetter: (()-> Actor)?,
@ -79,6 +83,9 @@ enum class UnitActionType(
{ ImageGetter.getImage("OtherIcons/Sleep") }, 'f'), { ImageGetter.getImage("OtherIcons/Sleep") }, 'f'),
SleepUntilHealed("Sleep until healed", SleepUntilHealed("Sleep until healed",
{ ImageGetter.getImage("OtherIcons/Sleep") }, 'h'), { ImageGetter.getImage("OtherIcons/Sleep") }, 'h'),
// Note: Both Fortify actions are a special case. The button starting fortification uses the `value` here,
// the button label as shown when the unit is already fortifying is "Fortification".tr() + " nn%".
// For now we keep it simple, and the unit test `allUnitActionsHaveTranslation` does not know about the latter.
Fortify("Fortify", Fortify("Fortify",
null, 'f', UncivSound.Fortify), null, 'f', UncivSound.Fortify),
FortifyUntilHealed("Fortify until healed", FortifyUntilHealed("Fortify until healed",

View File

@ -48,10 +48,12 @@ class TranslationTests {
fun allUnitActionsHaveTranslation() { fun allUnitActionsHaveTranslation() {
val actions: MutableSet<String> = HashSet() val actions: MutableSet<String> = HashSet()
for (action in UnitActionType.values()) { for (action in UnitActionType.values()) {
if (action == UnitActionType.Upgrade) actions.add( when(action) {
actions.add("Upgrade to [unitType] ([goldCost] gold)") UnitActionType.Upgrade -> "Upgrade to [unitType] ([goldCost] gold)"
else UnitActionType.Create -> "Create [improvement]"
actions.add(action.value) UnitActionType.SpreadReligion -> "Spread [religionName]"
else -> action.value
})
} }
val allUnitActionsHaveTranslation = allStringAreTranslated(actions) val allUnitActionsHaveTranslation = allStringAreTranslated(actions)
Assert.assertTrue("This test will only pass when there is a translation for all unit actions", Assert.assertTrue("This test will only pass when there is a translation for all unit actions",