diff --git a/app/build.gradle b/app/build.gradle index 63e96ffe9d..c60195a00f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -110,7 +110,8 @@ android { applicationId "com.kickstarter" minSdkVersion 23 targetSdkVersion 30 - testInstrumentationRunner "com.karumi.shot.ShotTestRunner" + testApplicationId "com.kickstarter.internal.debug.test" + testInstrumentationRunner "com.kickstarter.screenshoot.testing.KSScreenShotTestRunner" buildConfigField "String", "GIT_SHA", "\"${commitSha()}\"" buildConfigField "String", "BUILD_DATE", "\"${buildDate()}\"" @@ -194,6 +195,9 @@ android { } packagingOptions { + jniLibs { + useLegacyPackaging = true + } exclude 'META-INF/LICENSE.txt' exclude 'LICENSE.txt' exclude 'META-INF/AL2.0' @@ -373,5 +377,5 @@ apply plugin: 'com.google.gms.google-services' apply plugin: 'shot' shot { - runInstrumentation = false + useComposer = false } \ No newline at end of file diff --git a/app/screenshots/external/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_COMMENT_FOR_LOGIN_BACKED_USERS.png b/app/screenshots/external/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_COMMENT_FOR_LOGIN_BACKED_USERS.png new file mode 100644 index 0000000000..ee82c25370 Binary files /dev/null and b/app/screenshots/external/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_COMMENT_FOR_LOGIN_BACKED_USERS.png differ diff --git a/app/screenshots/external/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_COMMENT_WITH_REPLIES.png b/app/screenshots/external/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_COMMENT_WITH_REPLIES.png new file mode 100644 index 0000000000..54d37f52e8 Binary files /dev/null and b/app/screenshots/external/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_COMMENT_WITH_REPLIES.png differ diff --git a/app/screenshots/external/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_DELETED_COMMENT.png b/app/screenshots/external/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_DELETED_COMMENT.png new file mode 100644 index 0000000000..9c2c7c01e7 Binary files /dev/null and b/app/screenshots/external/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_DELETED_COMMENT.png differ diff --git a/app/screenshots/external/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_FAILED_TO_SEND_COMMENT.png b/app/screenshots/external/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_FAILED_TO_SEND_COMMENT.png new file mode 100644 index 0000000000..e9efda013b Binary files /dev/null and b/app/screenshots/external/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_FAILED_TO_SEND_COMMENT.png differ diff --git a/app/screenshots/external/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_RE_TRYING_TO_POST.png b/app/screenshots/external/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_RE_TRYING_TO_POST.png new file mode 100644 index 0000000000..1e0d77c180 Binary files /dev/null and b/app/screenshots/external/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_RE_TRYING_TO_POST.png differ diff --git a/app/screenshots/internal/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_COMMENT_FOR_LOGIN_BACKED_USERS.png b/app/screenshots/internal/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_COMMENT_FOR_LOGIN_BACKED_USERS.png new file mode 100644 index 0000000000..ee82c25370 Binary files /dev/null and b/app/screenshots/internal/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_COMMENT_FOR_LOGIN_BACKED_USERS.png differ diff --git a/app/screenshots/internal/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_COMMENT_WITH_REPLIES.png b/app/screenshots/internal/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_COMMENT_WITH_REPLIES.png new file mode 100644 index 0000000000..54d37f52e8 Binary files /dev/null and b/app/screenshots/internal/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_COMMENT_WITH_REPLIES.png differ diff --git a/app/screenshots/internal/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_DELETED_COMMENT.png b/app/screenshots/internal/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_DELETED_COMMENT.png new file mode 100644 index 0000000000..9c2c7c01e7 Binary files /dev/null and b/app/screenshots/internal/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_DELETED_COMMENT.png differ diff --git a/app/screenshots/internal/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_FAILED_TO_SEND_COMMENT.png b/app/screenshots/internal/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_FAILED_TO_SEND_COMMENT.png new file mode 100644 index 0000000000..e9efda013b Binary files /dev/null and b/app/screenshots/internal/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_FAILED_TO_SEND_COMMENT.png differ diff --git a/app/screenshots/internal/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_RE_TRYING_TO_POST.png b/app/screenshots/internal/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_RE_TRYING_TO_POST.png new file mode 100644 index 0000000000..1e0d77c180 Binary files /dev/null and b/app/screenshots/internal/debug/com.kickstarter.screenshoot.testing.ui.components.CommentCardShotTest_commentCardScreenshotTest_RE_TRYING_TO_POST.png differ diff --git a/app/src/androidTest/java/com/kickstarter/screenshoot/testing/InstrumentedApp.kt b/app/src/androidTest/java/com/kickstarter/screenshoot/testing/InstrumentedApp.kt new file mode 100644 index 0000000000..7c7c92065b --- /dev/null +++ b/app/src/androidTest/java/com/kickstarter/screenshoot/testing/InstrumentedApp.kt @@ -0,0 +1,23 @@ +package com.kickstarter.screenshoot.testing + +import com.kickstarter.ApplicationComponent +import com.kickstarter.DaggerApplicationComponent +import com.kickstarter.KSApplication +import com.kickstarter.screenshoot.testing.di.AndroidTestApplicationModule + +class InstrumentedApp : KSApplication() { + + override fun onCreate() { + super.onCreate() + } + + override fun getComponent(): ApplicationComponent { + return DaggerApplicationComponent.builder() + .applicationModule(AndroidTestApplicationModule(this)) + .build() + } + + override fun isInUnitTests(): Boolean { + return true + } +} diff --git a/app/src/androidTest/java/com/kickstarter/screenshoot/testing/KSScreenShotTestRunner.kt b/app/src/androidTest/java/com/kickstarter/screenshoot/testing/KSScreenShotTestRunner.kt new file mode 100644 index 0000000000..d7538b375b --- /dev/null +++ b/app/src/androidTest/java/com/kickstarter/screenshoot/testing/KSScreenShotTestRunner.kt @@ -0,0 +1,15 @@ +package com.kickstarter.screenshoot.testing + +import android.app.Application +import android.content.Context +import com.karumi.shot.ShotTestRunner + +class KSScreenShotTestRunner : ShotTestRunner() { + override fun newApplication( + cl: ClassLoader?, + className: String?, + context: Context? + ): Application { + return super.newApplication(cl, InstrumentedApp::class.java.name, context) + } +} diff --git a/app/src/androidTest/java/com/kickstarter/screenshoot/testing/di/AndroidTestApplicationModule.kt b/app/src/androidTest/java/com/kickstarter/screenshoot/testing/di/AndroidTestApplicationModule.kt index 1665e68a0f..1a86450ffc 100644 --- a/app/src/androidTest/java/com/kickstarter/screenshoot/testing/di/AndroidTestApplicationModule.kt +++ b/app/src/androidTest/java/com/kickstarter/screenshoot/testing/di/AndroidTestApplicationModule.kt @@ -1,12 +1,13 @@ -package com.kickstarter +package com.kickstarter.screenshoot.testing.di +import android.app.Application import androidx.annotation.NonNull import com.apollographql.apollo.ApolloClient import com.google.gson.Gson +import com.kickstarter.ApplicationModule import com.kickstarter.libs.ApiEndpoint import com.kickstarter.libs.BuildCheck import com.kickstarter.libs.InternalToolsType -import com.kickstarter.libs.NoopBuildCheck import com.kickstarter.libs.NoopInternalTools import com.kickstarter.mock.services.MockApiClient import com.kickstarter.mock.services.MockApolloClient @@ -18,7 +19,7 @@ import dagger.Provides import javax.inject.Singleton @Module(includes = [ApplicationModule::class]) -class AndroidTestApplicationModule { +class AndroidTestApplicationModule(private val application: Application) : ApplicationModule(application) { @Provides @Singleton diff --git a/app/src/androidTest/java/com/kickstarter/screenshoot/testing/di/ApplicationComponent.kt b/app/src/androidTest/java/com/kickstarter/screenshoot/testing/di/ApplicationComponent.kt index 7e489613a1..8b8f04ffec 100644 --- a/app/src/androidTest/java/com/kickstarter/screenshoot/testing/di/ApplicationComponent.kt +++ b/app/src/androidTest/java/com/kickstarter/screenshoot/testing/di/ApplicationComponent.kt @@ -1,5 +1,6 @@ -package com.kickstarter +package com.kickstarter.screenshoot.testing.di +import com.kickstarter.ApplicationGraph import dagger.Component import javax.inject.Singleton diff --git a/app/src/androidTest/java/com/kickstarter/screenshoot/testing/di/NoopBuildCheck.kt b/app/src/androidTest/java/com/kickstarter/screenshoot/testing/di/NoopBuildCheck.kt index 1e3286658b..e2f1afd7d1 100644 --- a/app/src/androidTest/java/com/kickstarter/screenshoot/testing/di/NoopBuildCheck.kt +++ b/app/src/androidTest/java/com/kickstarter/screenshoot/testing/di/NoopBuildCheck.kt @@ -1,6 +1,7 @@ -package com.kickstarter.libs +package com.kickstarter.screenshoot.testing.di import androidx.annotation.NonNull +import com.kickstarter.libs.BuildCheck import com.kickstarter.services.WebClientType import com.kickstarter.viewmodels.DiscoveryViewModel diff --git a/app/src/androidTest/java/com/kickstarter/screenshoot/testing/ui/components/CommentCardShotTest.kt b/app/src/androidTest/java/com/kickstarter/screenshoot/testing/ui/components/CommentCardShotTest.kt index 26a882c2c1..fe0bd1363e 100644 --- a/app/src/androidTest/java/com/kickstarter/screenshoot/testing/ui/components/CommentCardShotTest.kt +++ b/app/src/androidTest/java/com/kickstarter/screenshoot/testing/ui/components/CommentCardShotTest.kt @@ -2,33 +2,73 @@ package com.kickstarter.screenshoot.testing.ui.components import android.view.LayoutInflater import androidx.constraintlayout.widget.ConstraintLayout -import androidx.test.core.app.ApplicationProvider +import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation import com.karumi.shot.ScreenshotTest -import com.kickstarter.KSApplication +import com.kickstarter.ApplicationComponent import com.kickstarter.R +import com.kickstarter.libs.utils.DateTimeUtils import com.kickstarter.mock.factories.UserFactory +import com.kickstarter.screenshoot.testing.InstrumentedApp import com.kickstarter.ui.views.CommentCard import com.kickstarter.ui.views.CommentCardStatus import org.joda.time.DateTime +import org.junit.Before import org.junit.Test class CommentCardShotTest : ScreenshotTest { - private val context = ApplicationProvider.getApplicationContext() - @Test - fun commentCardScreenshotTest_COMMENT_FOR_LOGIN_BACKED_USERS() { - var commentCard: CommentCard = (LayoutInflater.from(context).inflate(R.layout.item_comment_card, null) as ConstraintLayout) + lateinit var commentCard: CommentCard + lateinit var component: ApplicationComponent + + @Before + fun setup() { + // - Test Application + val app = getInstrumentation().targetContext.applicationContext as InstrumentedApp + // - Test Dagger component for injecting on environment Mock Objects + component = app.component() + + commentCard = (LayoutInflater.from(getInstrumentation().targetContext).inflate(R.layout.item_comment_card, null) as ConstraintLayout) .findViewById(R.id.comments_card_view) val user = UserFactory.user() - commentCard.setAvatarUrl(null) // -> internal network call to picasso we need to extract that. - commentCard.setReplyButtonVisibility(true) - commentCard.setViewRepliesVisibility(true) + commentCard.setAvatarUrl(null) // -> internal network call to picasso we need to wrap Picasso into our own client to be able to mock on testing. commentCard.setCommentUserName(user.name()) - commentCard.setCommentBody("Message here for the Screenshot test lets see how it behaves ....") - commentCard.setCommentPostTime(DateTime.now().toString()) + commentCard.setCommentBody("Message here for the Screenshot test lets see how it behaves ...") + + val relativeTime = DateTime.now().minusMinutes(5) + val commentPostedRelativeTime = DateTimeUtils.relative(getInstrumentation().targetContext, component.environment().ksString(), relativeTime) + commentCard.setCommentPostTime(commentPostedRelativeTime) + } + @Test + fun commentCardScreenshotTest_COMMENT_FOR_LOGIN_BACKED_USERS() { commentCard.setCommentCardStatus(CommentCardStatus.COMMENT_FOR_LOGIN_BACKED_USERS) compareScreenshot(commentCard) } + + @Test + fun commentCardScreenshotTest_COMMENT_WITH_REPLIES() { + commentCard.setCommentEnabledThreads(true) + commentCard.setCommentReplies(3) + commentCard.setCommentCardStatus(CommentCardStatus.COMMENT_WITH_REPLIES) + compareScreenshot(commentCard) + } + + @Test + fun commentCardScreenshotTest_FAILED_TO_SEND_COMMENT() { + commentCard.setCommentCardStatus(CommentCardStatus.FAILED_TO_SEND_COMMENT) + compareScreenshot(commentCard) + } + + @Test + fun commentCardScreenshotTest_DELETED_COMMENT() { + commentCard.setCommentCardStatus(CommentCardStatus.DELETED_COMMENT) + compareScreenshot(commentCard) + } + + @Test + fun commentCardScreenshotTest_RE_TRYING_TO_POST() { + commentCard.setCommentCardStatus(CommentCardStatus.RE_TRYING_TO_POST) + compareScreenshot(commentCard) + } } diff --git a/app/src/internal/AndroidManifest.xml b/app/src/internal/AndroidManifest.xml index 6ae36377a5..f2e4de446b 100644 --- a/app/src/internal/AndroidManifest.xml +++ b/app/src/internal/AndroidManifest.xml @@ -1,6 +1,6 @@ + xmlns:android="http://schemas.android.com/apk/res/android"> diff --git a/app/src/internalDebug/AndroidManifest.xml b/app/src/internalDebug/AndroidManifest.xml index 44b9249efc..6a49894f47 100644 --- a/app/src/internalDebug/AndroidManifest.xml +++ b/app/src/internalDebug/AndroidManifest.xml @@ -1,13 +1,6 @@ + package="com.kickstarter"> - - - - \ No newline at end of file diff --git a/app/src/main/java/com/kickstarter/IKSApplicationComponent.java b/app/src/main/java/com/kickstarter/IKSApplicationComponent.java new file mode 100644 index 0000000000..9c1c65c4cd --- /dev/null +++ b/app/src/main/java/com/kickstarter/IKSApplicationComponent.java @@ -0,0 +1,5 @@ +package com.kickstarter; + +public interface IKSApplicationComponent { + ApplicationGraph getComponent(); +} diff --git a/app/src/main/java/com/kickstarter/KSApplication.java b/app/src/main/java/com/kickstarter/KSApplication.java index 1fe2d5e029..632525a65b 100644 --- a/app/src/main/java/com/kickstarter/KSApplication.java +++ b/app/src/main/java/com/kickstarter/KSApplication.java @@ -28,7 +28,7 @@ import androidx.multidex.MultiDexApplication; import timber.log.Timber; -public class KSApplication extends MultiDexApplication { +public class KSApplication extends MultiDexApplication implements IKSApplicationComponent { private ApplicationComponent component; @Inject protected CookieManager cookieManager; @Inject protected PushNotifications pushNotifications; @@ -40,11 +40,21 @@ public class KSApplication extends MultiDexApplication { public void onCreate() { super.onCreate(); + this.component = getComponent(); + component().inject(this); + if (!isInUnitTests()) { initApplication(); } } + public ApplicationComponent getComponent() { + final ApplicationComponent component = DaggerApplicationComponent.builder() + .applicationModule(new ApplicationModule(this)) + .build(); + return component; + } + private void initApplication() { MultiDex.install(this); @@ -53,11 +63,6 @@ private void initApplication() { Timber.plant(new Timber.DebugTree()); } - this.component = DaggerApplicationComponent.builder() - .applicationModule(new ApplicationModule(this)) - .build(); - component().inject(this); - if (FirebaseApp.getApps(getApplicationContext()).isEmpty()) { FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true); FirebaseApp.initializeApp(getApplicationContext()); diff --git a/app/src/test/java/com/kickstarter/TestKSApplication.java b/app/src/test/java/com/kickstarter/TestKSApplication.java index a9ebe6846e..31e06d59f9 100644 --- a/app/src/test/java/com/kickstarter/TestKSApplication.java +++ b/app/src/test/java/com/kickstarter/TestKSApplication.java @@ -4,6 +4,15 @@ public class TestKSApplication extends KSApplication { + @Override + public ApplicationComponent getComponent() { + final ApplicationComponent component = DaggerApplicationComponent.builder() + .applicationModule(new TestApplicationModule(this)) + .build(); + + return component; + } + @Override public void onCreate() { // - LoginToutViewModelTest needs the FacebookSDK initialized @@ -16,3 +25,4 @@ public boolean isInUnitTests() { return true; } } +