Skip to content

Commit e6646de

Browse files
committed
Add UI test
1 parent aa46317 commit e6646de

File tree

8 files changed

+125
-27
lines changed

8 files changed

+125
-27
lines changed

sample/src/main/java/com/airbnb/android/showkasesample/CustomButton.kt

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import androidx.compose.ui.graphics.Color
1212
import androidx.compose.ui.text.TextStyle
1313
import androidx.compose.ui.unit.dp
1414
import com.airbnb.android.showkase.annotation.ShowkaseComposable
15-
import com.airbnb.android.submodule.showkasesample.CustomPreviewAnnotation
1615

1716
@Composable
1817
fun CustomButton(

showkase-browser-testing/src/androidTest/java/com/airbnb/android/showkase_browser_testing/ShowkaseBrowserTest.kt

+107-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.airbnb.android.showkase_browser_testing
22

3-
import androidx.compose.ui.test.*
3+
import androidx.compose.ui.test.assertIsDisplayed
44
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
5+
import androidx.compose.ui.test.onNodeWithTag
6+
import androidx.compose.ui.test.onNodeWithText
7+
import androidx.compose.ui.test.performGesture
8+
import androidx.compose.ui.test.swipeDown
59
import androidx.test.ext.junit.rules.ActivityScenarioRule
610
import androidx.test.platform.app.InstrumentationRegistry
711
import com.airbnb.android.showkase.models.Showkase
@@ -70,12 +74,21 @@ class ShowcaseBrowserTest {
7074
clickRowWithText("Components ($componentSize)")
7175

7276
// Verify that all the groups are displayed on the screen
73-
verifyRowsWithTextAreDisplayed(
74-
"Group1 (2)",
75-
"Group2 (1)",
76-
"Group3 (2)",
77-
"Submodule (1)"
78-
)
77+
if (BuildConfig.IS_RUNNING_KSP) {
78+
verifyRowsWithTextAreDisplayed(
79+
"Button (4)",
80+
"Chips (1)",
81+
"CustomExternalPreview (4)",
82+
"Group1 (2)"
83+
)
84+
} else {
85+
verifyRowsWithTextAreDisplayed(
86+
"Group1 (2)",
87+
"Group2 (1)",
88+
"Group3 (2)",
89+
"Submodule (1)"
90+
)
91+
}
7992
}
8093
}
8194

@@ -665,7 +678,7 @@ class ShowcaseBrowserTest {
665678

666679
waitForIdle()
667680

668-
clickRowWithText("Group7 (4)")
681+
clickRowWithText("Stacked Annotations (4)")
669682

670683
waitForIdle()
671684

@@ -678,4 +691,90 @@ class ShowcaseBrowserTest {
678691
}
679692
}
680693
}
694+
695+
@Test
696+
fun combined_custom_annotation_previews_are_generated_correctly() {
697+
if (BuildConfig.IS_RUNNING_KSP) {
698+
composeTestRule.apply {
699+
verifyLandingScreen(
700+
components = componentSize,
701+
typography = 13,
702+
colors = 4,
703+
)
704+
705+
// Tap on the "Components" row
706+
clickRowWithText("Components ($componentSize)")
707+
708+
waitForIdle()
709+
710+
clickRowWithText("CustomExternalPreview (4)")
711+
712+
waitForIdle()
713+
714+
// Verify that combined are treated as different composables. The reason these are
715+
// only two is that the other two is in another group.
716+
onNodeWithText("PreviewCombinedCustomAnnotation - CustomPreview one - 1").assertIsDisplayed()
717+
onNodeWithText("PreviewCombinedCustomAnnotation - CustomPreview two - 1").assertIsDisplayed()
718+
719+
// Verify that we have made managed to make previews from custom annotation in other module
720+
onNodeWithText("PreviewCustomTextWithCustomAnnotationFromOtherModule - CustomPreview one - 0").assertIsDisplayed()
721+
onNodeWithText("PreviewCustomTextWithCustomAnnotationFromOtherModule - CustomPreview two - 0").assertIsDisplayed()
722+
}
723+
}
724+
}
725+
726+
@Test
727+
fun internal_custom_annotation_preview_are_generated_correctly() {
728+
if (BuildConfig.IS_RUNNING_KSP) {
729+
composeTestRule.apply {
730+
verifyLandingScreen(
731+
components = componentSize,
732+
typography = 13,
733+
colors = 4,
734+
)
735+
736+
// Tap on the "Components" row
737+
clickRowWithText("Components ($componentSize)")
738+
739+
waitForIdle()
740+
741+
clickRowWithText("Button (4)")
742+
743+
waitForIdle()
744+
745+
// Check that we have generated the previews for single internal custom annotation
746+
onNodeWithText("PreviewCustomText - Custom Text Light").assertIsDisplayed()
747+
onNodeWithText("PreviewCustomText - Custom Text Dark").assertIsDisplayed()
748+
749+
// Check that we have generated the previews from combined internal custom annotation
750+
// The reason this is only two and not four is that they are placed in different
751+
// groups. That is because the previews have different groups set.
752+
onNodeWithText("PreviewCombinedCustomAnnotation - Custom Text Dark").assertIsDisplayed()
753+
onNodeWithText("PreviewCombinedCustomAnnotation - Custom Text Light").assertIsDisplayed()
754+
}
755+
}
756+
}
757+
758+
@Test
759+
fun combined_preview_with_single_preview_generates_the_single_preview() {
760+
// This should work with both KSP and KAPT.
761+
composeTestRule.apply {
762+
verifyLandingScreen(
763+
components = componentSize,
764+
typography = 13,
765+
colors = 4,
766+
)
767+
768+
// Tap on the "Components" row
769+
clickRowWithText("Components ($componentSize)")
770+
771+
waitForIdle()
772+
773+
clickRowWithText("Chips (1)")
774+
775+
waitForIdle()
776+
777+
onNodeWithText("Custom Text Dark From Combined Previews").assertIsDisplayed()
778+
}
779+
}
681780
}

