Skip to content

Commit

Permalink
Fix issue with submodule components not showing up (#216)
Browse files Browse the repository at this point in the history
* Fix issue

* Added submodule to verify components are being pulled from all modules

* Fix failing tests

* Fix detekt issue

* Remove unnecessary code
  • Loading branch information
vinaygaba committed Jan 27, 2022
1 parent f056dbd commit f12c050
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 9 deletions.
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ rootProject.name = "Showkase"
include ':sample-submodule'
include ':showkase-screenshot-testing'
include ':showkase-browser-testing'
include ':showkase-browser-testing-submodule'
1 change: 1 addition & 0 deletions showkase-browser-testing-submodule/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
85 changes: 85 additions & 0 deletions showkase-browser-testing-submodule/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 31
// Added to avoid this error -
// Execution failed for task ':showkase-processor-testing:mergeDebugAndroidTestJavaResource'.
// > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
// > More than one file was found with OS independent path 'META-INF/gradle/incremental.annotation.processors'
packagingOptions {
exclude 'META-INF/gradle/incremental.annotation.processors'
exclude("META-INF/*.kotlin_module")
}
defaultConfig {
minSdkVersion 26
targetSdkVersion 30
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// The following argument makes the Android Test Orchestrator run its
// "pm clear" command after each test invocation. This command ensures
// that the app's state is completely cleared between tests.
testInstrumentationRunnerArguments clearPackageData: 'true'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerVersion "${versions.kotlinCompilerVersion}"
kotlinCompilerExtensionVersion "${versions.compose}"
}
// Added to avoid this error -
// Execution failed for task ':app:mergeDebugAndroidTestJavaResource'.
// > A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
// > 2 files found with path 'META-INF/AL2.0' from inputs:
packagingOptions {
exclude 'META-INF/AL2.0'
exclude 'META-INF/LGPL2.1'
}
configurations {
all {
// work around this error:
// Duplicate class org.intellij.lang.annotations.Identifier found in modules annotations-12.0 (com.intellij:annotations:12.0) and annotations-13.0 (org.jetbrains:annotations:13.0)
exclude group: "com.intellij", module: "annotations"
}
}
}

dependencies {
// Support Libraries
implementation deps.support.appCompat

// Showkase
implementation project(':showkase')
if (project.hasProperty('useKsp')) {
ksp project(':showkase-processor')
} else {
kapt project(':showkase-processor')
}
implementation project(':showkase-processor')
implementation project(':showkase-screenshot-testing')

// Compose
implementation deps.compose.activityCompose
implementation deps.compose.composeRuntime
implementation deps.compose.core
implementation deps.compose.foundation
implementation deps.compose.tooling
androidTestImplementation deps.compose.uiTest

// Material
implementation deps.material.material
implementation deps.material.mdcComposeThemeAdapter

// Testing
androidTestImplementation deps.test.junitImplementation
androidTestImplementation deps.test.androidXTestCore
androidTestImplementation deps.test.androidXTestRules
androidTestImplementation deps.test.androidxTestRunner
}
Empty file.
21 changes: 21 additions & 0 deletions showkase-browser-testing-submodule/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vinaygaba.showkase_browser_testing_submodule">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@file:Suppress("PackageNaming")
package com.vinaygaba.showkase_browser_testing_submodule

import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import com.airbnb.android.showkase.annotation.ShowkaseComposable

@ShowkaseComposable(name = "Submodule Component", group = "Submodule")
@Composable
fun SubmoduleComposable() {
BasicText(text = "Submodule Component")
}
2 changes: 2 additions & 0 deletions showkase-browser-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ android {
dependencies {
// Support Libraries
implementation deps.support.appCompat
// Submodule for testing
implementation project(':showkase-browser-testing-submodule')

// Showkase
implementation project(':showkase')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ class ShowcaseBrowserTest {
verifyLandingScreen()

// Tap on the "Components" row
clickRowWithText("Components (5)")
clickRowWithText("Components (6)")

// Verify that all the groups are displayed on the screen
verifyRowsWithTextAreDisplayed("Group1 (2)", "Group2 (1)", "Group3 (2)")
verifyRowsWithTextAreDisplayed("Group1 (2)", "Group2 (1)", "Group3 (2)", "Submodule (1)")
}
}

Expand Down Expand Up @@ -94,7 +94,7 @@ class ShowcaseBrowserTest {
verifyLandingScreen()

// Tap on the "Components" row
clickRowWithText("Components (5)")
clickRowWithText("Components (6)")

// Select "Group1"
clickRowWithText("Group1 (2)")
Expand Down Expand Up @@ -200,7 +200,7 @@ class ShowcaseBrowserTest {
verifyLandingScreen()

// Select Components
clickRowWithText("Components (5)")
clickRowWithText("Components (6)")

// Tap on the search icon
clickRowWithTag("SearchIcon")
Expand Down Expand Up @@ -264,7 +264,7 @@ class ShowcaseBrowserTest {
verifyLandingScreen()

// Select components
clickRowWithText("Components (5)")
clickRowWithText("Components (6)")

// Select Group 3
clickRowWithText("Group3 (2)")
Expand Down Expand Up @@ -355,7 +355,7 @@ class ShowcaseBrowserTest {
verifyLandingScreen()

// Select components to go to the component groups screen
clickRowWithText("Components (5)")
clickRowWithText("Components (6)")

// Click on "Group 1" to go to the components in a group screen
clickRowWithText("Group1 (2)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal fun <T : ComponentActivity> AndroidComposeTestRule<ActivityScenarioRule
}

internal fun AndroidComposeTestRule<ActivityScenarioRule<ShowkaseBrowserActivity>, ShowkaseBrowserActivity>.verifyLandingScreen() {
verifyRowsWithTextAreDisplayed("Components (5)", "Typography (13)", "Colors (4)")
verifyRowsWithTextAreDisplayed("Components (6)", "Typography (13)", "Colors (4)")
}

internal fun AndroidComposeTestRule<ActivityScenarioRule<ShowkaseBrowserActivity>, ShowkaseBrowserActivity>.verifyTypographyDetailScreen() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,16 @@ class ShowkaseProcessor @JvmOverloads constructor(

private fun getShowkaseCodegenMetadataOnClassPath(environment: XProcessingEnv): Set<ShowkaseMetadata> {
return environment.getTypeElementsFromPackage(CODEGEN_PACKAGE_NAME)
.flatMap { it.getEnclosedElements() }
.mapNotNull { element ->
val codegenMetadataAnnotation =
element.getAnnotation(ShowkaseCodegenMetadata::class)
when {
codegenMetadataAnnotation == null -> null
else -> codegenMetadataAnnotation.toModel(element)
else -> element to codegenMetadataAnnotation
}
}
.map { it.second.toModel(it.first) }
.toSet()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ internal enum class ShowkaseMetadataType {
TYPOGRAPHY
}

internal fun XAnnotationBox<ShowkaseCodegenMetadata>.toModel(element: XTypeElement): ShowkaseMetadata {
internal fun XAnnotationBox<ShowkaseCodegenMetadata>.toModel(element: XElement): ShowkaseMetadata {
val (enclosingClassType, previewParameterClassType) = getCodegenMetadataTypes()

// The box is needed to get all Class values, primitives can be accessed dirctly
Expand Down

0 comments on commit f12c050

Please sign in to comment.