Mholloway has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/378255 )

Change subject: [DONOTMERGE] Demo: View test breakage
......................................................................

[DONOTMERGE] Demo: View test breakage

The recent patches reworking our theme structure broke most if not all of
the view tests running on our periodic CI testing job.  The issue is that
various attributes are no longer being found.  This patch demonstates the
steps I've taken so far in attempting to fix them, including:

* Creating our ContextThemeWrapper objects from AppTheme rather than
  Theme.LIGHT or Theme.DARK, since these latter no longer inherit from a
  system theme;

* Then explicitly setting the new light or dark theme on the ContextTheme-
  Wrapper, which seems to work cumulatively, as expected.

Still, it seems certain attributes are still not being found, e.g.,
?attr/selectableItemBackground.

For exploratory purposes I'm focusing on the first test in DescriptionEdit-
HelpViewTest.  This is currently only passing because I've removed the
reference to ?attr/selectableItemBackground.

(Note that this code is solely exploratory in nature and not close to
production-quality!)

Change-Id: I28ca8aba11c836ac799f1e1448ff11397f494ebe
---
M 
app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditHelpViewTest.java
M app/src/androidTest/java/org/wikipedia/test/view/ViewTest.java
M app/src/main/res/layout/view_description_edit_help.xml
3 files changed, 35 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/55/378255/1

diff --git 
a/app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditHelpViewTest.java
 
b/app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditHelpViewTest.java
index 580acee..3640095 100644
--- 
a/app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditHelpViewTest.java
+++ 
b/app/src/androidTest/java/org/wikipedia/descriptions/DescriptionEditHelpViewTest.java
@@ -4,6 +4,7 @@
 
 import org.junit.experimental.theories.Theory;
 import org.junit.experimental.theories.suppliers.TestedOn;
+import org.wikipedia.R;
 import org.wikipedia.test.theories.TestedOnBool;
 import org.wikipedia.test.view.FontScale;
 import org.wikipedia.test.view.LayoutDirection;
@@ -19,11 +20,11 @@
 
     @Theory public void testWidth(@TestedOn(ints = {WIDTH_DP_XL, WIDTH_DP_L}) 
int widthDp,
                                   @NonNull FontScale fontScale) {
-        setUp(widthDp, LayoutDirection.LOCALE, fontScale, Theme.LIGHT);
+        setUp(widthDp, LayoutDirection.LOCALE, fontScale, R.style.AppTheme);
         snap(subject);
     }
 
-    @Theory public void testLayoutDirection(@NonNull LayoutDirection 
direction) {
+    /*@Theory public void testLayoutDirection(@NonNull LayoutDirection 
direction) {
         setUp(WIDTH_DP_L, direction, FontScale.DEFAULT, Theme.LIGHT);
         snap(subject);
     }
@@ -50,16 +51,17 @@
             verify(callback).onAboutClick();
             verify(callback).onGuideClick();
         }
-    }
+    }*/
 
     private void defaultSetUp() {
-        setUp(WIDTH_DP_L, LayoutDirection.LOCALE, FontScale.DEFAULT, 
Theme.LIGHT);
+        setUp(WIDTH_DP_L, LayoutDirection.LOCALE, FontScale.DEFAULT, 
R.style.AppTheme);
     }
 
     @Override
     protected void setUp(int widthDp, @NonNull LayoutDirection layoutDirection,
-                       @NonNull FontScale fontScale, @NonNull Theme theme) {
-        super.setUp(widthDp, layoutDirection, fontScale, theme);
+                       @NonNull FontScale fontScale, @NonNull int themeResId) {
+        super.setUp(widthDp, layoutDirection, fontScale, themeResId);
+        setColorTheme(R.style.ThemeLight);
         subject = new DescriptionEditHelpView(ctx());
     }
 }
diff --git a/app/src/androidTest/java/org/wikipedia/test/view/ViewTest.java 
b/app/src/androidTest/java/org/wikipedia/test/view/ViewTest.java
index 521cdd0..eba6009 100644
--- a/app/src/androidTest/java/org/wikipedia/test/view/ViewTest.java
+++ b/app/src/androidTest/java/org/wikipedia/test/view/ViewTest.java
@@ -9,6 +9,7 @@
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.annotation.StringRes;
+import android.support.annotation.StyleRes;
 import android.support.v4.text.TextUtilsCompat;
 import android.view.ContextThemeWrapper;
 import android.view.View;
