Skip to content

Commit

Permalink
Sync sample repo from screenshot-tests-for-android
Browse files Browse the repository at this point in the history
  • Loading branch information
tdrhq committed Sep 19, 2022
1 parent abcee78 commit 2b6e28a
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 69 deletions.
21 changes: 8 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,23 +19,20 @@ buildscript {
repositories {
mavenLocal()
jcenter()
mavenCentral()
google()
}

dependencies {
classpath plugs.agp
classpath plugs.screenshot
classpath plugs.kotlin
classpath "io.screenshotbot:plugin:0.1.6"
}
}

allprojects {
repositories {
mavenLocal()
jcenter()
mavenCentral()
google()
}
}
Expand All @@ -45,8 +42,6 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.facebook.testing.screenshot'
apply plugin: 'io.screenshotbot.plugin'


android {
compileSdkVersion versions.compileSdk
Expand All @@ -57,7 +52,10 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.facebook.testing.screenshot.sample.ScreenshotTestRunner"
ndkVersion "20.1.5948944"
testInstrumentationRunnerArguments clearPackageData: 'true'
}
testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
}

Expand All @@ -73,11 +71,12 @@ dependencies {
kapt deps.lithoProcessor

implementation deps.soLoader
implementation "androidx.constraintlayout:constraintlayout:2.0.4"

androidTestImplementation deps.screenshotTestCommon
androidTestImplementation deps.screenshotTestLitho
androidTestImplementation deps.junit
androidTestImplementation deps.testRunner
androidTestUtil deps.orchestrator
androidTestImplementation(deps.espresso) {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.code.findbugs', module: 'jsr305'
Expand All @@ -87,9 +86,5 @@ dependencies {

screenshots {
multipleDevices true
}

screenshotbot {
channelName "screenshotbot-example"
githubRepo "https://github.com/tdrhq/screenshotbot-example"
pythonExecutable 'python3'
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,22 +18,30 @@

import android.content.Context;
import android.view.LayoutInflater;
import androidx.test.annotation.UiThreadTest;
import androidx.test.platform.app.InstrumentationRegistry;
import com.facebook.litho.LithoView;
import com.facebook.testing.screenshot.Screenshot;
import com.facebook.testing.screenshot.ViewHelpers;
import org.junit.Before;
import org.junit.Test;

public class ExampleScreenshotTest {
@Before
public void before() {
InstrumentationRegistry.getInstrumentation().getUiAutomation();
}

@Test
@UiThreadTest
public void testDefault() {
Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
LayoutInflater inflater = LayoutInflater.from(targetContext);
LithoView view = (LithoView) inflater.inflate(R.layout.litho_view, null, false);

view.setComponent(Example.create(view.getComponentContext()).build());

ViewHelpers.setupView(view).setExactWidthDp(303).layout();
ViewHelpers.setupView(view).setExactWidthDp(300).setExactHeightDp(300).layout();
Screenshot.snap(view).record();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,15 +18,23 @@

import android.content.Context;
import android.view.LayoutInflater;
import androidx.test.annotation.UiThreadTest;
import androidx.test.platform.app.InstrumentationRegistry;
import com.facebook.litho.LithoView;
import com.facebook.testing.screenshot.Screenshot;
import com.facebook.testing.screenshot.ViewHelpers;
import org.junit.Before;
import org.junit.Test;

public class ImageRowScreenshotTest {
@Before
public void before() {
InstrumentationRegistry.getInstrumentation().getUiAutomation();
}

@Test
public void testDefault2() {
@UiThreadTest
public void testDefault() {
Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
LayoutInflater inflater = LayoutInflater.from(targetContext);
LithoView view = (LithoView) inflater.inflate(R.layout.litho_view, null, false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,23 +16,29 @@

package com.facebook.testing.screenshot.sample


import android.view.View
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.ActivityTestRule
import com.facebook.testing.screenshot.Screenshot
import org.hamcrest.core.AllOf.allOf
import org.junit.Before
import org.junit.Rule
import org.junit.Test

class MainActivityTest {
@get:Rule
var activityTestRule = ActivityTestRule<MainActivity>(MainActivity::class.java, false, false)

@Before
fun before() {
InstrumentationRegistry.getInstrumentation().getUiAutomation()
}

@Test
fun testScreenshotEntireActivity() {
val activity = activityTestRule.launchActivity(null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,4 +43,3 @@ class ScreenshotTestRunner : AndroidJUnitRunner() {
super.finish(resultCode, results)
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,6 @@

package com.facebook.testing.screenshot.sample


import android.view.View
import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -69,4 +69,3 @@ class StandardAndroidViewTest {
Screenshot.snap(view).record()
}
}

12 changes: 0 additions & 12 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<activity
android:name=".SpinnerActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

</application>

</manifest>
4 changes: 2 additions & 2 deletions src/main/java/com/facebook/testing/screenshot/sample/App.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,4 +24,4 @@ class App : Application() {
super.onCreate()
SoLoader.init(this, false)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,9 +31,7 @@ object ExampleSpec {
fun onCreateLayout(c: ComponentContext): Component =
Column.create(c)
.child(ImageRow.create(c))
.child(
Text.create(c)
.textRes(R.string.large_text))
.child(Text.create(c).textRes(R.string.large_text))
.paddingDip(YogaEdge.ALL, 16f)
.border(
Border.create(c)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,24 +19,19 @@ package com.facebook.testing.screenshot.sample
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.widget.TextView
import androidx.annotation.ColorRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.snackbar.Snackbar
import androidx.core.content.ContextCompat
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import android.view.Menu
import android.view.View
import android.widget.TextView
import com.facebook.litho.LithoView

class MainActivity : AppCompatActivity() {
companion object {
private const val STATUS = "status"

fun intent(status: Status) = Intent().apply {
putExtra(STATUS, status.name)
}
fun intent(status: Status) = Intent().apply { putExtra(STATUS, status.name) }
}

enum class Status {
Expand All @@ -53,18 +48,21 @@ class MainActivity : AppCompatActivity() {
val textView = findViewById<TextView>(R.id.text_view)
val status = Status.valueOf(intent.string(STATUS, Status.OK.name))
when (status) {
Status.OK -> textView.run {
setTextColor(context.color(R.color.ok))
text = "Status is OK"
}
Status.WARNING -> textView.run {
setTextColor(context.color(R.color.warning))
text = "Status is WARNING"
}
Status.ERROR -> textView.run {
setTextColor(context.color(R.color.error))
text = "Status is ERROR"
}
Status.OK ->
textView.run {
setTextColor(context.color(R.color.ok))
text = "Status is OK"
}
Status.WARNING ->
textView.run {
setTextColor(context.color(R.color.warning))
text = "Status is WARNING"
}
Status.ERROR ->
textView.run {
setTextColor(context.color(R.color.error))
text = "Status is ERROR"
}
}

findViewById<FloatingActionButton>(R.id.fab).setOnClickListener { view ->
Expand Down
4 changes: 2 additions & 2 deletions src/main/res/layout/search_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
android:layout_weight="1"
android:singleLine="true"
android:textColor="@android:color/black"
android:hint="Search the world!" />
android:hint="Search the world" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search!!!!" />
android:text="Search!" />
</LinearLayout>

0 comments on commit 2b6e28a

Please sign in to comment.