-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #373 from OpenSRP/367-add-mls-support-to-native-forms
Add MLS to native forms
- Loading branch information
Showing
21 changed files
with
1,066 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...id-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/NativeFormLangUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.vijay.jsonwizard.utils; | ||
|
||
import android.content.Context; | ||
import android.content.res.AssetManager; | ||
|
||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Locale; | ||
|
||
import static com.vijay.jsonwizard.utils.Utils.convertStreamToString; | ||
import static com.vijay.jsonwizard.utils.Utils.getTranslatedYamlFile; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.mock; | ||
|
||
/** | ||
* Created by Vincent Karuri on 20/02/2020 | ||
*/ | ||
public class NativeFormLangUtilsTest { | ||
|
||
@Test | ||
public void testJsonFormTranslationShouldTranslateForm() { | ||
Locale.setDefault(new Locale("id")); | ||
String expectedJsonForm = getFileContentsAsString("test_form_translation_in"); | ||
String interpolatedJsonForm = getFileContentsAsString("test_form_translation_interpolated"); | ||
assertEquals(expectedJsonForm, NativeFormLangUtils.getTranslatedString(interpolatedJsonForm)); | ||
|
||
Locale.setDefault(new Locale("en", "US")); | ||
expectedJsonForm = getFileContentsAsString("test_form_translation_en_US"); | ||
assertEquals(expectedJsonForm, NativeFormLangUtils.getTranslatedString(interpolatedJsonForm)); | ||
} | ||
|
||
@Test | ||
public void testYamlFileTranslationShouldTranslateYamlFile() throws IOException { | ||
Context context = mockAssetManager("test_yaml_translation_interpolated"); | ||
Locale.setDefault(new Locale("en", "US")); | ||
String translatedYamlStr = getTranslatedYamlFile("file_name", context); | ||
assertEquals(getFileContentsAsString("test_yaml_translation_en_US"), translatedYamlStr); | ||
} | ||
|
||
@Test | ||
public void testJsonFormTranslationShouldReturnUntranslatedForm() { | ||
Locale.setDefault(new Locale("id")); | ||
String interpolatedJsonForm = getFileContentsAsString("test_form_translation_interpolated_missing_translations"); | ||
assertEquals(interpolatedJsonForm, NativeFormLangUtils.getTranslatedString(interpolatedJsonForm)); | ||
} | ||
|
||
@Test | ||
public void testYamlFileTranslationShouldReturnUntranslatedYamlFile() throws IOException { | ||
Context context = mockAssetManager("test_yaml_translation_interpolated_missing_translations"); | ||
Locale.setDefault(new Locale("en", "US")); | ||
String translatedYamlStr = getTranslatedYamlFile("file_name", context); | ||
assertEquals(getFileContentsAsString("test_yaml_translation_interpolated_missing_translations"), translatedYamlStr); | ||
} | ||
|
||
private Context mockAssetManager(String yamlFilePath) throws IOException { | ||
Context context = mock(Context.class); | ||
AssetManager assetManager = mock(AssetManager.class); | ||
doReturn(getTestResource(yamlFilePath)) | ||
.when(assetManager) | ||
.open(eq("file_name")); | ||
doReturn(assetManager).when(context).getAssets(); | ||
return context; | ||
} | ||
|
||
private InputStream getTestResource(String filePath) { | ||
return getClass().getClassLoader().getResourceAsStream(filePath); | ||
} | ||
|
||
private String getFileContentsAsString(String filePath) { | ||
return convertStreamToString(getTestResource(filePath)); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
android-json-form-wizard/src/test/resources/form_strings_en_US.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
step1.title = New client record | ||
step1.previous_label = SAVE AND EXIT | ||
step1.submit_label = SAVE | ||
step1.patient_name_label.text = Name | ||
step1.sex.label = Gender | ||
step1.sex.options.Female.text = Female | ||
step1.sex.options.Male.text = Male | ||
step1.sex.v_required.err = Please specify gender | ||
step1.patient_dob.hint = Patient's date of birth | ||
step1.patient_dob.duration.label = Age | ||
step1.patient_occupation_label.text = Occupation | ||
step1.been_treated.label = Has been treated for malaria in the past 3 months? | ||
step1.been_treated.options.Yes.text = Yes | ||
step1.been_treated.options.No.text = No | ||
step1.been_treated.options.not_answered.text = Not Answered | ||
step1.been_treated.v_required.err = Has the patient been treated for malaria in the past 3 months? |
16 changes: 16 additions & 0 deletions
16
android-json-form-wizard/src/test/resources/form_strings_in.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
step1.title = Data Pasien Baru | ||
step1.previous_label = SIMPAN DAN KELUAR | ||
step1.submit_label = SIMPAN | ||
step1.patient_name_label.text = Nama | ||
step1.sex.label = Jenis kelamin pasien | ||
step1.sex.options.Female.text = Perempuan | ||
step1.sex.options.Male.text = Laki-laki | ||
step1.sex.v_required.err = Silakan sebutkan jenis kelamin | ||
step1.patient_dob.hint = Tanggal lahir pasien | ||
step1.patient_dob.duration.label = Usia | ||
step1.patient_occupation_label.text = Pekerjaan pasien | ||
step1.been_treated.label = Pernah dirawat karena Malaria dalam 3 bulan terakhir? | ||
step1.been_treated.options.Yes.text = Ya | ||
step1.been_treated.options.No.text = Tidak | ||
step1.been_treated.options.not_answered.text = Tidak dijawab | ||
step1.been_treated.v_required.err = Pernahkah pasien dirawat karena malaria dalam 3 bulan terakhir? |
Oops, something went wrong.