Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [ANDROAPP-5808] GS1 QR code is show as QR Code if value does not have GS1 prefix value. #3709

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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