Skip to content

Commit

Permalink
Add UI test
Browse files Browse the repository at this point in the history
  • Loading branch information
oas004 committed Sep 28, 2022
1 parent aa46317 commit aad61a6
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import com.airbnb.android.showkase.annotation.ShowkaseComposable
import com.airbnb.android.submodule.showkasesample.CustomPreviewAnnotation

@Composable
fun CustomButton(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.airbnb.android.showkase_browser_testing

import androidx.compose.ui.test.*
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performGesture
import androidx.compose.ui.test.swipeDown
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.platform.app.InstrumentationRegistry
import com.airbnb.android.showkase.models.Showkase
Expand Down Expand Up @@ -70,12 +74,21 @@ class ShowcaseBrowserTest {
clickRowWithText("Components ($componentSize)")

// Verify that all the groups are displayed on the screen
verifyRowsWithTextAreDisplayed(
"Group1 (2)",
"Group2 (1)",
"Group3 (2)",
"Submodule (1)"
)
if (BuildConfig.IS_RUNNING_KSP) {
verifyRowsWithTextAreDisplayed(
"Button (4)",
"Chips (1)",
"CustomExternalPreview (4)",
"Group1 (2)"
)
} else {
verifyRowsWithTextAreDisplayed(
"Group1 (2)",
"Group2 (1)",
"Group3 (2)",
"Submodule (1)"
)
}
}
}

Expand Down Expand Up @@ -665,7 +678,7 @@ class ShowcaseBrowserTest {

waitForIdle()

clickRowWithText("Group7 (4)")
clickRowWithText("A Stacked Annotations (4)")

waitForIdle()

Expand All @@ -678,4 +691,90 @@ class ShowcaseBrowserTest {
}
}
}

@Test
fun combined_custom_annotation_previews_are_generated_correctly() {
if (BuildConfig.IS_RUNNING_KSP) {
composeTestRule.apply {
verifyLandingScreen(
components = componentSize,
typography = 13,
colors = 4,
)

// Tap on the "Components" row
clickRowWithText("Components ($componentSize)")

waitForIdle()

clickRowWithText("CustomExternalPreview (4)")

waitForIdle()

// Verify that combined are treated as different composables. The reason these are
// only two is that the other two is in another group.
onNodeWithText("PreviewCombinedCustomAnnotation - CustomPreview one - 1").assertIsDisplayed()
onNodeWithText("PreviewCombinedCustomAnnotation - CustomPreview two - 1").assertIsDisplayed()

// Verify that we have made managed to make previews from custom annotation in other module
onNodeWithText("PreviewCustomTextWithCustomAnnotationFromOtherModule - CustomPreview one - 0").assertIsDisplayed()
onNodeWithText("PreviewCustomTextWithCustomAnnotationFromOtherModule - CustomPreview two - 0").assertIsDisplayed()
}
}
}

@Test
fun internal_custom_annotation_preview_are_generated_correctly() {
if (BuildConfig.IS_RUNNING_KSP) {
composeTestRule.apply {
verifyLandingScreen(
components = componentSize,
typography = 13,
colors = 4,
)

// Tap on the "Components" row
clickRowWithText("Components ($componentSize)")

waitForIdle()

clickRowWithText("Button (4)")

waitForIdle()

// Check that we have generated the previews for single internal custom annotation
onNodeWithText("PreviewCustomText - Custom Text Light").assertIsDisplayed()
onNodeWithText("PreviewCustomText - Custom Text Dark").assertIsDisplayed()

// Check that we have generated the previews from combined internal custom annotation
// The reason this is only two and not four is that they are placed in different
// groups. That is because the previews have different groups set.
onNodeWithText("PreviewCombinedCustomAnnotation - Custom Text Dark").assertIsDisplayed()
onNodeWithText("PreviewCombinedCustomAnnotation - Custom Text Light").assertIsDisplayed()
}
}
}