showkase-browser-testing/src/main/java/com/airbnb/android/showkase_browser_testing/TestComposables.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ class WrapperComposableClass {
5454
}
5555
}
5656

57-
@ShowkaseComposable("Composable7", "Group7")
58-
@ShowkaseComposable("Composable8", "Group7")
57+
@ShowkaseComposable("Composable7", "Stacked Annotations")
58+
@ShowkaseComposable("Composable8", "Stacked Annotations")
5959
@Composable
6060
fun TestComposable7() {
6161
BasicText(text = "Test Composable7and8")
6262
}
6363

64-
@Preview("Composable9", "Group7")
65-
@Preview("Composable10", "Group7")
64+
@Preview("Composable9", "Stacked Annotations")
65+
@Preview("Composable10", "Stacked Annotations")
6666
@Composable
6767
fun TestComposable8() {
6868
BasicText(text = "Test Composable9and10")

showkase-processor/src/main/java/com/airbnb/android/showkase/processor/models/ShowkaseMetadata.kt

-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import androidx.room.compiler.processing.XElement
66
import androidx.room.compiler.processing.XFieldElement
77
import androidx.room.compiler.processing.XMemberContainer
88
import androidx.room.compiler.processing.XMethodElement
9-
import androidx.room.compiler.processing.XProcessingEnv
109
import androidx.room.compiler.processing.XType
1110
import androidx.room.compiler.processing.XTypeElement
1211
import androidx.room.compiler.processing.compat.XConverters.toJavac
@@ -15,23 +14,20 @@ import com.airbnb.android.showkase.annotation.ShowkaseColor
1514
import com.airbnb.android.showkase.annotation.ShowkaseComposable
1615
import com.airbnb.android.showkase.annotation.ShowkaseMultiPreviewCodegenMetadata
1716
import com.airbnb.android.showkase.annotation.ShowkaseTypography
18-
import com.airbnb.android.showkase.processor.ShowkaseProcessor
1917
import com.airbnb.android.showkase.processor.ShowkaseProcessor.Companion.PREVIEW_PARAMETER_SIMPLE_NAME
2018
import com.airbnb.android.showkase.processor.ShowkaseProcessor.Companion.PREVIEW_SIMPLE_NAME
2119
import com.airbnb.android.showkase.processor.exceptions.ShowkaseProcessorException
2220
import com.airbnb.android.showkase.processor.logging.ShowkaseValidator
2321
import com.airbnb.android.showkase.processor.utils.findAnnotationBySimpleName
2422
import com.airbnb.android.showkase.processor.utils.getFieldWithReflection
2523
import com.airbnb.android.showkase.processor.utils.requireAnnotationBySimpleName
26-
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
2724
import com.squareup.kotlinpoet.ClassName
2825
import com.squareup.kotlinpoet.TypeName
2926
import com.squareup.kotlinpoet.javapoet.toKClassName
3027
import com.squareup.kotlinpoet.javapoet.toKTypeName
3128
import kotlinx.metadata.jvm.KotlinClassHeader.Companion.FILE_FACADE_KIND
3229
import kotlinx.metadata.jvm.KotlinClassMetadata
3330
import java.util.Locale
34-
import javax.annotation.processing.ProcessingEnvironment
3531

3632
@Suppress("LongParameterList")
3733
internal sealed class ShowkaseMetadata {

showkase-processor/src/main/java/com/airbnb/android/showkase/processor/writer/ShowkaseBrowserWriter.kt

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.airbnb.android.showkase.processor.writer
22

3-
import androidx.room.compiler.processing.XAnnotation
43
import androidx.room.compiler.processing.XElement
54
import androidx.room.compiler.processing.XFiler
65
import androidx.room.compiler.processing.XProcessingEnv

showkase-processor/src/main/java/com/airbnb/android/showkase/processor/writer/ShowkaseCodegenMetadataWriter.kt

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import androidx.room.compiler.processing.XProcessingEnv
55
import androidx.room.compiler.processing.addOriginatingElement
66
import androidx.room.compiler.processing.writeTo
77
import com.airbnb.android.showkase.annotation.ShowkaseCodegenMetadata
8-
import com.airbnb.android.showkase.processor.ShowkaseProcessor
98
import com.airbnb.android.showkase.processor.ShowkaseProcessor.Companion.CODEGEN_PACKAGE_NAME
109
import com.airbnb.android.showkase.processor.models.ShowkaseMetadata
1110
import com.airbnb.android.showkase.processor.models.ShowkaseMetadataType

showkase-processor/src/main/java/com/airbnb/android/showkase/processor/writer/ShowkaseExtensionFunctionsWriter.kt

+10-6
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ internal class ShowkaseExtensionFunctionsWriter(
4848
addParameter(
4949
CONTEXT_PARAMETER_NAME, CONTEXT_CLASS_NAME
5050
)
51-
addKdoc("Helper function that's autogenerated and gives you an intent to start the " +
52-
"ShowkaseBrowser.")
51+
addKdoc(
52+
"Helper function that's autogenerated and gives you an intent to start the " +
53+
"ShowkaseBrowser."
54+
)
5355
receiver(SHOWKASE_OBJECT_CLASS_NAME)
5456
returns(INTENT_CLASS_NAME)
5557
addCode(
@@ -85,9 +87,11 @@ internal class ShowkaseExtensionFunctionsWriter(
8587
"https://github.com/airbnb/Showkase#Installation."
8688
receiver(SHOWKASE_OBJECT_CLASS_NAME)
8789
returns(SHOWKASE_ELEMENTS_METADATA_CLASS_NAME)
88-
addKdoc("Helper function that's give's you access to Showkase metadata. This contains " +
89-
"data about the composables, colors and typography in your codebase that's " +
90-
"rendered in showakse.")
90+
addKdoc(
91+
"Helper function that's give's you access to Showkase metadata. This contains " +
92+
"data about the composables, colors and typography in your codebase that's " +
93+
"rendered in showakse."
94+
)
9195
addCode(
9296
CodeBlock.Builder()
9397
.indent()
@@ -125,7 +129,7 @@ internal class ShowkaseExtensionFunctionsWriter(
125129
ClassName(CONTEXT_PACKAGE_NAME, "Intent")
126130
private val SHOWKASE_BROWSER_ACTIVITY_CLASS_NAME =
127131
ClassName("com.airbnb.android.showkase.ui", "ShowkaseBrowserActivity")
128-
private val SHOWKASE_ELEMENTS_METADATA_CLASS_NAME =
132+
private val SHOWKASE_ELEMENTS_METADATA_CLASS_NAME =
129133
ClassName(SHOWKASE_MODELS_PACKAGE_NAME, "ShowkaseElementsMetadata")
130134
internal val SHOWKASE_OBJECT_CLASS_NAME =
131135
ClassName(SHOWKASE_MODELS_PACKAGE_NAME, "Showkase")

showkase-processor/src/main/java/com/airbnb/android/showkase/processor/writer/ShowkaseScreenshotTestWriter.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ internal class ShowkaseScreenshotTestWriter(private val environment: XProcessing
111111
private val CREATE_COMPOSE_RULE_CLASS_NAME = ClassName(JUNIT4_PACKAGE, "createComposeRule")
112112
private val INSTRUMENTATION_REGISTRY_CLASS_NAME =
113113
ClassName("androidx.test.platform.app", "InstrumentationRegistry")
114-
private val GRANT_PERMISSION_RULE_CLASS_NAME = ClassName("androidx.test.rule",
115-
"GrantPermissionRule")
114+
private val GRANT_PERMISSION_RULE_CLASS_NAME = ClassName(
115+
"androidx.test.rule",
116+
"GrantPermissionRule"
117+
)
116118
private val JVM_FIELD_CLASS_NAME = ClassName("kotlin.jvm", "JvmField")
117119
private val MANIFEST_CLASS_NAME = ClassName("android", "Manifest")
118120
}

0 commit comments

Comments
 (0)