diff --git a/form/src/androidTest/kotlin/org/dhis2/form/ui/provider/inputfield/AgeProviderTest.kt b/form/src/androidTest/kotlin/org/dhis2/form/ui/provider/inputfield/AgeProviderTest.kt index 6160f1321d..1b37987cdf 100644 --- a/form/src/androidTest/kotlin/org/dhis2/form/ui/provider/inputfield/AgeProviderTest.kt +++ b/form/src/androidTest/kotlin/org/dhis2/form/ui/provider/inputfield/AgeProviderTest.kt @@ -31,9 +31,9 @@ class AgeProviderTest { const val INPUT_AGE_OPEN_CALENDAR_BUTTON = "INPUT_AGE_OPEN_CALENDAR_BUTTON" const val INPUT_AGE_TIME_UNIT_SELECTOR = "INPUT_AGE_TIME_UNIT_SELECTOR" const val INPUT_AGE_TEXT_FIELD = "INPUT_AGE_TEXT_FIELD" - const val RADIO_BUTTON_months = "RADIO_BUTTON_months" - const val RADIO_BUTTON_days = "RADIO_BUTTON_days" - const val RADIO_BUTTON_years = "RADIO_BUTTON_years" + const val RADIO_BUTTON_months = "RADIO_BUTTON_MONTHS" + const val RADIO_BUTTON_days = "RADIO_BUTTON_DAYS" + const val RADIO_BUTTON_years = "RADIO_BUTTON_YEARS" const val AGE_SELECTOR_TEXT = "6 years" const val INPUT_AGE_TEST_TAG = "INPUT_AGE" const val FIELD_UI_MODEL_UID = "FieldUIModelUid" diff --git a/form/src/main/java/org/dhis2/form/ui/dialog/QRImageControllerImpl.kt b/form/src/main/java/org/dhis2/form/ui/dialog/QRImageControllerImpl.kt index f2d771135b..d472c5e54b 100644 --- a/form/src/main/java/org/dhis2/form/ui/dialog/QRImageControllerImpl.kt +++ b/form/src/main/java/org/dhis2/form/ui/dialog/QRImageControllerImpl.kt @@ -17,15 +17,18 @@ class QRImageControllerImpl( ) : QRImageController { @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) - fun getWriterFromRendering(value: String, renderingType: UiRenderType) = when { - value.startsWith(GS1Elements.GS1_d2_IDENTIFIER.element) -> Pair( - DataMatrixWriter(), - BarcodeFormat.DATA_MATRIX, - ) - renderingType == UiRenderType.QR_CODE -> Pair(QRCodeWriter(), BarcodeFormat.QR_CODE) - renderingType == UiRenderType.BAR_CODE -> Pair(Code128Writer(), BarcodeFormat.CODE_128) - else -> throw IllegalArgumentException() - } + fun getWriterFromRendering(value: String, renderingType: UiRenderType) = + when (renderingType) { + UiRenderType.GS1_DATAMATRIX -> + if (value.startsWith(GS1Elements.GS1_d2_IDENTIFIER.element)) { + Pair(DataMatrixWriter(), BarcodeFormat.DATA_MATRIX) + } else { + Pair(QRCodeWriter(), BarcodeFormat.QR_CODE) + } + UiRenderType.QR_CODE -> Pair(QRCodeWriter(), BarcodeFormat.QR_CODE) + UiRenderType.BAR_CODE -> Pair(Code128Writer(), BarcodeFormat.CODE_128) + else -> throw IllegalArgumentException() + } private fun formattedContent(value: String) = value.removePrefix(GS1Elements.GS1_d2_IDENTIFIER.element) diff --git a/form/src/test/java/org/dhis2/form/dialog/QRImageControllerTest.kt b/form/src/test/java/org/dhis2/form/dialog/QRImageControllerTest.kt index cef23732ef..086304cbd1 100644 --- a/form/src/test/java/org/dhis2/form/dialog/QRImageControllerTest.kt +++ b/form/src/test/java/org/dhis2/form/dialog/QRImageControllerTest.kt @@ -15,12 +15,21 @@ class QRImageControllerTest { @Test fun shouldReturnDataMatrixWriter() { val testValue = "]d2\u001D01084700069915412110081996195256\u001D10DXB2005\u001D17220228" - controller.getWriterFromRendering(testValue, UiRenderType.QR_CODE).let { (writer, format) -> + controller.getWriterFromRendering(testValue, UiRenderType.GS1_DATAMATRIX).let { (writer, format) -> assertTrue(writer is DataMatrixWriter) assertTrue(format == BarcodeFormat.DATA_MATRIX) } } + @Test + fun shouldReturnQRWriterWhenValueDoesNotHaveGS1Prefix() { + val testValue = "01084700069915412110081996195256\u001D10DXB2005\u001D17220228" + controller.getWriterFromRendering(testValue, UiRenderType.GS1_DATAMATRIX).let { (writer, format) -> + assertTrue(writer is QRCodeWriter) + assertTrue(format == BarcodeFormat.QR_CODE) + } + } + @Test fun shouldReturnQRWriter() { val testValue = "qrValue"