@@ -71,30 +72,47 @@
     private Locale locale;
     private LayoutDirection layoutDirection;
     private FontScale fontScale;
-    private Theme theme;
+    @StyleRes private int themeResId;
     private Context ctx;
 
+    // TODO: REMOVE?
     protected void setUp(int widthDp, @NonNull LayoutDirection layoutDirection,
                          @NonNull FontScale fontScale, @NonNull Theme theme) {
-        setUp(widthDp, null, LOCALES[0], layoutDirection, fontScale, theme);
+        setUp(widthDp, null, LOCALES[0], layoutDirection, fontScale, 
theme.getResourceId());
+    }
+
+    protected void setUp(int widthDp, @NonNull LayoutDirection layoutDirection,
+                         @NonNull FontScale fontScale, @StyleRes int 
themeResId) {
+        setUp(widthDp, null, LOCALES[0], layoutDirection, fontScale, 
themeResId);
     }
 
     protected void setUp(int widthDp, int heightDp, @NonNull LayoutDirection 
layoutDirection,
                          @NonNull FontScale fontScale, @NonNull Theme theme) {
-        setUp(widthDp, heightDp, LOCALES[0], layoutDirection, fontScale, 
theme);
+        setUp(widthDp, heightDp, LOCALES[0], layoutDirection, fontScale, 
theme.getResourceId());
+    }
+
+    protected void setUp(int widthDp, int heightDp, @NonNull LayoutDirection 
layoutDirection,
+                         @NonNull FontScale fontScale, @StyleRes int 
themeResId) {
+        setUp(widthDp, heightDp, LOCALES[0], layoutDirection, fontScale, 
themeResId);
     }
 
     protected void setUp(int widthDp, @Nullable Integer heightDp, @NonNull 
Locale locale,
                          @NonNull LayoutDirection layoutDirection, @NonNull 
FontScale fontScale,
-                         @NonNull Theme theme) {
+                         @StyleRes int themeResId) {
         this.widthDp = widthDp;
         this.heightDp = heightDp;
         this.locale = locale;
         this.layoutDirection = layoutDirection;
         this.fontScale = fontScale;
-        this.theme = theme;
-        ctx = new ContextThemeWrapper(getTargetContext(), 
theme.getResourceId());
+        this.themeResId = themeResId;
+        ctx = new ContextThemeWrapper(getTargetContext(), themeResId);
         config();
+    }
+
+    protected void setColorTheme(@StyleRes int themeResId) {
+        if (ctx != null) {
+            ctx.setTheme(themeResId);
+        }
     }
 
     protected void snap(@NonNull View subject, @Nullable String... dataPoints) 
{
@@ -118,7 +136,7 @@
         list.add(locale.toString());
         list.add(layoutDirection == LayoutDirection.RTL ? "rtl" : "ltr");
         list.add("font" + fontScale.multiplier() + "x");
-        list.add(theme.toString().toLowerCase(Locale.ENGLISH));
+        
list.add(ctx.getResources().getResourceEntryName(themeResId).toLowerCase(Locale.ENGLISH));
         list.addAll(Arrays.asList(ArrayUtils.nullToEmpty(dataPoints)));
         Screenshot.snap(subject).setName(testName(list)).record();
     }
diff --git a/app/src/main/res/layout/view_description_edit_help.xml 
b/app/src/main/res/layout/view_description_edit_help.xml
index 46bc7f7..3c13045 100644
--- a/app/src/main/res/layout/view_description_edit_help.xml
+++ b/app/src/main/res/layout/view_description_edit_help.xml
@@ -24,8 +24,7 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:clipToPadding="false"
-        android:clickable="true"
-        android:background="?attr/selectableItemBackground">
+        android:clickable="true">
         <ImageView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
@@ -48,8 +47,7 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:clipToPadding="false"
-        android:clickable="true"
-        android:background="?attr/selectableItemBackground">
+        android:clickable="true">
         <ImageView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"

-- 
To view, visit https://gerrit.wikimedia.org/r/378255
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I28ca8aba11c836ac799f1e1448ff11397f494ebe
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Mholloway <mhollo...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to