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

Text question type should allow new lines, wrap text, and respect the rows attribute #6271

Merged
merged 3 commits into from
Jul 19, 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 @@ -59,11 +59,9 @@ class WidgetAnswerText(context: Context, attrs: AttributeSet?) : FrameLayout(con
}
})
if (isMasked) {
binding.editText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
binding.editText.inputType = binding.editText.inputType or InputType.TYPE_TEXT_VARIATION_PASSWORD
binding.editText.transformationMethod = PasswordTransformationMethod.getInstance()
binding.textView.transformationMethod = PasswordTransformationMethod.getInstance()
} else {
binding.editText.inputType = InputType.TYPE_CLASS_TEXT
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import static org.odk.collect.android.utilities.Appearances.THOUSANDS_SEP;

import android.text.InputType;
import android.text.method.SingleLineTransformationMethod;

import androidx.annotation.NonNull;

Expand Down Expand Up @@ -216,6 +215,6 @@ public void separatorsShouldBeAddedWhenEnabled() {
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));
assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod(), equalTo(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import static org.odk.collect.android.utilities.Appearances.THOUSANDS_SEP;

import android.text.InputType;
import android.text.method.SingleLineTransformationMethod;

import androidx.annotation.NonNull;

Expand Down Expand Up @@ -99,7 +98,7 @@ public void separatorsShouldBeAddedWhenEnabled() {
public void verifyInputType() {
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().editText.getTransformationMethod(), equalTo(null));
assertThat(widget.binding.widgetAnswerText.getBinding().textView.getTransformationMethod(), equalTo(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import static org.odk.collect.android.utilities.Appearances.THOUSANDS_SEP;

import android.text.InputType;
import android.text.method.SingleLineTransformationMethod;

import androidx.annotation.NonNull;

Expand Down Expand Up @@ -73,7 +72,7 @@ public void separatorsShouldBeAddedWhenEnabled() {
public void verifyInputType() {
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().editText.getTransformationMethod(), equalTo(null));
assertThat(widget.binding.widgetAnswerText.getBinding().textView.getTransformationMethod(), equalTo(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import android.text.method.SingleLineTransformationMethod;

/**
* @author James Knight
Expand Down Expand Up @@ -58,16 +57,16 @@ public void setUp() throws Exception {
@Test
public void verifyInputType() {
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().editText.getInputType(), equalTo(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE));
assertThat(widget.binding.widgetAnswerText.getBinding().editText.getTransformationMethod(), equalTo(null));
assertThat(widget.binding.widgetAnswerText.getBinding().textView.getTransformationMethod(), equalTo(null));
}

@Test
public void verifyInputTypeWithMaskedAppearance() {
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.getInputType(), equalTo(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | 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));
}
Expand All @@ -85,4 +84,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 void whenNumberOfRowsSpecifiedEditTextShouldHaveProperNumberOfMinLines() {
when(questionDef.getAdditionalAttribute(null, "rows")).thenReturn("5");
assertThat(getWidget().binding.widgetAnswerText.getBinding().editText.getMinLines(), equalTo(5));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import static org.odk.collect.android.utilities.Appearances.THOUSANDS_SEP;

import android.text.InputType;
import android.text.method.SingleLineTransformationMethod;

import androidx.annotation.NonNull;

Expand Down Expand Up @@ -60,6 +59,6 @@ public void separatorsShouldBeAddedWhenEnabled() {
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));
assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod(), equalTo(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
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;

import androidx.annotation.NonNull;

Expand Down Expand Up @@ -60,14 +57,6 @@ public void separatorsShouldBeAddedWhenEnabled() {
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));
}

@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));
assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod(), equalTo(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import android.text.method.SingleLineTransformationMethod;

import androidx.annotation.NonNull;

Expand Down Expand Up @@ -45,16 +44,15 @@ public StringData getNextAnswer() {
@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));
assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE));
assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod(), equalTo(null));
}

@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.getInputType(), equalTo(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_VARIATION_PASSWORD));
assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class));
}

Expand All @@ -71,4 +69,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 void whenNumberOfRowsSpecifiedEditTextShouldHaveProperNumberOfMinLines() {
when(questionDef.getAdditionalAttribute(null, "rows")).thenReturn("5");
assertThat(getWidget().widgetAnswerText.getBinding().editText.getMinLines(), equalTo(5));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

import android.view.View;

import org.javarosa.core.model.QuestionDef;
import org.javarosa.core.model.data.IAnswerData;
import org.junit.Test;
import org.mockito.Mock;
import org.odk.collect.android.R;
import org.odk.collect.android.support.WidgetTestActivity;
import org.odk.collect.android.widgets.StringWidget;
Expand All @@ -25,15 +23,6 @@
public abstract class GeneralStringWidgetTest<W extends StringWidget, A extends IAnswerData>
extends QuestionWidgetTest<W, A> {

@Mock
QuestionDef questionDef;

@Override
public void setUp() throws Exception {
super.setUp();
when(formEntryPrompt.getQuestion()).thenReturn(questionDef);
}

@Override
public void callingClearShouldRemoveTheExistingAnswer() {
super.callingClearShouldRemoveTheExistingAnswer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public abstract class WidgetTest {

protected final SettingsProvider settingsProvider = TestSettingsProvider.getSettingsProvider();

@Mock
protected QuestionDef questionDef;

@Before
@OverridingMethodsMustInvokeSuper
public void setUp() throws Exception {
Expand All @@ -48,7 +51,7 @@ public void setUp() throws Exception {
when(formEntryPrompt.getIndex()).thenReturn(mock(FormIndex.class));
when(formEntryPrompt.getIndex().toString()).thenReturn("0, 0");
when(formEntryPrompt.getFormElement()).thenReturn(formElement);
when(formEntryPrompt.getQuestion()).thenReturn(mock(QuestionDef.class));
when(formEntryPrompt.getQuestion()).thenReturn(questionDef);
}

@Test
Expand Down