diff --git a/app/build.gradle b/app/build.gradle index bfaaae63d..74f781322 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -81,6 +81,7 @@ android { dependencies { implementation project(':core') implementation "androidx.appcompat:appcompat:${versions.appcompat}" + //noinspection OutdatedLibrary implementation "com.crashlytics.sdk.android:crashlytics:${versions.crashlytics}" implementation "com.google.firebase:firebase-core:${versions.firebase}" implementation "com.github.bumptech.glide:glide:${versions.glide}" diff --git a/app/src/androidTest/java/io/plaidapp/ui/AboutActivityTest.kt b/app/src/androidTest/java/io/plaidapp/ui/AboutActivityTest.kt new file mode 100644 index 000000000..596b0a44d --- /dev/null +++ b/app/src/androidTest/java/io/plaidapp/ui/AboutActivityTest.kt @@ -0,0 +1,86 @@ +package io.plaidapp.ui + + +import android.view.View +import android.view.ViewGroup +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.Espresso.pressBack +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.matcher.ViewMatchers.* +import androidx.test.filters.LargeTest +import androidx.test.rule.ActivityTestRule +import androidx.test.runner.AndroidJUnit4 +import io.plaidapp.R +import org.hamcrest.Description +import org.hamcrest.Matcher +import org.hamcrest.Matchers.allOf +import org.hamcrest.TypeSafeMatcher +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@LargeTest +@RunWith(AndroidJUnit4::class) +class AboutActivityTest { + + @Rule + @JvmField + var mActivityTestRule = ActivityTestRule(HomeActivity::class.java) + + @Test + fun aboutActivityTest() { + // Added a sleep statement to match the app's execution delay. + // The recommended way to handle such scenarios is to use Espresso idling resources: + // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html + Thread.sleep(7000) + + val overflowMenuButton = onView( + allOf(withContentDescription("More options"), + childAtPosition( + childAtPosition( + withId(R.id.toolbar), + 1), + 3), + isDisplayed())) + overflowMenuButton.perform(click()) + + // Added a sleep statement to match the app's execution delay. + // The recommended way to handle such scenarios is to use Espresso idling resources: + // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html + Thread.sleep(250) + + val appCompatTextView = onView( + allOf(withId(R.id.title), withText("About"), + childAtPosition( + childAtPosition( + withId(R.id.content), + 0), + 0), + isDisplayed())) + appCompatTextView.perform(click()) + + // Added a sleep statement to match the app's execution delay. + // The recommended way to handle such scenarios is to use Espresso idling resources: + // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html + Thread.sleep(7000) + + pressBack() + } + + private fun childAtPosition( + parentMatcher: Matcher, position: Int): Matcher { + + return object : TypeSafeMatcher() { + override fun describeTo(description: Description) { + description.appendText("Child at position $position in parent ") + parentMatcher.describeTo(description) + } + + public override fun matchesSafely(view: View): Boolean { + val parent = view.parent + return parent is ViewGroup && parentMatcher.matches(parent) + && view == parent.getChildAt(position) + } + } + } +} diff --git a/app/src/androidTest/java/io/plaidapp/ui/CheckingToolbarItems.kt b/app/src/androidTest/java/io/plaidapp/ui/CheckingToolbarItems.kt new file mode 100644 index 000000000..13b93f8e0 --- /dev/null +++ b/app/src/androidTest/java/io/plaidapp/ui/CheckingToolbarItems.kt @@ -0,0 +1,69 @@ +package io.plaidapp.ui + + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.* +import androidx.test.filters.LargeTest +import androidx.test.rule.ActivityTestRule +import androidx.test.runner.AndroidJUnit4 +import io.plaidapp.R +import org.hamcrest.Matchers.allOf +import org.hamcrest.core.IsInstanceOf +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@LargeTest +@RunWith(AndroidJUnit4::class) +class CheckingToolbarItems { + + @Rule + @JvmField + var mActivityTestRule = ActivityTestRule(HomeActivity::class.java) + + @Test + fun checkingToolbarItems() { + // Added a sleep statement to match the app's execution delay. + // The recommended way to handle such scenarios is to use Espresso idling resources: + // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html + Thread.sleep(7000) + + val viewGroup = onView( + allOf(withId(R.id.toolbar), + withParent(withParent(withId(R.id.drawer))), + isDisplayed())) + viewGroup.check(matches(isDisplayed())) + + val textView = onView( + allOf(withText("Plaid"), + withParent(allOf(withId(R.id.toolbar), + withParent(IsInstanceOf.instanceOf(android.widget.FrameLayout::class.java)))), + isDisplayed())) + textView.check(matches(withText("Plaid"))) + + val textView2 = onView( + allOf(withId(R.id.menu_search), withContentDescription("Search"), + withParent(withParent(withId(R.id.toolbar))), + isDisplayed())) + textView2.check(matches(isDisplayed())) + + val checkBox = onView( + allOf(withId(R.id.menu_theme), + withParent(withParent(withId(R.id.toolbar))), + isDisplayed())) + checkBox.check(matches(isDisplayed())) + + val textView3 = onView( + allOf(withId(R.id.menu_filter), withContentDescription("Filter"), + withParent(withParent(withId(R.id.toolbar))), + isDisplayed())) + textView3.check(matches(isDisplayed())) + + val imageView = onView( + allOf(withContentDescription("More options"), + withParent(withParent(withId(R.id.toolbar))), + isDisplayed())) + imageView.check(matches(isDisplayed())) + } +} diff --git a/app/src/androidTest/java/io/plaidapp/ui/FilterActivityTest.kt b/app/src/androidTest/java/io/plaidapp/ui/FilterActivityTest.kt new file mode 100644 index 000000000..1a2051a9f --- /dev/null +++ b/app/src/androidTest/java/io/plaidapp/ui/FilterActivityTest.kt @@ -0,0 +1,170 @@ +package io.plaidapp.ui + + +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView.ViewHolder +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.Espresso.pressBack +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition +import androidx.test.espresso.matcher.ViewMatchers.* +import androidx.test.filters.LargeTest +import androidx.test.rule.ActivityTestRule +import androidx.test.runner.AndroidJUnit4 +import io.plaidapp.R +import org.hamcrest.Description +import org.hamcrest.Matcher +import org.hamcrest.Matchers.allOf +import org.hamcrest.TypeSafeMatcher +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@LargeTest +@RunWith(AndroidJUnit4::class) +class FilterActivityTest { + + @Rule + @JvmField + var mActivityTestRule = ActivityTestRule(HomeActivity::class.java) + + @Test + fun filterActivityTest() { + // Added a sleep statement to match the app's execution delay. + // The recommended way to handle such scenarios is to use Espresso idling resources: + // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html + Thread.sleep(7000) + + val actionMenuItemView = onView( + allOf( + withId(R.id.menu_filter), withContentDescription("Filter"), + childAtPosition( + childAtPosition( + withId(R.id.toolbar), + 1 + ), + 2 + ), + isDisplayed() + ) + ) + actionMenuItemView.perform(click()) + + val recyclerView = onView( + allOf( + withId(R.id.filters), + childAtPosition( + withId(R.id.drawer), + 1 + ) + ) + ) + recyclerView.perform(actionOnItemAtPosition(0, click())) + + val recyclerView2 = onView( + allOf( + withId(R.id.filters), + childAtPosition( + withId(R.id.drawer), + 1 + ) + ) + ) + recyclerView2.perform(actionOnItemAtPosition(1, click())) + + val actionMenuItemView2 = onView( + allOf( + withId(R.id.menu_filter), withContentDescription("Filter"), + childAtPosition( + childAtPosition( + withId(R.id.toolbar), + 1 + ), + 2 + ), + isDisplayed() + ) + ) + actionMenuItemView2.perform(click()) + + val recyclerView3 = onView( + allOf( + withId(R.id.filters), + childAtPosition( + withId(R.id.drawer), + 1 + ) + ) + ) + recyclerView3.perform(actionOnItemAtPosition(0, click())) + + val recyclerView4 = onView( + allOf( + withId(R.id.filters), + childAtPosition( + withId(R.id.drawer), + 1 + ) + ) + ) + recyclerView4.perform(actionOnItemAtPosition(2, click())) + + val actionMenuItemView3 = onView( + allOf( + withId(R.id.menu_filter), withContentDescription("Filter"), + childAtPosition( + childAtPosition( + withId(R.id.toolbar), + 1 + ), + 2 + ), + isDisplayed() + ) + ) + actionMenuItemView3.perform(click()) + + val recyclerView5 = onView( + allOf( + withId(R.id.filters), + childAtPosition( + withId(R.id.drawer), + 1 + ) + ) + ) + recyclerView5.perform(actionOnItemAtPosition(2, click())) + + val recyclerView6 = onView( + allOf( + withId(R.id.filters), + childAtPosition( + withId(R.id.drawer), + 1 + ) + ) + ) + recyclerView6.perform(actionOnItemAtPosition(1, click())) + + pressBack() + } + + private fun childAtPosition( + parentMatcher: Matcher, position: Int + ): Matcher { + + return object : TypeSafeMatcher() { + override fun describeTo(description: Description) { + description.appendText("Child at position $position in parent ") + parentMatcher.describeTo(description) + } + + public override fun matchesSafely(view: View): Boolean { + val parent = view.parent + return parent is ViewGroup && parentMatcher.matches(parent) + && view == parent.getChildAt(position) + } + } + } +} diff --git a/app/src/androidTest/java/io/plaidapp/ui/HomeActivityTest.kt b/app/src/androidTest/java/io/plaidapp/ui/HomeActivityTest.kt deleted file mode 100644 index 67a99d736..000000000 --- a/app/src/androidTest/java/io/plaidapp/ui/HomeActivityTest.kt +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2018 Google LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.plaidapp.ui - -import android.view.Gravity -import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.action.ViewActions.click -import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.contrib.DrawerMatchers.isClosed -import androidx.test.espresso.contrib.DrawerMatchers.isOpen -import androidx.test.espresso.matcher.ViewMatchers.withId -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.rule.ActivityTestRule -import androidx.test.uiautomator.UiDevice -import io.plaidapp.R -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(AndroidJUnit4::class) -class HomeActivityTest { - - @Rule - @JvmField - var activityTestRule = ActivityTestRule(HomeActivity::class.java) - - @Test - fun drawerClosedOnStartup() { - // Given that the app is not launched - - // When the app is first launched - - // Then the drawer should be closed - onView(withId(R.id.drawer)).check(matches(isClosed(Gravity.END))) - } - - @Test - fun pressFilterButtonOpensDrawer() { - // Given that the drawer is closed - onView(withId(R.id.drawer)).check(matches(isClosed(Gravity.END))) - - // When the filter button is pressed - onView(withId(R.id.menu_filter)).perform(click()) - - // Then the drawer should be opened - onView(withId(R.id.drawer)).check(matches(isOpen(Gravity.END))) - } - - @Test - fun drawerStaysOpenAfterRotation() { - // Given that the drawer is open - onView(withId(R.id.menu_filter)).perform(click()) - onView(withId(R.id.drawer)).check(matches(isOpen(Gravity.END))) - - // When rotating the device - UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).setOrientationLeft() - - // Then the drawer should stay open after rotation - onView(withId(R.id.drawer)).check(matches(isOpen(Gravity.END))) - } -} diff --git a/app/src/androidTest/java/io/plaidapp/ui/LogintoDesignerNewsActivityTest.kt b/app/src/androidTest/java/io/plaidapp/ui/LogintoDesignerNewsActivityTest.kt new file mode 100644 index 000000000..a8989374e --- /dev/null +++ b/app/src/androidTest/java/io/plaidapp/ui/LogintoDesignerNewsActivityTest.kt @@ -0,0 +1,84 @@ +package io.plaidapp.ui + + +import android.view.View +import android.view.ViewGroup +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.matcher.ViewMatchers.* +import androidx.test.filters.LargeTest +import androidx.test.rule.ActivityTestRule +import androidx.test.runner.AndroidJUnit4 +import io.plaidapp.R +import org.hamcrest.Description +import org.hamcrest.Matcher +import org.hamcrest.Matchers.allOf +import org.hamcrest.TypeSafeMatcher +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@LargeTest +@RunWith(AndroidJUnit4::class) +class LogintoDesignerNewsActivityTest { + + @Rule + @JvmField + var mActivityTestRule = ActivityTestRule(HomeActivity::class.java) + + @Test + fun logintoDesignerNewsActivityTest() { + // Added a sleep statement to match the app's execution delay. + // The recommended way to handle such scenarios is to use Espresso idling resources: + // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html + Thread.sleep(7000) + + val overflowMenuButton = onView( + allOf(withContentDescription("More options"), + childAtPosition( + childAtPosition( + withId(R.id.toolbar), + 1), + 3), + isDisplayed())) + overflowMenuButton.perform(click()) + + // Added a sleep statement to match the app's execution delay. + // The recommended way to handle such scenarios is to use Espresso idling resources: + // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html + Thread.sleep(250) + + val appCompatTextView = onView( + allOf(withId(R.id.title), withText("Log in to Designer News"), + childAtPosition( + childAtPosition( + withId(R.id.content), + 0), + 0), + isDisplayed())) + appCompatTextView.perform(click()) + + // Added a sleep statement to match the app's execution delay. + // The recommended way to handle such scenarios is to use Espresso idling resources: + // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html + Thread.sleep(7000) + } + + + private fun childAtPosition( + parentMatcher: Matcher, position: Int): Matcher { + + return object : TypeSafeMatcher() { + override fun describeTo(description: Description) { + description.appendText("Child at position $position in parent ") + parentMatcher.describeTo(description) + } + + public override fun matchesSafely(view: View): Boolean { + val parent = view.parent + return parent is ViewGroup && parentMatcher.matches(parent) + && view == parent.getChildAt(position) + } + } + } +} diff --git a/app/src/androidTest/java/io/plaidapp/ui/MenuSearchActivityTest.kt b/app/src/androidTest/java/io/plaidapp/ui/MenuSearchActivityTest.kt new file mode 100644 index 000000000..7c9999b22 --- /dev/null +++ b/app/src/androidTest/java/io/plaidapp/ui/MenuSearchActivityTest.kt @@ -0,0 +1,83 @@ +package io.plaidapp.ui + + +import android.view.View +import android.view.ViewGroup +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.* +import androidx.test.espresso.matcher.ViewMatchers.* +import androidx.test.filters.LargeTest +import androidx.test.rule.ActivityTestRule +import androidx.test.runner.AndroidJUnit4 +import io.plaidapp.R +import org.hamcrest.Description +import org.hamcrest.Matcher +import org.hamcrest.Matchers.`is` +import org.hamcrest.Matchers.allOf +import org.hamcrest.TypeSafeMatcher +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@LargeTest +@RunWith(AndroidJUnit4::class) +class MenuSearchActivityTest +{ + + private val SearchAutoComplete: String = "" + + @Rule + @JvmField + var mActivityTestRule = ActivityTestRule(HomeActivity::class.java) + + @Test + fun menuSearchActivityTest() { + // Added a sleep statement to match the app's execution delay. + // The recommended way to handle such scenarios is to use Espresso idling resources: + // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html + Thread.sleep(7000) + + val actionMenuItemView = onView( + allOf(withId(R.id.menu_search), withContentDescription("Search"), + childAtPosition( + childAtPosition( + withId(R.id.toolbar), + 1), + 0), + isDisplayed())) + actionMenuItemView.perform(click()) + + // Added a sleep statement to match the app's execution delay. + // The recommended way to handle such scenarios is to use Espresso idling resources: + // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html + Thread.sleep(7000) + + val searchAutoComplete = onView( + allOf(withClassName(`is`("${SearchAutoComplete}")), + childAtPosition( + allOf(withClassName(`is`("android.widget.LinearLayout")), + childAtPosition( + withClassName(`is`("android.widget.LinearLayout")), + 1)), + 0), + isDisplayed())) + searchAutoComplete.perform(replaceText("Design"), closeSoftKeyboard()) + } + + private fun childAtPosition( + parentMatcher: Matcher, position: Int): Matcher { + + return object : TypeSafeMatcher() { + override fun describeTo(description: Description) { + description.appendText("Child at position $position in parent ") + parentMatcher.describeTo(description) + } + + public override fun matchesSafely(view: View): Boolean { + val parent = view.parent + return parent is ViewGroup && parentMatcher.matches(parent) + && view == parent.getChildAt(position) + } + } + } +} diff --git a/app/src/androidTest/java/io/plaidapp/ui/MenuThemeActivityTest.kt b/app/src/androidTest/java/io/plaidapp/ui/MenuThemeActivityTest.kt new file mode 100644 index 000000000..4a54c9326 --- /dev/null +++ b/app/src/androidTest/java/io/plaidapp/ui/MenuThemeActivityTest.kt @@ -0,0 +1,96 @@ +package io.plaidapp.ui + + +import android.view.View +import android.view.ViewGroup +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.filters.LargeTest +import androidx.test.rule.ActivityTestRule +import androidx.test.runner.AndroidJUnit4 +import io.plaidapp.R +import org.hamcrest.Description +import org.hamcrest.Matcher +import org.hamcrest.Matchers.allOf +import org.hamcrest.TypeSafeMatcher +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@LargeTest +@RunWith(AndroidJUnit4::class) +class MenuThemeActivityTest +{ + + @Rule + @JvmField + var mActivityTestRule = ActivityTestRule(HomeActivity::class.java) + + @Test + fun menuThemeActivityTest() { + // Added a sleep statement to match the app's execution delay. + // The recommended way to handle such scenarios is to use Espresso idling resources: + // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html + Thread.sleep(7000) + + val appCompatCheckBox = onView( + allOf(withId(R.id.menu_theme), + childAtPosition( + childAtPosition( + withId(R.id.toolbar), + 1), + 1), + isDisplayed())) + appCompatCheckBox.perform(click()) + + // Added a sleep statement to match the app's execution delay. + // The recommended way to handle such scenarios is to use Espresso idling resources: + // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html + Thread.sleep(7000) + + val appCompatCheckBox2 = onView( + allOf(withId(R.id.menu_theme), + childAtPosition( + childAtPosition( + withId(R.id.toolbar), + 1), + 1), + isDisplayed())) + appCompatCheckBox2.perform(click()) + + // Added a sleep statement to match the app's execution delay. + // The recommended way to handle such scenarios is to use Espresso idling resources: + // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html + Thread.sleep(7000) + + val appCompatCheckBox3 = onView( + allOf(withId(R.id.menu_theme), + childAtPosition( + childAtPosition( + withId(R.id.toolbar), + 1), + 1), + isDisplayed())) + appCompatCheckBox3.perform(click()) + Thread.sleep(7000) + } + + private fun childAtPosition( + parentMatcher: Matcher, position: Int): Matcher { + + return object : TypeSafeMatcher() { + override fun describeTo(description: Description) { + description.appendText("Child at position $position in parent ") + parentMatcher.describeTo(description) + } + + public override fun matchesSafely(view: View): Boolean { + val parent = view.parent + return parent is ViewGroup && parentMatcher.matches(parent) + && view == parent.getChildAt(position) + } + } + } +}