From ee32392ecd75659aecdf6855e3f340c274d3438b Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Fri, 6 Aug 2021 13:38:10 +0200 Subject: [PATCH] Bring `allUnitActionsHaveTranslation` test up to date (#4688) * Bring `allUnitActionsHaveTranslation` test up to date * Bring allUnitActionsHaveTranslation test up to date - revert enum prop --- core/src/com/unciv/models/UnitAction.kt | 7 +++++++ tests/src/com/unciv/testing/TranslationTests.kt | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/models/UnitAction.kt b/core/src/com/unciv/models/UnitAction.kt index cf1236dc6e..9408db18bc 100644 --- a/core/src/com/unciv/models/UnitAction.kt +++ b/core/src/com/unciv/models/UnitAction.kt @@ -61,6 +61,10 @@ data class UnitAction( * @param key keyboard binding - can be a [KeyCharAndCode], a [Char], or omitted. * @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( val value: String, val imageGetter: (()-> Actor)?, @@ -79,6 +83,9 @@ enum class UnitActionType( { ImageGetter.getImage("OtherIcons/Sleep") }, 'f'), SleepUntilHealed("Sleep until healed", { 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", null, 'f', UncivSound.Fortify), FortifyUntilHealed("Fortify until healed", diff --git a/tests/src/com/unciv/testing/TranslationTests.kt b/tests/src/com/unciv/testing/TranslationTests.kt index e4e3133f66..454e76edf2 100644 --- a/tests/src/com/unciv/testing/TranslationTests.kt +++ b/tests/src/com/unciv/testing/TranslationTests.kt @@ -48,10 +48,12 @@ class TranslationTests { fun allUnitActionsHaveTranslation() { val actions: MutableSet = HashSet() for (action in UnitActionType.values()) { - if (action == UnitActionType.Upgrade) - actions.add("Upgrade to [unitType] ([goldCost] gold)") - else - actions.add(action.value) + actions.add( when(action) { + UnitActionType.Upgrade -> "Upgrade to [unitType] ([goldCost] gold)" + UnitActionType.Create -> "Create [improvement]" + UnitActionType.SpreadReligion -> "Spread [religionName]" + else -> action.value + }) } val allUnitActionsHaveTranslation = allStringAreTranslated(actions) Assert.assertTrue("This test will only pass when there is a translation for all unit actions",