From 301b84a057314bae737f61ea9b2e838f7e3acc3e Mon Sep 17 00:00:00 2001 From: Ryan Brooks Date: Fri, 29 Sep 2023 09:55:53 -0700 Subject: [PATCH] Add stacked multipreview test --- .../processor/PreviewProcessorTest.kt | 15 ++++--- .../input/FontScaleVariants.kt | 20 ++++++++++ .../input/PreviewVariants.kt | 5 +++ .../input/StackedMultiPreviewComposable.kt | 8 ++++ .../input/UIModeVariants.kt | 16 ++++++++ ...eviewComposable_-2110175474_GenSnapshot.kt | 39 +++++++++++++++++++ ...reviewComposable_-262425918_GenSnapshot.kt | 39 +++++++++++++++++++ ...reviewComposable_-441987374_GenSnapshot.kt | 39 +++++++++++++++++++ ...PreviewComposable_441959458_GenSnapshot.kt | 39 +++++++++++++++++++ ...ackedMultiPreviewComposable_GenSnapshot.kt | 38 ++++++++++++++++++ 10 files changed, 253 insertions(+), 5 deletions(-) create mode 100644 snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/FontScaleVariants.kt create mode 100644 snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/PreviewVariants.kt create mode 100644 snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/StackedMultiPreviewComposable.kt create mode 100644 snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/UIModeVariants.kt create mode 100644 snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_-2110175474_GenSnapshot.kt create mode 100644 snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_-262425918_GenSnapshot.kt create mode 100644 snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_-441987374_GenSnapshot.kt create mode 100644 snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_441959458_GenSnapshot.kt create mode 100644 snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_GenSnapshot.kt diff --git a/snapshots/snapshots-processor-test/src/test/kotlin/com/emergetools/snapshots/processor/PreviewProcessorTest.kt b/snapshots/snapshots-processor-test/src/test/kotlin/com/emergetools/snapshots/processor/PreviewProcessorTest.kt index a1e1c8e9..ed80eeb7 100644 --- a/snapshots/snapshots-processor-test/src/test/kotlin/com/emergetools/snapshots/processor/PreviewProcessorTest.kt +++ b/snapshots/snapshots-processor-test/src/test/kotlin/com/emergetools/snapshots/processor/PreviewProcessorTest.kt @@ -15,6 +15,11 @@ import java.io.File class PreviewProcessorTest { + companion object { + // Set to true to overwrite the test outputs with those generated from tests above. + const val UPDATE_TEST_OUTPUTS = false + } + @Rule @JvmField val testNameRule = TestNameRule() @@ -54,6 +59,11 @@ class PreviewProcessorTest { compileInputsAndVerifyOutputs() } + @Test + fun `stacked multipreview five total previews produces five snapshots`() { + compileInputsAndVerifyOutputs() + } + private fun compileInputs( options: MutableMap = mutableMapOf(), onCompilation: (compilation: KotlinCompilation, result: KotlinCompilation.Result) -> Unit, @@ -142,9 +152,4 @@ class PreviewProcessorTest { val className = testNameRule.className.substringAfterLast(".") return File(rootResourcesDir, "$className/$methodName") } - - companion object { - // Set to true to overwrite the test outputs with those generated from tests above. - const val UPDATE_TEST_OUTPUTS = false - } } diff --git a/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/FontScaleVariants.kt b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/FontScaleVariants.kt new file mode 100644 index 00000000..f069e150 --- /dev/null +++ b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/FontScaleVariants.kt @@ -0,0 +1,20 @@ +package PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input + +import androidx.compose.ui.tooling.preview.Preview + +@Preview( + name = "Normal font", + group = "Font scale", + fontScale = 1f, +) +@Preview( + name = "Large font", + group = "Font scale", + fontScale = 1.5f, +) +@Preview( + name = "Small font", + group = "Font scale", + fontScale = .5f, +) +annotation class FontScaleVariants diff --git a/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/PreviewVariants.kt b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/PreviewVariants.kt new file mode 100644 index 00000000..11bbc07e --- /dev/null +++ b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/PreviewVariants.kt @@ -0,0 +1,5 @@ +package PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input + +@FontScaleVariants +@UIModeVariants +annotation class PreviewVariants diff --git a/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/StackedMultiPreviewComposable.kt b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/StackedMultiPreviewComposable.kt new file mode 100644 index 00000000..e8c28957 --- /dev/null +++ b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/StackedMultiPreviewComposable.kt @@ -0,0 +1,8 @@ +package PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input + +import androidx.compose.runtime.Composable + +@PreviewVariants +@Composable +fun StackedMultiPreviewComposable() { +} diff --git a/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/UIModeVariants.kt b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/UIModeVariants.kt new file mode 100644 index 00000000..fed50cf6 --- /dev/null +++ b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/input/UIModeVariants.kt @@ -0,0 +1,16 @@ +package PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input + +import android.content.res.Configuration +import androidx.compose.ui.tooling.preview.Preview + +@Preview( + name = "Light", + group = "UIMode", + uiMode = Configuration.UI_MODE_NIGHT_NO, +) +@Preview( + name = "Dark", + group = "UIMode", + uiMode = Configuration.UI_MODE_NIGHT_YES, +) +annotation class UIModeVariants diff --git a/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_-2110175474_GenSnapshot.kt b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_-2110175474_GenSnapshot.kt new file mode 100644 index 00000000..13b7bebd --- /dev/null +++ b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_-2110175474_GenSnapshot.kt @@ -0,0 +1,39 @@ +package PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input + +import PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input.StackedMultiPreviewComposable +import androidx.compose.runtime.Composable +import androidx.compose.ui.test.junit4.ComposeContentTestRule +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.emergetools.snapshots.EmergeSnapshots +import com.emergetools.snapshots.compose.SnapshotVariantProvider +import com.emergetools.snapshots.shared.ComposePreviewSnapshotConfig +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +public class `StackedMultiPreviewComposable_-2110175474_GenSnapshot` { + @get:Rule + public val composeRule: ComposeContentTestRule = createComposeRule() + + public val previewConfig: ComposePreviewSnapshotConfig = ComposePreviewSnapshotConfig(originalFqn + = + "PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input.StackedMultiPreviewComposable", + name = "Large font", + group = "Font scale", + fontScale = 1.5f) + + @get:Rule + public val snapshotRule: EmergeSnapshots = EmergeSnapshots() + + @Test + public fun StackedMultiPreviewComposable_GenSnapshot() { + composeRule.setContent { + SnapshotVariantProvider(previewConfig) { + StackedMultiPreviewComposable() + } + } + snapshotRule.take(composeRule, previewConfig) + } +} diff --git a/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_-262425918_GenSnapshot.kt b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_-262425918_GenSnapshot.kt new file mode 100644 index 00000000..1ceb8503 --- /dev/null +++ b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_-262425918_GenSnapshot.kt @@ -0,0 +1,39 @@ +package PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input + +import PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input.StackedMultiPreviewComposable +import androidx.compose.runtime.Composable +import androidx.compose.ui.test.junit4.ComposeContentTestRule +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.emergetools.snapshots.EmergeSnapshots +import com.emergetools.snapshots.compose.SnapshotVariantProvider +import com.emergetools.snapshots.shared.ComposePreviewSnapshotConfig +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +public class `StackedMultiPreviewComposable_-262425918_GenSnapshot` { + @get:Rule + public val composeRule: ComposeContentTestRule = createComposeRule() + + public val previewConfig: ComposePreviewSnapshotConfig = ComposePreviewSnapshotConfig(originalFqn + = + "PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input.StackedMultiPreviewComposable", + name = "Small font", + group = "Font scale", + fontScale = 0.5f) + + @get:Rule + public val snapshotRule: EmergeSnapshots = EmergeSnapshots() + + @Test + public fun StackedMultiPreviewComposable_GenSnapshot() { + composeRule.setContent { + SnapshotVariantProvider(previewConfig) { + StackedMultiPreviewComposable() + } + } + snapshotRule.take(composeRule, previewConfig) + } +} diff --git a/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_-441987374_GenSnapshot.kt b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_-441987374_GenSnapshot.kt new file mode 100644 index 00000000..2f60db34 --- /dev/null +++ b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_-441987374_GenSnapshot.kt @@ -0,0 +1,39 @@ +package PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input + +import PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input.StackedMultiPreviewComposable +import androidx.compose.runtime.Composable +import androidx.compose.ui.test.junit4.ComposeContentTestRule +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.emergetools.snapshots.EmergeSnapshots +import com.emergetools.snapshots.compose.SnapshotVariantProvider +import com.emergetools.snapshots.shared.ComposePreviewSnapshotConfig +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +public class `StackedMultiPreviewComposable_-441987374_GenSnapshot` { + @get:Rule + public val composeRule: ComposeContentTestRule = createComposeRule() + + public val previewConfig: ComposePreviewSnapshotConfig = ComposePreviewSnapshotConfig(originalFqn + = + "PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input.StackedMultiPreviewComposable", + name = "Dark", + group = "UIMode", + uiMode = 32) + + @get:Rule + public val snapshotRule: EmergeSnapshots = EmergeSnapshots() + + @Test + public fun StackedMultiPreviewComposable_GenSnapshot() { + composeRule.setContent { + SnapshotVariantProvider(previewConfig) { + StackedMultiPreviewComposable() + } + } + snapshotRule.take(composeRule, previewConfig) + } +} diff --git a/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_441959458_GenSnapshot.kt b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_441959458_GenSnapshot.kt new file mode 100644 index 00000000..a647b983 --- /dev/null +++ b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_441959458_GenSnapshot.kt @@ -0,0 +1,39 @@ +package PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input + +import PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input.StackedMultiPreviewComposable +import androidx.compose.runtime.Composable +import androidx.compose.ui.test.junit4.ComposeContentTestRule +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.emergetools.snapshots.EmergeSnapshots +import com.emergetools.snapshots.compose.SnapshotVariantProvider +import com.emergetools.snapshots.shared.ComposePreviewSnapshotConfig +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +public class StackedMultiPreviewComposable_441959458_GenSnapshot { + @get:Rule + public val composeRule: ComposeContentTestRule = createComposeRule() + + public val previewConfig: ComposePreviewSnapshotConfig = ComposePreviewSnapshotConfig(originalFqn + = + "PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input.StackedMultiPreviewComposable", + name = "Light", + group = "UIMode", + uiMode = 16) + + @get:Rule + public val snapshotRule: EmergeSnapshots = EmergeSnapshots() + + @Test + public fun StackedMultiPreviewComposable_GenSnapshot() { + composeRule.setContent { + SnapshotVariantProvider(previewConfig) { + StackedMultiPreviewComposable() + } + } + snapshotRule.take(composeRule, previewConfig) + } +} diff --git a/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_GenSnapshot.kt b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_GenSnapshot.kt new file mode 100644 index 00000000..ffbc4f5c --- /dev/null +++ b/snapshots/snapshots-processor-test/src/test/resources/PreviewProcessorTest/stacked_multipreview_five_total_previews_produces_five_snapshots/output/StackedMultiPreviewComposable_GenSnapshot.kt @@ -0,0 +1,38 @@ +package PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input + +import PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input.StackedMultiPreviewComposable +import androidx.compose.runtime.Composable +import androidx.compose.ui.test.junit4.ComposeContentTestRule +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.emergetools.snapshots.EmergeSnapshots +import com.emergetools.snapshots.compose.SnapshotVariantProvider +import com.emergetools.snapshots.shared.ComposePreviewSnapshotConfig +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +public class StackedMultiPreviewComposable_GenSnapshot { + @get:Rule + public val composeRule: ComposeContentTestRule = createComposeRule() + + public val previewConfig: ComposePreviewSnapshotConfig = ComposePreviewSnapshotConfig(originalFqn + = + "PreviewProcessorTest.stacked_multipreview_five_total_previews_produces_five_snapshots.input.StackedMultiPreviewComposable", + name = "Normal font", + group = "Font scale") + + @get:Rule + public val snapshotRule: EmergeSnapshots = EmergeSnapshots() + + @Test + public fun StackedMultiPreviewComposable_GenSnapshot() { + composeRule.setContent { + SnapshotVariantProvider(previewConfig) { + StackedMultiPreviewComposable() + } + } + snapshotRule.take(composeRule, previewConfig) + } +}