@Test
fun combined_preview_with_single_preview_generates_the_single_preview() {
// This should work with both KSP and KAPT.
composeTestRule.apply {
verifyLandingScreen(
components = componentSize,
typography = 13,
colors = 4,
)

// Tap on the "Components" row
clickRowWithText("Components ($componentSize)")

waitForIdle()

clickRowWithText("Chips (1)")

waitForIdle()

onNodeWithText("Custom Text Dark From Combined Previews").assertIsDisplayed()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ class WrapperComposableClass {
}
}

@ShowkaseComposable("Composable7", "Group7")
@ShowkaseComposable("Composable8", "Group7")
@ShowkaseComposable("Composable7", "A Stacked Annotations")
@ShowkaseComposable("Composable8", "A Stacked Annotations")
@Composable
fun TestComposable7() {
BasicText(text = "Test Composable7and8")
}

@Preview("Composable9", "Group7")
@Preview("Composable10", "Group7")
@Preview("Composable9", "A Stacked Annotations")
@Preview("Composable10", "A Stacked Annotations")
@Composable
fun TestComposable8() {
BasicText(text = "Test Composable9and10")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.room.compiler.processing.XElement
import androidx.room.compiler.processing.XFieldElement
import androidx.room.compiler.processing.XMemberContainer
import androidx.room.compiler.processing.XMethodElement
import androidx.room.compiler.processing.XProcessingEnv
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.compat.XConverters.toJavac
Expand All @@ -15,23 +14,20 @@ import com.airbnb.android.showkase.annotation.ShowkaseColor
import com.airbnb.android.showkase.annotation.ShowkaseComposable
import com.airbnb.android.showkase.annotation.ShowkaseMultiPreviewCodegenMetadata
import com.airbnb.android.showkase.annotation.ShowkaseTypography
import com.airbnb.android.showkase.processor.ShowkaseProcessor
import com.airbnb.android.showkase.processor.ShowkaseProcessor.Companion.PREVIEW_PARAMETER_SIMPLE_NAME
import com.airbnb.android.showkase.processor.ShowkaseProcessor.Companion.PREVIEW_SIMPLE_NAME
import com.airbnb.android.showkase.processor.exceptions.ShowkaseProcessorException
import com.airbnb.android.showkase.processor.logging.ShowkaseValidator
import com.airbnb.android.showkase.processor.utils.findAnnotationBySimpleName
import com.airbnb.android.showkase.processor.utils.getFieldWithReflection
import com.airbnb.android.showkase.processor.utils.requireAnnotationBySimpleName
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.TypeName
import com.squareup.kotlinpoet.javapoet.toKClassName
import com.squareup.kotlinpoet.javapoet.toKTypeName
import kotlinx.metadata.jvm.KotlinClassHeader.Companion.FILE_FACADE_KIND
import kotlinx.metadata.jvm.KotlinClassMetadata
import java.util.Locale
import javax.annotation.processing.ProcessingEnvironment

@Suppress("LongParameterList")
internal sealed class ShowkaseMetadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.airbnb.android.showkase.processor.writer

import androidx.room.compiler.processing.XAnnotation
import androidx.room.compiler.processing.XElement
import androidx.room.compiler.processing.XFiler
import androidx.room.compiler.processing.XProcessingEnv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.room.compiler.processing.XProcessingEnv
import androidx.room.compiler.processing.addOriginatingElement
import androidx.room.compiler.processing.writeTo
import com.airbnb.android.showkase.annotation.ShowkaseCodegenMetadata
import com.airbnb.android.showkase.processor.ShowkaseProcessor
import com.airbnb.android.showkase.processor.ShowkaseProcessor.Companion.CODEGEN_PACKAGE_NAME
import com.airbnb.android.showkase.processor.models.ShowkaseMetadata
import com.airbnb.android.showkase.processor.models.ShowkaseMetadataType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ internal class ShowkaseExtensionFunctionsWriter(
addParameter(
CONTEXT_PARAMETER_NAME, CONTEXT_CLASS_NAME
)
addKdoc("Helper function that's autogenerated and gives you an intent to start the " +
"ShowkaseBrowser.")
addKdoc(
"Helper function that's autogenerated and gives you an intent to start the " +
"ShowkaseBrowser."
)
receiver(SHOWKASE_OBJECT_CLASS_NAME)
returns(INTENT_CLASS_NAME)
addCode(
Expand Down Expand Up @@ -85,9 +87,11 @@ internal class ShowkaseExtensionFunctionsWriter(
"https://github.com/airbnb/Showkase#Installation."
receiver(SHOWKASE_OBJECT_CLASS_NAME)
returns(SHOWKASE_ELEMENTS_METADATA_CLASS_NAME)
addKdoc("Helper function that's give's you access to Showkase metadata. This contains " +
"data about the composables, colors and typography in your codebase that's " +
"rendered in showakse.")
addKdoc(
"Helper function that's give's you access to Showkase metadata. This contains " +
"data about the composables, colors and typography in your codebase that's " +
"rendered in showakse."
)
addCode(
CodeBlock.Builder()
.indent()
Expand Down Expand Up @@ -125,7 +129,7 @@ internal class ShowkaseExtensionFunctionsWriter(
ClassName(CONTEXT_PACKAGE_NAME, "Intent")
private val SHOWKASE_BROWSER_ACTIVITY_CLASS_NAME =
ClassName("com.airbnb.android.showkase.ui", "ShowkaseBrowserActivity")
private val SHOWKASE_ELEMENTS_METADATA_CLASS_NAME =
private val SHOWKASE_ELEMENTS_METADATA_CLASS_NAME =
ClassName(SHOWKASE_MODELS_PACKAGE_NAME, "ShowkaseElementsMetadata")
internal val SHOWKASE_OBJECT_CLASS_NAME =
ClassName(SHOWKASE_MODELS_PACKAGE_NAME, "Showkase")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ internal class ShowkaseScreenshotTestWriter(private val environment: XProcessing
private val CREATE_COMPOSE_RULE_CLASS_NAME = ClassName(JUNIT4_PACKAGE, "createComposeRule")
private val INSTRUMENTATION_REGISTRY_CLASS_NAME =
ClassName("androidx.test.platform.app", "InstrumentationRegistry")
private val GRANT_PERMISSION_RULE_CLASS_NAME = ClassName("androidx.test.rule",
"GrantPermissionRule")
private val GRANT_PERMISSION_RULE_CLASS_NAME = ClassName(
"androidx.test.rule",
"GrantPermissionRule"
)
private val JVM_FIELD_CLASS_NAME = ClassName("kotlin.jvm", "JvmField")
private val MANIFEST_CLASS_NAME = ClassName("android", "Manifest")
}
Expand Down

0 comments on commit aad61a6

Please sign in to comment.