Skip to content

Commit

Permalink
KasperskyLab#249. Jetpack Compose Main page (template) in the sample …
Browse files Browse the repository at this point in the history
…is ready
  • Loading branch information
matzuk committed Nov 4, 2021
1 parent 56b727c commit c75259d
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ android {
}
}

@Suppress("UnstableApiUsage")
onVariants {
androidTest {
enabled = false
}
}
// todo doesn't work on AGP 4.2.2
// @Suppress("UnstableApiUsage")
// onVariants {
// androidTest {
// enabled = false
// }
// }
}
18 changes: 15 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
[versions]
kotlin = "1.4.32"
kotlin = "1.5.21"
detekt = "1.18.1"
espresso = "3.4.0"
allure = "2.2.7"
compose = "1.0.2"
activityCompose = "1.3.1"

[libraries]
# plugins
kotlinPlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
androidPlugin = "com.android.tools.build:gradle:4.1.0"
androidPlugin = "com.android.tools.build:gradle:4.2.2"

# libraries
kotlinCli = "org.jetbrains.kotlinx:kotlinx-cli:0.3"
Expand All @@ -28,7 +30,16 @@ androidXCore = "androidx.core:core:1.7.0"
androidXRules = "androidx.test:rules:1.4.0"
androidXTest = "androidx.test.ext:junit:1.1.3"
androidXTestKtx = "androidx.test.ext:junit-ktx:1.1.3"
composeUiTest = "androidx.compose.ui:ui-test:1.0.3"

composeActivity = { module = "androidx.activity:activity-compose", version.ref = "activityCompose" }
composeUiTooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
composeMaterial = { module = "androidx.compose.material:material", version.ref = "compose" }
composeTestManifest = { module = "androidx.compose.ui:ui-test-manifest", version.ref = "compose" }
composeCompiler = { module = "androidx.compose.compiler:compiler", version.ref = "compose" }

composeUiTest = { module = "androidx.compose.ui:ui-test", version.ref = "compose" }

composeJunit = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "compose" }

appcompat = "androidx.appcompat:appcompat:1.3.0"
material = "com.google.android.material:material:1.2.0"
Expand All @@ -55,3 +66,4 @@ allureKotlinAndroid = { module = "io.qameta.allure:allure-kotlin-android", versi
[bundles]
espresso = ["espressoCore", "espressoWeb"]
allure = ["allureKotlinModel", "allureKotlinCommons", "allureKotlinJunit4", "allureKotlinAndroid"]
compose = ["composeActivity", "composeUiTooling", "composeMaterial", "composeTestManifest", "composeCompiler"]
1 change: 1 addition & 0 deletions kaspresso/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
implementation(libs.kotlinStdlib)
implementation(libs.gson)
implementation(projects.adbServer.adbserverDevice)
// todo remove woth kakao-compose 0.0.3
implementation(libs.composeUiTest)

testImplementation(libs.junit)
Expand Down
12 changes: 12 additions & 0 deletions samples/kaspresso-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ android {
testInstrumentationRunnerArguments["clearPackageData"] = "true"
}

buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerVersion = libs.versions.kotlin.get()
kotlinCompilerExtensionVersion = libs.versions.compose.get()
}

sourceSets {
val main by getting {
java.srcDir("src/main/kotlin")
Expand Down Expand Up @@ -37,13 +46,15 @@ dependencies {
implementation(libs.appcompat)
implementation(libs.material)
implementation(libs.constraint)
implementation(libs.bundles.compose)

androidTestImplementation(libs.runner)
androidTestImplementation(libs.junit)
androidTestImplementation(projects.kaspresso)
androidTestImplementation(libs.androidXRules)
androidTestImplementation(libs.androidXTestKtx)
androidTestImplementation(libs.androidXTest)
androidTestImplementation(libs.composeJunit)

androidTestUtil(libs.orchestrator)

Expand All @@ -54,6 +65,7 @@ dependencies {
testImplementation(libs.androidXTestKtx)
testImplementation(libs.androidXTest)
testImplementation(libs.robolectric)
testImplementation(libs.composeJunit)

debugImplementation(libs.fragmentTesting)
}
4 changes: 4 additions & 0 deletions samples/kaspresso-sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
android:name=".sharedtest.SharedTestActivity"
android:label="@string/main_screen_shared_test"/>

<activity
android:name=".jetpack_compose.JetpackComposeActivity"
android:label="@string/main_screen_jetpack_compose_button"/>

<service
android:name=".device.DeviceSampleAccessibilityService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,11 @@ class MainActivity : AppCompatActivity() {
Intent(this, MeasureActivity::class.java)
)
}

activity_main_jetpack_compose_button.setOnClickListener {
startActivity(
Intent(this, MeasureActivity::class.java)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.kaspersky.kaspressample.jetpack_compose

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTag
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

@Composable
fun ComposeScreen() {
Column(
modifier = Modifier
.fillMaxSize()
.semantics { testTag = "MainScreen" }
) {
Text(
text = "Simple text 1",
modifier = Modifier
.padding(8.dp)
.semantics { testTag = "mySimpleText" }
)

Text(
text = "Simple text 2",
modifier = Modifier
.padding(8.dp)
.semantics { testTag = "mySimpleText" }
)

Button(
content = {
Text(text = "Button 1")
},
onClick = {
// nothing
},
modifier = Modifier
.padding(8.dp)
.semantics { testTag = "myTestButton" }
)
}
}

@Composable
@Preview(showSystemUi = true)
private fun MainScreenPreview() {
MaterialTheme {
ComposeScreen()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.kaspersky.kaspressample.jetpack_compose

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity

class JetpackComposeActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ComposeScreen()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,18 @@
android:layout_below="@id/activity_main_idlewaiting_sample_button"
android:text="@string/main_screen_measure_sample_button" />

<Button
android:id="@+id/activity_main_jetpack_compose_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/activity_main_measure_sample_button"
android:text="@string/main_screen_jetpack_compose_button" />

<TextView
android:id="@+id/activity_main_description_textview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="@+id/activity_main_measure_sample_button"
android:text="@string/main_screen_title" />

</RelativeLayout>
</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<string name="main_screen_complex_compose_sample_button">Complex compose пример</string>
<string name="main_screen_idlewaiting_sample_button">Waiting for idle пример</string>
<string name="main_screen_measure_sample_button">Measure пример</string>
<string name="main_screen_jetpack_compose_button">Jetpack Compose примеры</string>
<string name="main_screen_shared_test">Shared Test with Robolectric пример</string>

<!-- Simple fragment screen -->
Expand Down
1 change: 1 addition & 0 deletions samples/kaspresso-sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<string name="main_screen_complex_compose_sample_button">Complex compose sample</string>
<string name="main_screen_idlewaiting_sample_button">Waiting for idle sample</string>
<string name="main_screen_measure_sample_button">Measure sample</string>
<string name="main_screen_jetpack_compose_button">Jetpack Compose samples</string>
<string name="main_screen_shared_test">Shared Test with Robolectric sample</string>

<!-- Simple fragment screen -->
Expand Down

0 comments on commit c75259d

Please sign in to comment.