16
16
package io.getstream.feeds.android.client.internal.state
17
17
18
18
import io.getstream.feeds.android.client.api.model.FeedData
19
- import io.getstream.feeds.android.client.api.model.PaginationData
20
- import io.getstream.feeds.android.client.api.model.PaginationResult
21
19
import io.getstream.feeds.android.client.api.model.QueryConfiguration
22
20
import io.getstream.feeds.android.client.api.state.query.FeedsFilterField
23
21
import io.getstream.feeds.android.client.api.state.query.FeedsQuery
24
22
import io.getstream.feeds.android.client.api.state.query.FeedsSort
23
+ import io.getstream.feeds.android.client.internal.test.TestData.defaultPaginationResult
25
24
import io.getstream.feeds.android.client.internal.test.TestData.feedData
26
25
import kotlinx.coroutines.test.runTest
27
26
import org.junit.Assert.assertEquals
@@ -40,57 +39,72 @@ internal class FeedListStateImplTest {
40
39
41
40
@Test
42
41
fun `on queryMoreFeeds, then update feeds and pagination` () = runTest {
43
- val feeds = listOf (feedData(), feedData(" feed-2" , " user" , " Test Feed 2" ))
44
- val paginationResult =
45
- PaginationResult (
46
- models = feeds,
47
- pagination = PaginationData (next = " next-cursor" , previous = null ),
48
- )
49
- val queryConfig =
50
- QueryConfiguration <FeedsFilterField , FeedsSort >(filter = null , sort = FeedsSort .Default )
42
+ val feed1 = feedData(id = " feed-1" , groupId = " user" , name = " First Feed" )
43
+ val feed2 = feedData(id = " feed-2" , groupId = " user" , name = " Second Feed" )
44
+ val feeds = listOf (feed1, feed2)
45
+ val paginationResult = defaultPaginationResult(feeds)
51
46
52
- feedListState.onQueryMoreFeeds(paginationResult, queryConfig )
47
+ feedListState.onQueryMoreFeeds(paginationResult, defaultQueryConfig )
53
48
54
49
assertEquals(feeds, feedListState.feeds.value)
55
50
assertEquals(" next-cursor" , feedListState.pagination?.next)
56
- assertEquals(queryConfig , feedListState.queryConfig)
51
+ assertEquals(defaultQueryConfig , feedListState.queryConfig)
57
52
}
58
53
59
54
@Test
60
55
fun `on feedUpdated, then update specific feed` () = runTest {
61
- val initialFeeds = listOf (feedData(), feedData(" feed-2" , " user" , " Test Feed 2" ))
62
- val paginationResult =
63
- PaginationResult (
64
- models = initialFeeds,
65
- pagination = PaginationData (next = " next-cursor" , previous = null ),
66
- )
67
- val queryConfig =
68
- QueryConfiguration <FeedsFilterField , FeedsSort >(filter = null , sort = FeedsSort .Default )
69
- feedListState.onQueryMoreFeeds(paginationResult, queryConfig)
56
+ val feed1 = feedData(id = " feed-1" , groupId = " user" , name = " First Feed" )
57
+ val feed2 = feedData(id = " feed-2" , groupId = " user" , name = " Second Feed" )
58
+ val initialFeeds = listOf (feed1, feed2)
59
+ val paginationResult = defaultPaginationResult(initialFeeds)
60
+ feedListState.onQueryMoreFeeds(paginationResult, defaultQueryConfig)
70
61
71
62
val updatedFeed =
72
- feedData(" user-1" , " user" , " Updated Feed" , description = " Updated description" )
63
+ feedData(
64
+ id = " feed-1" ,
65
+ groupId = " user" ,
66
+ name = " Updated Feed" ,
67
+ description = " Updated description" ,
68
+ )
73
69
feedListState.onFeedUpdated(updatedFeed)
74
70
75
71
val updatedFeeds = feedListState.feeds.value
76
- assertEquals(listOf (updatedFeed, initialFeeds[ 1 ] ), updatedFeeds)
72
+ assertEquals(listOf (updatedFeed, feed2 ), updatedFeeds)
77
73
}
78
74
79
75
@Test
80
76
fun `on feedUpdated with non-existent feed, then keep existing feeds unchanged` () = runTest {
81
- val initialFeeds = listOf (feedData(), feedData(" feed-2" , " user" , " Test Feed 2" ))
82
- val paginationResult =
83
- PaginationResult (
84
- models = initialFeeds,
85
- pagination = PaginationData (next = " next-cursor" , previous = null ),
86
- )
77
+ val feed1 = feedData(id = " feed-1" , groupId = " user" , name = " First Feed" )
78
+ val feed2 = feedData(id = " feed-2" , groupId = " user" , name = " Second Feed" )
79
+ val initialFeeds = listOf (feed1, feed2)
80
+ val paginationResult = defaultPaginationResult(initialFeeds)
81
+ feedListState.onQueryMoreFeeds(paginationResult, defaultQueryConfig)
82
+
83
+ val nonExistentFeed =
84
+ feedData(id = " non-existent" , groupId = " user" , name = " Non-existent Feed" )
85
+ feedListState.onFeedUpdated(nonExistentFeed)
86
+
87
+ assertEquals(initialFeeds, feedListState.feeds.value)
88
+ }
89
+
90
+ @Test
91
+ fun `on feedRemoved, then remove specific feed` () = runTest {
92
+ val feed1 = feedData(id = " feed-1" , groupId = " user" , name = " First Feed" )
93
+ val feed2 = feedData(id = " feed-2" , groupId = " user" , name = " Second Feed" )
94
+ val initialFeeds = listOf (feed1, feed2)
95
+ val paginationResult = defaultPaginationResult(initialFeeds)
87
96
val queryConfig =
88
97
QueryConfiguration <FeedsFilterField , FeedsSort >(filter = null , sort = FeedsSort .Default )
89
98
feedListState.onQueryMoreFeeds(paginationResult, queryConfig)
90
99
91
- val nonExistentFeed = feedData(" non-existent" , " user" , " Non-existent Feed" )
92
- feedListState.onFeedUpdated(nonExistentFeed)
100
+ feedListState.onFeedRemoved(" user:feed-1" )
93
101
94
- assertEquals(initialFeeds, feedListState.feeds.value)
102
+ val remainingFeeds = feedListState.feeds.value
103
+ assertEquals(listOf (feed2), remainingFeeds)
104
+ }
105
+
106
+ companion object {
107
+ private val defaultQueryConfig =
108
+ QueryConfiguration <FeedsFilterField , FeedsSort >(filter = null , sort = FeedsSort .Default )
95
109
}
96
110
}
0 commit comments