Skip to content

Commit

Permalink
ISSUE-88: Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJette committed Mar 25, 2024
1 parent 3e1a8d0 commit ec7f4ce
Show file tree
Hide file tree
Showing 68 changed files with 1,518 additions and 333 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

### Legacy Sample

#### Added

- Added tests demonstrating the usage of ScreenshotScenarioRule.

### Flix Sample
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 ndtp
* Copyright (c) 2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 ndtp
* Copyright (c) 2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2022 ndtp
* Copyright (c) 2022-2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions Library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ android {
multiDexEnabled = true
kotlinOptions {
allWarningsAsErrors = true
freeCompilerArgs = [ "-Xcontext-receivers" ]
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Modified work copyright (c) 2022 ndtp
* Modified work copyright (c) 2022-2024 ndtp
* Original work copyright (c) 2021 Shopify Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 ndtp
* Copyright (c) 2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 ndtp
* Copyright (c) 2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 ndtp
* Copyright (c) 2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 ndtp
* Copyright (c) 2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2022 ndtp
* Copyright (c) 2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -70,8 +70,8 @@ class ScreenshotScenarioLifecycleTest {
}

assertEquals(6, observer.log.size)
assertEquals("applyConfiguration", observer.log[0])
assertEquals("beforeAssertSame", observer.log[1])
assertEquals("beforeAssertSame", observer.log[0])
assertEquals("applyConfiguration", observer.log[1])
assertEquals("beforeInitializeView", observer.log[2])
assertEquals("afterInitializeView", observer.log[3])
assertEquals("beforeScreenshot", observer.log[4])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 ndtp
* Copyright (c) 2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 1 addition & 2 deletions Library/src/main/java/dev/testify/ScreenshotRule.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Modified work copyright (c) 2022 ndtp
* Modified work copyright (c) 2022-2024 ndtp
* Original work copyright (c) 2019 Shopify Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -398,7 +398,6 @@ open class ScreenshotRule<T : Activity> @JvmOverloads constructor(
/**
* The [Statement] to be executed by the [ScreenshotStatement].
*/
@VisibleForTesting
internal var statement: Statement? = null

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2022 ndtp
* Copyright (c) 2022-2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 ndtp
* Copyright (c) 2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Modified work copyright (c) 2022 ndtp
* Modified work copyright (c) 2022-2024 ndtp
* Original work copyright (c) 2020 Shopify Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 ndtp
* Copyright (c) 2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 ndtp
* Copyright (c) 2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions Library/src/main/java/dev/testify/core/logic/AssertSame.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 ndtp
* Copyright (c) 2023-2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -173,15 +173,15 @@ internal fun <TActivity : Activity> assertSame(

if (TestifyFeatures.GenerateDiffs.isEnabled(activity)) {
HighContrastDiff
.create(configuration.exclusionRects) // TODO: Test me
.create(configuration.exclusionRects)
.name(outputFileName)
.baseline(baselineBitmap)
.current(currentBitmap)
.exactness(configuration.exactness)
.generate(context = activity)
}
if (isRecordMode) {
TestInstrumentationRegistry.instrumentationPrintln( // TODO: Test me
TestInstrumentationRegistry.instrumentationPrintln(
"\n\t" + "Recording baseline for ${description.name}".cyan()
)
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2022 ndtp
* Copyright (c) 2022-2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Modified work copyright (c) 2022 ndtp
* Modified work copyright (c) 2022-2024 ndtp
* Original work copyright (c) 2020 Shopify Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 ndtp
* Copyright (c) 2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -56,7 +56,6 @@ import dev.testify.core.exception.ScreenshotIsDifferentException
import dev.testify.core.logic.AssertionState
import dev.testify.core.logic.ScreenshotLifecycleHost
import dev.testify.core.logic.ScreenshotLifecycleObserver
import dev.testify.internal.extensions.TestInstrumentationRegistry.instrumentationPrintln
import dev.testify.internal.extensions.isInvokedFromPlugin
import dev.testify.internal.helpers.ActivityProvider
import dev.testify.internal.helpers.closeSoftKeyboard
Expand All @@ -68,6 +67,9 @@ import org.junit.rules.TestRule
import org.junit.rules.TestWatcher
import org.junit.runner.Description
import org.junit.runners.model.Statement
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/**
* ScreenshotScenarioRule is one of the main entry point for Testify.
Expand Down Expand Up @@ -189,7 +191,7 @@ open class ScreenshotScenarioRule @JvmOverloads constructor(
* @ScreenshotInstrumentation
* @Test
* fun default() {
* launchActivity<TestLocaleHarnessActivity>().use { scenario ->
* launchActivity<TestHarnessActivity>().use { scenario ->
* rule
* .withScenario(scenario)
* .assertSame()
Expand Down Expand Up @@ -217,7 +219,7 @@ open class ScreenshotScenarioRule @JvmOverloads constructor(
* @ScreenshotInstrumentation
* @Test
* fun default() {
* launchActivity<TestLocaleHarnessActivity>().use { scenario ->
* launchActivity<TestHarnessActivity>().use { scenario ->
* rule
* .withScenario(scenario)
* .setViewModifications { harnessRoot ->
Expand Down Expand Up @@ -247,7 +249,7 @@ open class ScreenshotScenarioRule @JvmOverloads constructor(
* @ScreenshotInstrumentation
* @Test
* fun setScreenshotViewProvider() {
* launchActivity<TestLocaleHarnessActivity>().use { scenario ->
* launchActivity<TestHarnessActivity>().use { scenario ->
* rule
* .withScenario(scenario)
* .setScreenshotViewProvider {
Expand All @@ -273,7 +275,7 @@ open class ScreenshotScenarioRule @JvmOverloads constructor(
* @ScreenshotInstrumentation
* @Test
* fun testConfigure() {
* launchActivity<TestLocaleHarnessActivity>().use { scenario ->
* launchActivity<TestHarnessActivity>().use { scenario ->
* rule
* .withScenario(scenario)
* .configure {
Expand Down Expand Up @@ -344,7 +346,6 @@ open class ScreenshotScenarioRule @JvmOverloads constructor(
testClass: Class<*>,
methodAnnotations: Collection<Annotation>?
) {
instrumentationPrintln("apply")
val classAnnotations = testClass.annotations.asList()
assertForScreenshotInstrumentationAnnotation(
methodName,
Expand Down Expand Up @@ -454,7 +455,6 @@ open class ScreenshotScenarioRule @JvmOverloads constructor(
*/
@CallSuper
override fun beforeAssertSame() {
instrumentationPrintln("beforeAssertSame")
getInstrumentation().registerActivityProvider(this)

// Called after configuration has been set
Expand All @@ -477,7 +477,7 @@ open class ScreenshotScenarioRule @JvmOverloads constructor(
* @ScreenshotInstrumentation
* @Test
* fun default() {
* launchActivity<TestLocaleHarnessActivity>().use { scenario ->
* launchActivity<TestHarnessActivity>().use { scenario ->
* rule
* .configure {
* exactness = 0.95f
Expand All @@ -494,6 +494,20 @@ open class ScreenshotScenarioRule @JvmOverloads constructor(
throw ScenarioRequiredException()
}

scenario?.let {
assertSame(it)
} ?: throw ScenarioRequiredException()
}

context (ActivityScenario<*>)
@JvmName("assertSameContext")
fun assertSame() {
assertSame(this@ActivityScenario)
}

private fun assertSame(scenario: ActivityScenario<*>) {
this.scenario = scenario

addScreenshotObserver(this)

try {
Expand Down Expand Up @@ -533,9 +547,6 @@ open class ScreenshotScenarioRule @JvmOverloads constructor(
* Called by the [ScreenshotStatement] before each test method is executed.
*/
protected fun evaluateBeforeEach() {

instrumentationPrintln("evaluateBeforeEach")

getInstrumentation()?.run {
reporter?.identifySession(this)
}
Expand All @@ -555,8 +566,6 @@ open class ScreenshotScenarioRule @JvmOverloads constructor(
* Called by the [ScreenshotStatement] after each test method is executed.
*/
protected fun evaluateAfterEach() {
instrumentationPrintln("evaluateAfterEach")

/**
* Only throw the MissingAssertSameException if the test is a screenshot test.
* This allows the user to run the test as a normal JUnit test without having to call assertSame.
Expand Down Expand Up @@ -610,3 +619,11 @@ open class ScreenshotScenarioRule @JvmOverloads constructor(
notifyObservers { it.applyConfiguration(getActivity(), configuration) }
}
}

@OptIn(ExperimentalContracts::class)
inline fun <T : ActivityScenario<A>, A : Activity> T.test(block: T.(T) -> Unit) {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
this.block(this)
}
2 changes: 1 addition & 1 deletion Library/src/test/java/dev/testify/ScreenshotRuleTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 ndtp
* Copyright (c) 2023-2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Modified work copyright (c) 2022 ndtp
* Modified work copyright (c) 2022-2024 ndtp
* Original work copyright (c) 2021 Shopify Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 ndtp
* Copyright (c) 2023-2024 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit ec7f4ce

Please sign in to comment.