Skip to content

Commit

Permalink
Improvements (#252)
Browse files Browse the repository at this point in the history
* Restore preview in CMP

* Fix todos in detekt config

* Add issue to todo

* Resolve Koin todos

* Resolve wear todos

* Fix bug with first month

* Update Compose UI tests with Kakao
  • Loading branch information
phansier authored Aug 2, 2024
1 parent e802a37 commit f39e275
Show file tree
Hide file tree
Showing 63 changed files with 481 additions and 384 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ cmp-iosApp/iosApp.xcodeproj/*
*.jks
*.jks.*
app/src/main/play
/gcm-diagnose.log
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ path := ./
params := --console=plain

detekt:
$(path)gradlew detektAll
$(path)gradlew detektAll $(params)

autodetekt:
$(path)gradlew detektAll --auto-correct --continue

buildApp:
./gradlew :app:assembleDebug
./gradlew :app:assembleDebug $(params)

buildWear:
./gradlew :wear:assemble
./gradlew :wear:assemble $(params)


buildAndroid:
./gradlew :cmp-app:assemble
./gradlew :cmp-app:assemble $(params)

testCommon:
./gradlew :cmp-common:testDebugUnitTest
./gradlew :cmp-common:testDebugUnitTest $(params)

localCheck: detekt buildApp buildWear buildAndroid testCommon $(params)
localCheck: detekt buildApp buildWear buildAndroid testCommon

compose_metrics:
$(path)gradlew :app:assembleRelease \-Pmyapp.enableComposeCompilerReports=true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.beryukhov.coffeegram.data

import androidx.annotation.VisibleForTesting

const val START_ACTIVITY_PATH = "/start-activity"
const val DAY_COFFEE_PATH = "/coffee"

@VisibleForTesting
fun Map<CoffeeType, Int>.withEmpty(): List<Pair<CoffeeType, Int>> {
@Suppress("DataClassShouldBeImmutable")
data class MutablePair(val ct: CoffeeType, var count: Int)

val emptyList: MutableList<MutablePair> =
CoffeeType.entries.map { MutablePair(it, 0) }.toMutableList()
this.forEach { entry: Map.Entry<CoffeeType, Int> ->
emptyList.filter { it.ct == entry.key }.forEach { it.count = entry.value }
}
return emptyList.map { it.ct to it.count }
}
6 changes: 3 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ dependencies {

testImplementation(libs.kotlin.test.junit)

androidTestImplementation(libs.compose.uiTest)
androidTestImplementation(libs.compose.uiTestJunit4)

implementation(projects.dateTimeUtils)

implementation(libs.coroutines.core)
Expand All @@ -128,6 +125,9 @@ dependencies {
implementation(libs.coroutines.play)

implementation(libs.lottie.compose)

androidTestImplementation(libs.compose.uiTestJunit4)
androidTestImplementation(libs.kakao.compose)
}

protobuf {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ru.beryukhov.coffeegram

import androidx.compose.ui.semantics.SemanticsNode
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.KNode
import io.github.kakaocup.compose.node.element.lazylist.KLazyListItemNode
import io.github.kakaocup.compose.node.element.lazylist.KLazyListNode
import ru.beryukhov.coffeegram.pages.LazyListItemPosition
import ru.beryukhov.coffeegram.pages.LazyListLengthSemantics

class CoffeeListScreen(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<CoffeeListScreen>(
semanticsProvider = semanticsProvider,
viewBuilderAction = {
hasTestTag("CoffeeListScreen")
}
) {
val coffeeList = KLazyListNode(
semanticsProvider = semanticsProvider,
viewBuilderAction = {
hasTestTag("CoffeeList")
},
itemTypeBuilder = {
itemType(::CoffeeItemNode)
},
positionMatcher = { position -> SemanticsMatcher.expectValue(LazyListItemPosition, position) },
lengthSemanticsPropertyKey = LazyListLengthSemantics
)
}

class CoffeeItemNode(
semanticsNode: SemanticsNode,
semanticsProvider: SemanticsNodeInteractionsProvider,
) : KLazyListItemNode<CoffeeItemNode>(semanticsNode, semanticsProvider) {
val title: KNode = child {
hasTestTag("CoffeeName")
}
}
27 changes: 27 additions & 0 deletions app/src/androidTest/java/ru/beryukhov/coffeegram/ComposeAppTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ru.beryukhov.coffeegram

import androidx.compose.ui.test.junit4.createAndroidComposeRule
import io.github.kakaocup.compose.node.element.ComposeScreen
import org.junit.Rule
import org.junit.Test

class ComposeAppTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()
@Test
fun testDayOpen() {
ComposeScreen.onComposeScreen<TableScreen>(composeTestRule) {
assertIsDisplayed()
day("1").apply {
assertIsDisplayed()
performClick()
}
}
ComposeScreen.onComposeScreen<CoffeeListScreen>(composeTestRule) {
assertIsDisplayed()
coffeeList.assertLengthEquals(42)
// CappuccinoItem.assertIsDisplayed()
// LatteItem.assertIsDisplayed()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ru.beryukhov.coffeegram

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import kotlinx.datetime.Month
import org.junit.Rule
import org.junit.Test
import ru.beryukhov.coffeegram.model.NavigationStore
import ru.beryukhov.date_time_utils.YearMonth
import ru.beryukhov.date_time_utils.nowYM

class ComposeScreenTest {
@get:Rule
val composeTestRule = createComposeRule()

@Test
fun testYear() {
withRule(yearMonth = YearMonth(2020, Month(1))) {
onNodeWithText("2020").assertIsDisplayed()
onComposeScreen<TableScreen>(composeTestRule) {
yearName.assertIsDisplayed()
monthName.assertIsDisplayed()
yearName.assertTextEquals("2020")
monthName.assertTextEquals("January")
}
}
}

@Test
fun testMonthChange() {
withRule(yearMonth = YearMonth(2020, Month(9))) {
onComposeScreen<TableScreen>(composeTestRule) {
monthName.assertTextEquals("September")
leftArrowButton {
assertIsDisplayed()
performClick()
}
monthName.assertTextEquals("August")
rightArrowButton {
assertIsDisplayed()
performClick()
}
monthName.assertTextEquals("September")
rightArrowButton {
assertIsDisplayed()
performClick()
}
monthName.assertTextEquals("October")
}
}
}

private inline fun <R> withRule(yearMonth: YearMonth = nowYM(), block: ComposeTestRule.() -> R): R =
with(composeTestRule) {
setContent {
PagesContent(
navigationStore = NavigationStore(yearMonth = yearMonth),
)
}
block()
}
}

This file was deleted.

38 changes: 0 additions & 38 deletions app/src/androidTest/java/ru/beryukhov/coffeegram/PageObject.kt

This file was deleted.

30 changes: 30 additions & 0 deletions app/src/androidTest/java/ru/beryukhov/coffeegram/TableScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ru.beryukhov.coffeegram

import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.KNode

class TableScreen(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<TableScreen>(
semanticsProvider = semanticsProvider,
viewBuilderAction = {
hasTestTag("TableScreen")
}
) {
val leftArrowButton = KNode(semanticsProvider) {
hasContentDescription("LeftArrow")
}
val rightArrowButton = KNode(semanticsProvider) {
hasTestTag("RightArrow")
}
val monthName = KNode(semanticsProvider) {
hasTestTag("Month")
}
val yearName = KNode(semanticsProvider) {
hasTestTag("Year")
}
fun day(number: String) = onNode {
hasTestTag("Day")
hasText(number)
}
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<!--TODO fix widgets-->
<!--TODO fix widgets https://github.com/phansier/Coffeegram/issues/135-->
<!-- <receiver-->
<!-- android:name=".widget.WidgetReceiver"-->
<!-- android:enabled="true"-->
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/java/ru/beryukhov/coffeegram/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.launch
import kotlinx.coroutines.tasks.await
import org.koin.androidx.compose.get
import ru.beryukhov.coffeegram.animations.TransitionSlot
import ru.beryukhov.coffeegram.data.CoffeeType
import ru.beryukhov.coffeegram.data.DAY_COFFEE_PATH
import ru.beryukhov.coffeegram.data.DayCoffee
import ru.beryukhov.coffeegram.data.START_ACTIVITY_PATH
import ru.beryukhov.coffeegram.data.toDataMap
import ru.beryukhov.coffeegram.pages.LandingPage

Expand Down Expand Up @@ -79,7 +80,8 @@ private fun MainActivity.startWearableActivity() {
// todo replace mock
DayCoffee(
mapOf(
CoffeeType.Cappuccino to 1, CoffeeType.Americano to 2
CoffeeType.Cappuccino to 1,
CoffeeType.Americano to 2
)
)
)
Expand Down Expand Up @@ -107,7 +109,4 @@ private fun MainActivity.checkCoarseLocationPermission(): Boolean = checkSelfPer
ACCESS_COARSE_LOCATION
) == PackageManager.PERMISSION_GRANTED

private const val START_ACTIVITY_PATH = "/start-activity"
private const val DAY_COFFEE_PATH = "/coffee"

private const val TAG = "TestWatch_"
Loading

0 comments on commit f39e275

Please sign in to comment.