Skip to content

Commit b06f240

Browse files
AboutActivity to Jetpack Compose (#2489)
* WIP * test: Add test tags for compose components * test: Add basic test for compose about screen * refactor: Add defaults for `AboutScreenContent` * refactor: Move compose tests to unit tests * refactor: Make `showRateOnGooglePlay` default to `app/build.gradle.kts/defaultConfig` value * refactor: Best practise to make previews private to reduce pollution * refactor: Best practise apply theme as high as possible for most cases * style: Format AboutActivity.kt * test: Add more comprehensive tests for about screen * test: Fix configuration of compose tests * Fix Gradle setup * Fix build issues * Adjust text sizing * Use full black OLED theme in Compose if chosen in settings --------- Co-authored-by: LooKeR <[email protected]>
1 parent 61e2626 commit b06f240

File tree

15 files changed

+475
-759
lines changed

15 files changed

+475
-759
lines changed

app/build.gradle.kts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
44
plugins {
55
alias(libs.plugins.com.android.application)
66
alias(libs.plugins.org.jetbrains.kotlin.android)
7+
alias(libs.plugins.org.jetbrains.kotlin.plugin.compose)
78
}
89

910
kotlin {
@@ -48,6 +49,7 @@ android {
4849

4950
buildFeatures {
5051
buildConfig = true
52+
compose = true
5153
viewBinding = true
5254
}
5355

@@ -93,18 +95,21 @@ android {
9395
lint {
9496
lintConfig = file("lint.xml")
9597
}
98+
9699
kotlin {
97100
compilerOptions {
98-
jvmTarget = JvmTarget.JVM_21
101+
jvmTarget = JvmTarget.JVM_17
99102
}
100103
}
101104
compileOptions {
102105
encoding = "UTF-8"
103106

104107
// Flag to enable support for the new language APIs
105108
isCoreLibraryDesugaringEnabled = true
106-
sourceCompatibility = JavaVersion.VERSION_21
107-
targetCompatibility = JavaVersion.VERSION_21
109+
110+
111+
sourceCompatibility = JavaVersion.VERSION_17
112+
targetCompatibility = JavaVersion.VERSION_17
108113
}
109114
}
110115

@@ -121,6 +126,19 @@ dependencies {
121126
implementation(libs.com.google.android.material.material)
122127
coreLibraryDesugaring(libs.com.android.tools.desugar.jdk.libs)
123128

129+
// Compose
130+
implementation(libs.androidx.activity.activity.compose)
131+
val composeBom = platform(libs.androidx.compose.compose.bom)
132+
implementation(composeBom)
133+
implementation(libs.androidx.compose.foundation.foundation)
134+
implementation(libs.androidx.compose.material3.material3)
135+
implementation(libs.androidx.compose.material.material.icons.extended)
136+
implementation(libs.androidx.compose.ui.ui.tooling.preview.android)
137+
debugImplementation(libs.androidx.compose.ui.ui.test.manifest)
138+
139+
androidTestImplementation(composeBom)
140+
androidTestImplementation(libs.androidx.compose.ui.ui.test.junit4)
141+
124142
// Third-party
125143
implementation(libs.com.journeyapps.zxing.android.embedded)
126144
implementation(libs.com.github.yalantis.ucrop)
@@ -140,6 +158,8 @@ dependencies {
140158
androidTestImplementation(libs.bundles.androidx.test)
141159
androidTestImplementation(libs.junit.junit)
142160
androidTestImplementation(libs.androidx.test.ext.junit)
161+
androidTestImplementation(libs.androidx.test.rules)
162+
androidTestImplementation(libs.androidx.test.runner)
143163
androidTestImplementation(libs.androidx.test.uiautomator.uiautomator)
144164
androidTestImplementation(libs.androidx.test.espresso.espresso.core)
145165
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package protect.card_locker
2+
3+
import android.app.Instrumentation
4+
import androidx.compose.ui.test.ExperimentalTestApi
5+
import androidx.compose.ui.test.assertIsDisplayed
6+
import androidx.compose.ui.test.assertIsNotDisplayed
7+
import androidx.compose.ui.test.junit4.ComposeContentTestRule
8+
import androidx.compose.ui.test.junit4.createComposeRule
9+
import androidx.compose.ui.test.onNodeWithTag
10+
import androidx.compose.ui.test.onNodeWithText
11+
import androidx.compose.ui.test.performScrollTo
12+
import androidx.compose.ui.test.runComposeUiTest
13+
import androidx.test.ext.junit.runners.AndroidJUnit4
14+
import androidx.test.platform.app.InstrumentationRegistry
15+
import org.junit.Rule
16+
import org.junit.Test
17+
import org.junit.runner.RunWith
18+
import protect.card_locker.compose.theme.CatimaTheme
19+
20+
@OptIn(ExperimentalTestApi::class)
21+
@RunWith(AndroidJUnit4::class)
22+
class AboutActivityTest {
23+
@get:Rule
24+
private val rule: ComposeContentTestRule = createComposeRule()
25+
26+
private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
27+
28+
private val content: AboutContent = AboutContent(instrumentation.targetContext)
29+
30+
@Test
31+
fun testInitialState(): Unit = runComposeUiTest {
32+
setContent {
33+
AboutScreenContent(content = content)
34+
}
35+
36+
onNodeWithTag("topbar_catima").assertIsDisplayed()
37+
38+
onNodeWithTag("card_version_history").assertIsDisplayed()
39+
onNodeWithText(content.versionHistory).assertIsDisplayed()
40+
41+
onNodeWithTag("card_credits").assertIsDisplayed()
42+
onNodeWithText(content.copyrightShort).assertIsDisplayed()
43+
44+
onNodeWithTag("card_translate").assertIsDisplayed()
45+
onNodeWithTag("card_license").assertIsDisplayed()
46+
47+
// We might be off the screen so start scrolling
48+
onNodeWithTag("card_source_github").performScrollTo().assertIsDisplayed()
49+
onNodeWithTag("card_privacy_policy").performScrollTo().assertIsDisplayed()
50+
onNodeWithTag("card_donate").performScrollTo().assertIsDisplayed()
51+
// Dont scroll to this, since its not displayed
52+
onNodeWithTag("card_rate_google").assertIsNotDisplayed()
53+
onNodeWithTag("card_report_error").performScrollTo().assertIsDisplayed()
54+
}
55+
56+
@Test
57+
fun testDonateAndGoogleCardVisible(): Unit = runComposeUiTest {
58+
setContent {
59+
CatimaTheme {
60+
AboutScreenContent(
61+
content = content,
62+
showDonate = true,
63+
showRateOnGooglePlay = true,
64+
)
65+
}
66+
}
67+
68+
onNodeWithTag("card_donate").performScrollTo().assertIsDisplayed()
69+
onNodeWithTag("card_rate_google").performScrollTo().assertIsDisplayed()
70+
}
71+
72+
@Test
73+
fun testDonateAndGoogleCardHidden(): Unit = runComposeUiTest {
74+
setContent {
75+
CatimaTheme {
76+
AboutScreenContent(
77+
content = content,
78+
showDonate = false,
79+
showRateOnGooglePlay = false,
80+
)
81+
}
82+
}
83+
84+
onNodeWithTag("card_privacy_policy").performScrollTo().assertIsDisplayed()
85+
onNodeWithTag("card_donate").assertIsNotDisplayed()
86+
onNodeWithTag("card_rate_google").assertIsNotDisplayed()
87+
onNodeWithTag("card_report_error").performScrollTo().assertIsDisplayed()
88+
}
89+
}

0 commit comments

Comments
 (0)