Skip to content

Commit

Permalink
fix: [ANDROAPP-5808] GS1 QR code is show as QR Code if value does not…
Browse files Browse the repository at this point in the history
… have GS1 prefix value. (#3709)

* GS1 QR code is show as QR Code if value does not have GS1 prefix value.

* Fix failing test
  • Loading branch information
ferdyrod authored Jul 8, 2024
1 parent e9acb51 commit 2dac14d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2dac14d

Please sign in to comment.