Skip to content

Commit

Permalink
NT-2125: CommentCard Screen shot test. (#1331)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkariang committed Jul 21, 2021
1 parent 88053fb commit 8659365
Show file tree
Hide file tree
Showing 22 changed files with 131 additions and 33 deletions.
8 changes: 6 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()}\""
Expand Down Expand Up @@ -194,6 +195,9 @@ android {
}

packagingOptions {
jniLibs {
useLegacyPackaging = true
}
exclude 'META-INF/LICENSE.txt'
exclude 'LICENSE.txt'
exclude 'META-INF/AL2.0'
Expand Down Expand Up @@ -373,5 +377,5 @@ apply plugin: 'com.google.gms.google-services'

apply plugin: 'shot'
shot {
runInstrumentation = false
useComposer = false
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kickstarter
package com.kickstarter.screenshoot.testing.di

import com.kickstarter.ApplicationGraph
import dagger.Component
import javax.inject.Singleton

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<KSApplication>()

@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)
}
}
2 changes: 1 addition & 1 deletion app/src/internal/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.kickstarter"
xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<activity android:name=".ui.activities.InternalToolsActivity" />
Expand Down
9 changes: 1 addition & 8 deletions app/src/internalDebug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.kickstarter"
android:sharedUserId="com.kickstarter">
package="com.kickstarter">

<!-- Strip away maxSdkVersion -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:remove="android:maxSdkVersion"/>

<!-- Add the permission with no maxSdkVersion defined -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.kickstarter;

public interface IKSApplicationComponent {
ApplicationGraph getComponent();
}
17 changes: 11 additions & 6 deletions app/src/main/java/com/kickstarter/KSApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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());
Expand Down
10 changes: 10 additions & 0 deletions app/src/test/java/com/kickstarter/TestKSApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,3 +25,4 @@ public boolean isInUnitTests() {
return true;
}
}

0 comments on commit 8659365

Please sign in to comment.