Skip to content

Commit 738ac54

Browse files
committed
Extract createMatrixTimelineDiffProcessor from class.
1 parent e21c8d1 commit 738ac54

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/timeline/MatrixTimelineDiffProcessorTest.kt

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MatrixTimelineDiffProcessorTest {
3131
@Test
3232
fun `Append adds new entries at the end of the list`() = runTest {
3333
timelineItems.value = listOf(anEvent)
34-
val processor = createProcessor()
34+
val processor = createMatrixTimelineDiffProcessor(timelineItems)
3535
processor.postDiffs(listOf(FakeRustTimelineDiff(change = TimelineChange.APPEND)))
3636
assertThat(timelineItems.value.count()).isEqualTo(2)
3737
assertThat(timelineItems.value).containsExactly(
@@ -43,7 +43,7 @@ class MatrixTimelineDiffProcessorTest {
4343
@Test
4444
fun `PushBack adds a new entry at the end of the list`() = runTest {
4545
timelineItems.value = listOf(anEvent)
46-
val processor = createProcessor()
46+
val processor = createMatrixTimelineDiffProcessor(timelineItems)
4747
processor.postDiffs(listOf(FakeRustTimelineDiff(change = TimelineChange.PUSH_BACK)))
4848
assertThat(timelineItems.value.count()).isEqualTo(2)
4949
assertThat(timelineItems.value).containsExactly(
@@ -55,7 +55,7 @@ class MatrixTimelineDiffProcessorTest {
5555
@Test
5656
fun `PushFront inserts a new entry at the start of the list`() = runTest {
5757
timelineItems.value = listOf(anEvent)
58-
val processor = createProcessor()
58+
val processor = createMatrixTimelineDiffProcessor(timelineItems)
5959
processor.postDiffs(listOf(FakeRustTimelineDiff(change = TimelineChange.PUSH_FRONT)))
6060
assertThat(timelineItems.value.count()).isEqualTo(2)
6161
assertThat(timelineItems.value).containsExactly(
@@ -67,7 +67,7 @@ class MatrixTimelineDiffProcessorTest {
6767
@Test
6868
fun `Set replaces an entry at some index`() = runTest {
6969
timelineItems.value = listOf(anEvent, anEvent2)
70-
val processor = createProcessor()
70+
val processor = createMatrixTimelineDiffProcessor(timelineItems)
7171
processor.postDiffs(listOf(FakeRustTimelineDiff(change = TimelineChange.SET)))
7272
assertThat(timelineItems.value.count()).isEqualTo(2)
7373
assertThat(timelineItems.value).containsExactly(
@@ -79,7 +79,7 @@ class MatrixTimelineDiffProcessorTest {
7979
@Test
8080
fun `Insert inserts a new entry at the provided index`() = runTest {
8181
timelineItems.value = listOf(anEvent, anEvent2)
82-
val processor = createProcessor()
82+
val processor = createMatrixTimelineDiffProcessor(timelineItems)
8383
processor.postDiffs(listOf(FakeRustTimelineDiff(change = TimelineChange.INSERT)))
8484
assertThat(timelineItems.value.count()).isEqualTo(3)
8585
assertThat(timelineItems.value).containsExactly(
@@ -92,7 +92,7 @@ class MatrixTimelineDiffProcessorTest {
9292
@Test
9393
fun `Remove removes an entry at some index`() = runTest {
9494
timelineItems.value = listOf(anEvent, MatrixTimelineItem.Other, anEvent2)
95-
val processor = createProcessor()
95+
val processor = createMatrixTimelineDiffProcessor(timelineItems)
9696
processor.postDiffs(listOf(FakeRustTimelineDiff(change = TimelineChange.REMOVE)))
9797
assertThat(timelineItems.value.count()).isEqualTo(2)
9898
assertThat(timelineItems.value).containsExactly(
@@ -104,7 +104,7 @@ class MatrixTimelineDiffProcessorTest {
104104
@Test
105105
fun `PopBack removes an entry at the end of the list`() = runTest {
106106
timelineItems.value = listOf(anEvent, anEvent2)
107-
val processor = createProcessor()
107+
val processor = createMatrixTimelineDiffProcessor(timelineItems)
108108
processor.postDiffs(listOf(FakeRustTimelineDiff(change = TimelineChange.POP_BACK)))
109109
assertThat(timelineItems.value.count()).isEqualTo(1)
110110
assertThat(timelineItems.value).containsExactly(
@@ -115,7 +115,7 @@ class MatrixTimelineDiffProcessorTest {
115115
@Test
116116
fun `PopFront removes an entry at the start of the list`() = runTest {
117117
timelineItems.value = listOf(anEvent, anEvent2)
118-
val processor = createProcessor()
118+
val processor = createMatrixTimelineDiffProcessor(timelineItems)
119119
processor.postDiffs(listOf(FakeRustTimelineDiff(change = TimelineChange.POP_FRONT)))
120120
assertThat(timelineItems.value.count()).isEqualTo(1)
121121
assertThat(timelineItems.value).containsExactly(
@@ -126,15 +126,15 @@ class MatrixTimelineDiffProcessorTest {
126126
@Test
127127
fun `Clear removes all the entries`() = runTest {
128128
timelineItems.value = listOf(anEvent, anEvent2)
129-
val processor = createProcessor()
129+
val processor = createMatrixTimelineDiffProcessor(timelineItems)
130130
processor.postDiffs(listOf(FakeRustTimelineDiff(change = TimelineChange.CLEAR)))
131131
assertThat(timelineItems.value).isEmpty()
132132
}
133133

134134
@Test
135135
fun `Truncate removes all entries after the provided length`() = runTest {
136136
timelineItems.value = listOf(anEvent, MatrixTimelineItem.Other, anEvent2)
137-
val processor = createProcessor()
137+
val processor = createMatrixTimelineDiffProcessor(timelineItems)
138138
processor.postDiffs(listOf(FakeRustTimelineDiff(change = TimelineChange.TRUNCATE)))
139139
assertThat(timelineItems.value.count()).isEqualTo(1)
140140
assertThat(timelineItems.value).containsExactly(
@@ -145,27 +145,29 @@ class MatrixTimelineDiffProcessorTest {
145145
@Test
146146
fun `Reset removes all entries and add the provided ones`() = runTest {
147147
timelineItems.value = listOf(anEvent, MatrixTimelineItem.Other, anEvent2)
148-
val processor = createProcessor()
148+
val processor = createMatrixTimelineDiffProcessor(timelineItems)
149149
processor.postDiffs(listOf(FakeRustTimelineDiff(change = TimelineChange.RESET)))
150150
assertThat(timelineItems.value.count()).isEqualTo(1)
151151
assertThat(timelineItems.value).containsExactly(
152152
MatrixTimelineItem.Other,
153153
)
154154
}
155+
}
155156

156-
private fun TestScope.createProcessor(): MatrixTimelineDiffProcessor {
157-
val timelineEventContentMapper = TimelineEventContentMapper()
158-
val timelineItemMapper = MatrixTimelineItemMapper(
159-
fetchDetailsForEvent = { _ -> Result.success(Unit) },
160-
coroutineScope = this,
161-
virtualTimelineItemMapper = VirtualTimelineItemMapper(),
162-
eventTimelineItemMapper = EventTimelineItemMapper(
163-
contentMapper = timelineEventContentMapper
164-
)
165-
)
166-
return MatrixTimelineDiffProcessor(
167-
timelineItems,
168-
timelineItemFactory = timelineItemMapper,
157+
internal fun TestScope.createMatrixTimelineDiffProcessor(
158+
timelineItems: MutableStateFlow<List<MatrixTimelineItem>>,
159+
): MatrixTimelineDiffProcessor {
160+
val timelineEventContentMapper = TimelineEventContentMapper()
161+
val timelineItemMapper = MatrixTimelineItemMapper(
162+
fetchDetailsForEvent = { _ -> Result.success(Unit) },
163+
coroutineScope = this,
164+
virtualTimelineItemMapper = VirtualTimelineItemMapper(),
165+
eventTimelineItemMapper = EventTimelineItemMapper(
166+
contentMapper = timelineEventContentMapper
169167
)
170-
}
168+
)
169+
return MatrixTimelineDiffProcessor(
170+
timelineItems = timelineItems,
171+
timelineItemFactory = timelineItemMapper,
172+
)
171173
}

0 commit comments

Comments
 (0)