From 932f80a2815390198ae1095525545d3cee602d08 Mon Sep 17 00:00:00 2001 From: Mohsen Rzna Date: Sun, 20 Nov 2022 12:15:35 +0100 Subject: [PATCH 1/4] Added the test for empty state and refactor --- .../feature/bookmarks/BookmarksScreenTest.kt | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt b/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt index 1dafc5c98..81d99442c 100644 --- a/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt +++ b/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt @@ -17,7 +17,6 @@ package com.google.samples.apps.nowinandroid.feature.bookmarks import androidx.activity.ComponentActivity -import androidx.compose.material3.windowsizeclass.WindowSizeClass import androidx.compose.ui.test.assertCountEquals import androidx.compose.ui.test.assertHasClickAction import androidx.compose.ui.test.filter @@ -34,10 +33,11 @@ import androidx.compose.ui.test.performScrollToNode import com.google.samples.apps.nowinandroid.core.domain.model.SaveableNewsResource import com.google.samples.apps.nowinandroid.core.model.data.previewNewsResources import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState -import kotlin.test.assertEquals -import kotlin.test.assertTrue +import com.google.samples.apps.nowinandroid.core.ui.R.string import org.junit.Rule import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue /** * UI tests for [BookmarksScreen] composable. @@ -65,8 +65,6 @@ class BookmarksScreenTest { @Test fun feed_whenHasBookmarks_showsBookmarks() { - lateinit var windowSizeClass: WindowSizeClass - composeTestRule.setContent { BookmarksScreen( feedState = NewsFeedUiState.Success( @@ -120,11 +118,8 @@ class BookmarksScreenTest { } composeTestRule - .onAllNodesWithContentDescription( - composeTestRule.activity.getString( - com.google.samples.apps.nowinandroid.core.ui.R.string.unbookmark - ) - ).filter( + .onAllNodesWithContentDescription(composeTestRule.activity.getString(string.unbookmark)) + .filter( hasAnyAncestor( hasText( previewNewsResources[0].title, @@ -138,4 +133,26 @@ class BookmarksScreenTest { assertTrue(removeFromBookmarksCalled) } + + @Test + fun feed_whenHasNoBookmarks_showsEmptyState() { + composeTestRule.setContent { + BookmarksScreen( + feedState = NewsFeedUiState.Success(emptyList()), + removeFromBookmarks = { } + ) + } + + composeTestRule + .onNodeWithText( + composeTestRule.activity.getString(R.string.bookmarks_empty_error) + ) + .assertExists() + + composeTestRule + .onNodeWithText( + composeTestRule.activity.getString(R.string.bookmarks_empty_description) + ) + .assertExists() + } } From 40838f8138c569661fb1653d07b21094b2739770 Mon Sep 17 00:00:00 2001 From: Mohsen Rzna Date: Sun, 20 Nov 2022 12:28:35 +0100 Subject: [PATCH 2/4] Spotless apply --- .../feature/bookmarks/BookmarksScreenTest.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt b/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt index 81d99442c..ff033033a 100644 --- a/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt +++ b/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt @@ -33,11 +33,10 @@ import androidx.compose.ui.test.performScrollToNode import com.google.samples.apps.nowinandroid.core.domain.model.SaveableNewsResource import com.google.samples.apps.nowinandroid.core.model.data.previewNewsResources import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState -import com.google.samples.apps.nowinandroid.core.ui.R.string -import org.junit.Rule -import org.junit.Test import kotlin.test.assertEquals import kotlin.test.assertTrue +import org.junit.Rule +import org.junit.Test /** * UI tests for [BookmarksScreen] composable. @@ -118,8 +117,11 @@ class BookmarksScreenTest { } composeTestRule - .onAllNodesWithContentDescription(composeTestRule.activity.getString(string.unbookmark)) - .filter( + .onAllNodesWithContentDescription( + composeTestRule.activity.getString( + com.google.samples.apps.nowinandroid.core.ui.R.string.unbookmark + ) + ).filter( hasAnyAncestor( hasText( previewNewsResources[0].title, From d865c6421e44df18f8bbc90847547a5c0dd44655 Mon Sep 17 00:00:00 2001 From: Mohsen Rzna Date: Sun, 20 Nov 2022 15:10:04 +0100 Subject: [PATCH 3/4] Reverted the changes back for import --- .../nowinandroid/feature/bookmarks/BookmarksScreenTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt b/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt index ff033033a..4e47f06b1 100644 --- a/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt +++ b/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt @@ -33,10 +33,10 @@ import androidx.compose.ui.test.performScrollToNode import com.google.samples.apps.nowinandroid.core.domain.model.SaveableNewsResource import com.google.samples.apps.nowinandroid.core.model.data.previewNewsResources import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState -import kotlin.test.assertEquals -import kotlin.test.assertTrue import org.junit.Rule import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue /** * UI tests for [BookmarksScreen] composable. From 4ded548ba730d2053463c6a5fd03db48b90fa70e Mon Sep 17 00:00:00 2001 From: Mohsen Rzna Date: Sun, 20 Nov 2022 15:23:50 +0100 Subject: [PATCH 4/4] Spotless apply - new version --- .../nowinandroid/feature/bookmarks/BookmarksScreenTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt b/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt index 4e47f06b1..ff033033a 100644 --- a/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt +++ b/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt @@ -33,10 +33,10 @@ import androidx.compose.ui.test.performScrollToNode import com.google.samples.apps.nowinandroid.core.domain.model.SaveableNewsResource import com.google.samples.apps.nowinandroid.core.model.data.previewNewsResources import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState -import org.junit.Rule -import org.junit.Test import kotlin.test.assertEquals import kotlin.test.assertTrue +import org.junit.Rule +import org.junit.Test /** * UI tests for [BookmarksScreen] composable.