diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/DecimalWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/DecimalWidgetTest.java index c74437ff005..cd1293f7596 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/DecimalWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/DecimalWidgetTest.java @@ -20,8 +20,13 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.when; +import static org.odk.collect.android.utilities.Appearances.MASKED; import static org.odk.collect.android.utilities.Appearances.THOUSANDS_SEP; +import android.text.InputType; +import android.text.method.PasswordTransformationMethod; +import android.text.method.SingleLineTransformationMethod; + public class DecimalWidgetTest extends GeneralStringWidgetTest { private final Random random = new Random(); @@ -205,4 +210,21 @@ public void separatorsShouldBeAddedWhenEnabled() { assertEquals("123,456,789.54", getWidget().widgetAnswerText.getBinding().editText.getText().toString()); assertEquals("123,456,789.54", getWidget().widgetAnswerText.getBinding().textView.getText().toString()); } + + @Override + @Test + public void verifyInputType() { + DecimalWidget widget = getWidget(); + assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL)); + assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(SingleLineTransformationMethod.class)); + } + + @Override + @Test + public void verifyInputTypeWithMaskedAppearance() { + when(formEntryPrompt.getAppearanceHint()).thenReturn(MASKED); + DecimalWidget widget = getWidget(); + assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL)); + assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class)); + } } diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/ExDecimalWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/ExDecimalWidgetTest.java index cb150a8e92a..519ff5038d1 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/ExDecimalWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/ExDecimalWidgetTest.java @@ -20,8 +20,13 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.when; +import static org.odk.collect.android.utilities.Appearances.MASKED; import static org.odk.collect.android.utilities.Appearances.THOUSANDS_SEP; +import android.text.InputType; +import android.text.method.PasswordTransformationMethod; +import android.text.method.SingleLineTransformationMethod; + /** * @author James Knight */ @@ -88,4 +93,23 @@ public void separatorsShouldBeAddedWhenEnabled() { assertEquals("123,456,789.54", getWidget().binding.widgetAnswerText.getBinding().editText.getText().toString()); assertEquals("123,456,789.54", getWidget().binding.widgetAnswerText.getBinding().textView.getText().toString()); } + + @Override + @Test + public void verifyKeyboardType() { + ExDecimalWidget widget = getWidget(); + assertThat(widget.binding.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL)); + assertThat(widget.binding.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(SingleLineTransformationMethod.class)); + assertThat(widget.binding.widgetAnswerText.getBinding().textView.getTransformationMethod(), equalTo(null)); + } + + @Override + @Test + public void verifyKeyboardTypeWithMaskedAppearance() { + when(formEntryPrompt.getAppearanceHint()).thenReturn(MASKED); + ExDecimalWidget widget = getWidget(); + assertThat(widget.binding.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL)); + assertThat(widget.binding.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class)); + assertThat(widget.binding.widgetAnswerText.getBinding().textView.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class)); + } } diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/ExIntegerWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/ExIntegerWidgetTest.java index 9d012508ca2..04b04aeecc6 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/ExIntegerWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/ExIntegerWidgetTest.java @@ -11,9 +11,16 @@ import org.odk.collect.android.widgets.utilities.StringRequester; import static junit.framework.TestCase.assertEquals; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; +import static org.odk.collect.android.utilities.Appearances.MASKED; import static org.odk.collect.android.utilities.Appearances.THOUSANDS_SEP; +import android.text.InputType; +import android.text.method.PasswordTransformationMethod; +import android.text.method.SingleLineTransformationMethod; + /** * @author James Knight */ @@ -60,4 +67,23 @@ public void separatorsShouldBeAddedWhenEnabled() { assertEquals("123,456,789", getWidget().binding.widgetAnswerText.getBinding().editText.getText().toString()); assertEquals("123,456,789", getWidget().binding.widgetAnswerText.getBinding().textView.getText().toString()); } + + @Override + @Test + public void verifyKeyboardType() { + ExIntegerWidget widget = getWidget(); + assertThat(widget.binding.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED)); + assertThat(widget.binding.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(SingleLineTransformationMethod.class)); + assertThat(widget.binding.widgetAnswerText.getBinding().textView.getTransformationMethod(), equalTo(null)); + } + + @Override + @Test + public void verifyKeyboardTypeWithMaskedAppearance() { + when(formEntryPrompt.getAppearanceHint()).thenReturn(MASKED); + ExIntegerWidget widget = getWidget(); + assertThat(widget.binding.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED)); + assertThat(widget.binding.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class)); + assertThat(widget.binding.widgetAnswerText.getBinding().textView.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class)); + } } diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/ExStringWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/ExStringWidgetTest.java index e022cd9c3c2..6a0ede839f9 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/ExStringWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/ExStringWidgetTest.java @@ -5,13 +5,21 @@ import net.bytebuddy.utility.RandomString; import org.javarosa.core.model.data.StringData; +import org.junit.Test; import org.mockito.Mock; import org.odk.collect.android.formentry.questions.QuestionDetails; import org.odk.collect.android.widgets.base.GeneralExStringWidgetTest; import org.odk.collect.android.widgets.support.FakeWaitingForDataRegistry; import org.odk.collect.android.widgets.utilities.StringRequester; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; import static org.mockito.Mockito.when; +import static org.odk.collect.android.utilities.Appearances.MASKED; + +import android.text.InputType; +import android.text.method.PasswordTransformationMethod; +import android.text.method.SingleLineTransformationMethod; /** * @author James Knight @@ -39,4 +47,23 @@ public void setUp() throws Exception { super.setUp(); when(formEntryPrompt.getAppearanceHint()).thenReturn(""); } + + @Override + @Test + public void verifyKeyboardType() { + ExStringWidget widget = getWidget(); + assertThat(widget.binding.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_TEXT)); + assertThat(widget.binding.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(SingleLineTransformationMethod.class)); + assertThat(widget.binding.widgetAnswerText.getBinding().textView.getTransformationMethod(), equalTo(null)); + } + + @Override + @Test + public void verifyKeyboardTypeWithMaskedAppearance() { + when(formEntryPrompt.getAppearanceHint()).thenReturn(MASKED); + ExStringWidget widget = getWidget(); + assertThat(widget.binding.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)); + assertThat(widget.binding.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class)); + assertThat(widget.binding.widgetAnswerText.getBinding().textView.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class)); + } } diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/IntegerWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/IntegerWidgetTest.java index 2cb61e7ecf5..1b019474016 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/IntegerWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/IntegerWidgetTest.java @@ -8,9 +8,16 @@ import org.odk.collect.android.widgets.base.GeneralStringWidgetTest; import static junit.framework.TestCase.assertEquals; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; +import static org.odk.collect.android.utilities.Appearances.MASKED; import static org.odk.collect.android.utilities.Appearances.THOUSANDS_SEP; +import android.text.InputType; +import android.text.method.PasswordTransformationMethod; +import android.text.method.SingleLineTransformationMethod; + /** * @author James Knight */ @@ -47,4 +54,21 @@ public void separatorsShouldBeAddedWhenEnabled() { assertEquals("123,456,789", getWidget().widgetAnswerText.getBinding().editText.getText().toString()); assertEquals("123,456,789", getWidget().widgetAnswerText.getBinding().textView.getText().toString()); } + + @Override + @Test + public void verifyInputType() { + IntegerWidget widget = getWidget(); + assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED)); + assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(SingleLineTransformationMethod.class)); + } + + @Override + @Test + public void verifyInputTypeWithMaskedAppearance() { + when(formEntryPrompt.getAppearanceHint()).thenReturn(MASKED); + IntegerWidget widget = getWidget(); + assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED)); + assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class)); + } } diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/StringNumberWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/StringNumberWidgetTest.java index 6228d255e05..31b189cafb1 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/StringNumberWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/StringNumberWidgetTest.java @@ -10,9 +10,16 @@ import org.odk.collect.android.widgets.base.GeneralStringWidgetTest; import static junit.framework.TestCase.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; import static org.mockito.Mockito.when; +import static org.odk.collect.android.utilities.Appearances.MASKED; import static org.odk.collect.android.utilities.Appearances.THOUSANDS_SEP; +import android.text.InputType; +import android.text.method.PasswordTransformationMethod; +import android.text.method.SingleLineTransformationMethod; + /** * @author James Knight */ @@ -45,4 +52,21 @@ public void separatorsShouldBeAddedWhenEnabled() { assertEquals("123,456,789,123,456,789,123,456,789,123,456,789", getWidget().widgetAnswerText.getBinding().editText.getText().toString()); assertEquals("123,456,789,123,456,789,123,456,789,123,456,789", getWidget().widgetAnswerText.getBinding().textView.getText().toString()); } + + @Override + @Test + public void verifyInputType() { + StringNumberWidget widget = getWidget(); + assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER)); + assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(SingleLineTransformationMethod.class)); + } + + @Override + @Test + public void verifyInputTypeWithMaskedAppearance() { + when(formEntryPrompt.getAppearanceHint()).thenReturn(MASKED); + StringNumberWidget widget = getWidget(); + assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER)); + assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class)); + } } diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/StringWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/StringWidgetTest.java index 82c3f988049..c7e4b7988e0 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/StringWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/StringWidgetTest.java @@ -1,10 +1,20 @@ package org.odk.collect.android.widgets; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.when; +import static org.odk.collect.android.utilities.Appearances.MASKED; + +import android.text.InputType; +import android.text.method.PasswordTransformationMethod; +import android.text.method.SingleLineTransformationMethod; + import androidx.annotation.NonNull; import net.bytebuddy.utility.RandomString; import org.javarosa.core.model.data.StringData; +import org.junit.Test; import org.odk.collect.android.formentry.questions.QuestionDetails; import org.odk.collect.android.widgets.base.GeneralStringWidgetTest; @@ -24,4 +34,22 @@ public StringWidget createWidget() { public StringData getNextAnswer() { return new StringData(RandomString.make()); } + + @Override + @Test + public void verifyInputType() { + StringWidget widget = getWidget(); + assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_TEXT)); + assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(SingleLineTransformationMethod.class)); + assertThat(widget.widgetAnswerText.getBinding().textView.getTransformationMethod(), equalTo(null)); + } + + @Override + @Test + public void verifyInputTypeWithMaskedAppearance() { + when(formEntryPrompt.getAppearanceHint()).thenReturn(MASKED); + StringWidget widget = getWidget(); + assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)); + assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class)); + } } diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/base/GeneralExStringWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/base/GeneralExStringWidgetTest.java index 8010dd2949c..10b2fcbd86a 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/base/GeneralExStringWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/base/GeneralExStringWidgetTest.java @@ -81,4 +81,10 @@ public void answersShouldBeMaskedIfMaskedAppearanceIsUsed() { assertThat(getSpyWidget().binding.widgetAnswerText.getBinding().editText.getTransformationMethod(), is(instanceOf(PasswordTransformationMethod.class))); assertThat(getSpyWidget().binding.widgetAnswerText.getBinding().textView.getTransformationMethod(), is(instanceOf(PasswordTransformationMethod.class))); } + + @Test + public abstract void verifyKeyboardType(); + + @Test + public abstract void verifyKeyboardTypeWithMaskedAppearance(); } diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/base/GeneralStringWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/base/GeneralStringWidgetTest.java index ead5c8ac67a..536125a3f66 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/base/GeneralStringWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/base/GeneralStringWidgetTest.java @@ -120,4 +120,10 @@ public void answersShouldBeMaskedIfMaskedAppearanceIsUsed() { assertThat(getSpyWidget().widgetAnswerText.getBinding().editText.getTransformationMethod(), is(instanceOf(PasswordTransformationMethod.class))); assertThat(getSpyWidget().widgetAnswerText.getBinding().textView.getTransformationMethod(), is(instanceOf(PasswordTransformationMethod.class))); } + + @Test + public abstract void verifyInputType(); + + @Test + public abstract void verifyInputTypeWithMaskedAppearance(); } \ No newline at end of file