Niedzielski has uploaded a new change for review.
https://gerrit.wikimedia.org/r/319919
Change subject: Add DescriptionEditViewTest
......................................................................
Add DescriptionEditViewTest
Bug: T148203
Change-Id: I67b3250583784a3ba74b69bf46fbee76465dca71
---
A
app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditViewTest.java
M app/src/main/java/org/wikipedia/descriptions/DescriptionEditView.java
2 files changed, 133 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia
refs/changes/19/319919/1
diff --git
a/app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditViewTest.java
b/app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditViewTest.java
new file mode 100644
index 0000000..54e1630
--- /dev/null
+++
b/app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditViewTest.java
@@ -0,0 +1,121 @@
+package org.wikipedia.descriptions;
+
+import android.support.annotation.NonNull;
+
+import org.junit.Test;
+import org.junit.experimental.theories.Theory;
+import org.junit.experimental.theories.suppliers.TestedOn;
+import org.wikipedia.page.PageTitle;
+import org.wikipedia.test.theories.TestedOnBool;
+import org.wikipedia.test.view.FontScale;
+import org.wikipedia.test.view.LayoutDirection;
+import org.wikipedia.test.view.PrimaryTestStr;
+import org.wikipedia.test.view.SecondaryTestStr;
+import org.wikipedia.test.view.TestStr;
+import org.wikipedia.test.view.ViewTest;
+import org.wikipedia.theme.Theme;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.wikipedia.descriptions.DescriptionEditView.Callback;
+import static org.wikipedia.util.StringUtil.emptyIfNull;
+
+public class DescriptionEditViewTest extends ViewTest {
+ private DescriptionEditView subject;
+
+ @Theory public void testWidth(@TestedOn(ints = {WIDTH_DP_XL, WIDTH_DP_L})
int widthDp,
+ @NonNull FontScale fontScale, @NonNull
PrimaryTestStr title,
+ @NonNull SecondaryTestStr description,
+ @TestedOnBool boolean saving) {
+ setUp(widthDp, LayoutDirection.LOCALE, fontScale, Theme.LIGHT, title,
description, saving);
+ snap(subject, title + "_title", description + "_description", saving ?
"saving" : "unsaved");
+ }
+
+ @Theory public void testLayoutDirection(@NonNull LayoutDirection
direction) {
+ setUp(WIDTH_DP_L, direction, FontScale.DEFAULT, Theme.LIGHT,
PrimaryTestStr.SHORT,
+ SecondaryTestStr.SHORT, true);
+ snap(subject);
+ }
+
+ @Theory public void testTheme(@NonNull Theme theme, @TestedOnBool boolean
saving) {
+ setUp(WIDTH_DP_L, LayoutDirection.LOCALE, FontScale.DEFAULT, theme,
PrimaryTestStr.SHORT,
+ SecondaryTestStr.SHORT, saving);
+ snap(subject, saving ? "saving" : "unsaved");
+ }
+
+ @Theory public void testFocus(@NonNull Theme theme, @TestedOnBool boolean
saving) {
+ setUp(WIDTH_DP_L, LayoutDirection.LOCALE, FontScale.DEFAULT, theme,
PrimaryTestStr.SHORT,
+ SecondaryTestStr.SHORT, saving);
+ requestFocus(subject);
+ snap(subject, saving ? "saving" : "unsaved");
+ }
+
+ @Theory public void testSetCallback(@TestedOnBool boolean nul) {
+ defaultSetUp();
+ Callback callback = nul ? null : mock(Callback.class);
+ subject.setCallback(callback);
+
+ subject.onSaveClick();
+ if (callback != null) {
+ verify(callback).onSaveClick();
+ }
+ }
+
+ @Test public void testSetPageTitle() {
+ defaultSetUp();
+ PageTitle expected = mock(PageTitle.class);
+ when(expected.getDisplayText()).thenReturn("title");
+ when(expected.getDescription()).thenReturn("description");
+
+ subject.setPageTitle(expected);
+ assertThat(subject.pageTitleText.getText().toString(),
is(expected.getDisplayText()));
+ assertThat(subject.getDescription(), is(expected.getDescription()));
+ }
+
+ // todo: resolve why the button doesn't show up yet here or in the actual
screenshots above
+ // @Theory public void testSetSaveState(@TestedOnBool final boolean
saving) {
+ // defaultSetUp();
+ // subject.setSaveState(saving);
+ // assertThat(subject.saveButton.isShown(), is(!saving));
+ // }
+
+ @Theory public void testGetDescription(@TestedOnBool boolean nul) {
+ defaultSetUp();
+ String expected = nul ? null : "text";
+ subject.setDescription(expected);
+ assertThat(subject.getDescription(), is(emptyIfNull(expected)));
+ }
+
+ @Theory public void testSetTitle(@TestedOnBool boolean nul) {
+ defaultSetUp();
+ String expected = nul ? null : "text";
+ subject.setTitle(expected);
+ assertThat(subject.pageTitleText.getText().toString(),
is(emptyIfNull(expected)));
+ }
+
+ @Theory public void testSetDescription(@TestedOnBool boolean nul) {
+ defaultSetUp();
+ String expected = nul ? null : "text";
+ subject.setDescription(expected);
+ assertThat(subject.editText.getText().toString(),
is(emptyIfNull(expected)));
+ }
+
+ private void defaultSetUp() {
+ setUp(WIDTH_DP_L, LayoutDirection.LOCALE, FontScale.DEFAULT,
Theme.LIGHT,
+ PrimaryTestStr.SHORT, SecondaryTestStr.SHORT, true);
+ }
+
+ private void setUp(int widthDp, @NonNull LayoutDirection layoutDirection,
+ @NonNull FontScale fontScale, @NonNull Theme theme,
@NonNull TestStr title,
+ @NonNull TestStr description, boolean saving) {
+ setUp(widthDp, layoutDirection, fontScale, theme);
+
+ subject = new DescriptionEditView(ctx());
+ subject.setTitle(str(title));
+ subject.setDescription(str(description));
+ subject.setSaveState(saving);
+ }
+}
\ No newline at end of file
diff --git
a/app/src/main/java/org/wikipedia/descriptions/DescriptionEditView.java
b/app/src/main/java/org/wikipedia/descriptions/DescriptionEditView.java
index 54087c3..3e36696 100644
--- a/app/src/main/java/org/wikipedia/descriptions/DescriptionEditView.java
+++ b/app/src/main/java/org/wikipedia/descriptions/DescriptionEditView.java
@@ -7,6 +7,7 @@
import android.support.annotation.ColorRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import android.support.annotation.VisibleForTesting;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.text.Editable;
@@ -69,10 +70,8 @@
public void setPageTitle(@NonNull PageTitle pageTitle) {
this.pageTitle = pageTitle;
- originalDescription =
StringUtil.emptyIfNull(pageTitle.getDescription());
-
- pageTitleText.setText(pageTitle.getDisplayText());
- editText.setText(pageTitle.getDescription());
+ setTitle(pageTitle.getDisplayText());
+ setDescription(StringUtil.emptyIfNull(pageTitle.getDescription()));
}
public void setSaveState(boolean saving) {
@@ -101,6 +100,15 @@
updateCharCount();
}
+ @VisibleForTesting void setTitle(@Nullable CharSequence text) {
+ pageTitleText.setText(text);
+ }
+
+ @VisibleForTesting void setDescription(@Nullable String text) {
+ originalDescription = text;
+ editText.setText(text);
+ }
+
private void init() {
inflate(getContext(), R.layout.view_description_edit, this);
ButterKnife.bind(this);
--
To view, visit https://gerrit.wikimedia.org/r/319919
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I67b3250583784a3ba74b69bf46fbee76465dca71
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits