@@ -31,16 +31,23 @@ import org.junit.Test
31
31
import org.matrix.android.sdk.api.session.events.model.Event
32
32
import org.matrix.android.sdk.api.session.events.model.EventType
33
33
import org.matrix.android.sdk.api.session.events.model.getPollQuestion
34
+ import org.matrix.android.sdk.api.session.events.model.getRelationContent
34
35
import org.matrix.android.sdk.api.session.events.model.isAudioMessage
35
36
import org.matrix.android.sdk.api.session.events.model.isFileMessage
36
37
import org.matrix.android.sdk.api.session.events.model.isImageMessage
37
38
import org.matrix.android.sdk.api.session.events.model.isLiveLocation
38
- import org.matrix.android.sdk.api.session.events.model.isPoll
39
+ import org.matrix.android.sdk.api.session.events.model.isPollEnd
40
+ import org.matrix.android.sdk.api.session.events.model.isPollStart
39
41
import org.matrix.android.sdk.api.session.events.model.isSticker
40
42
import org.matrix.android.sdk.api.session.events.model.isVideoMessage
41
43
import org.matrix.android.sdk.api.session.events.model.isVoiceMessage
44
+ import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent
45
+ import org.matrix.android.sdk.api.session.room.model.message.PollCreationInfo
46
+ import org.matrix.android.sdk.api.session.room.model.message.PollQuestion
47
+ import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultContent
42
48
import org.matrix.android.sdk.api.session.room.model.relation.ReplyToContent
43
49
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
50
+ import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent
44
51
45
52
private const val A_ROOM_ID = " room-id"
46
53
private const val AN_EVENT_ID = " event-id"
@@ -93,6 +100,7 @@ class ProcessBodyOfReplyToEventUseCaseTest {
93
100
fun setup () {
94
101
givenNewPrefix()
95
102
mockkStatic(" org.matrix.android.sdk.api.session.events.model.EventKt" )
103
+ mockkStatic(" org.matrix.android.sdk.api.session.room.timeline.TimelineEventKt" )
96
104
}
97
105
98
106
@After
@@ -104,7 +112,7 @@ class ProcessBodyOfReplyToEventUseCaseTest {
104
112
fun `given a replied event of type file message when process the formatted body then content is replaced by correct string` () {
105
113
// Given
106
114
givenTypeOfRepliedEvent(isFileMessage = true )
107
- givenNewContentForId (R .string.message_reply_to_sender_sent_file)
115
+ givenContentForId (R .string.message_reply_to_sender_sent_file, content = A_NEW_CONTENT )
108
116
109
117
executeAndAssertResult()
110
118
}
@@ -113,7 +121,7 @@ class ProcessBodyOfReplyToEventUseCaseTest {
113
121
fun `given a replied event of type voice message when process the formatted body then content is replaced by correct string` () {
114
122
// Given
115
123
givenTypeOfRepliedEvent(isVoiceMessage = true )
116
- givenNewContentForId (R .string.message_reply_to_sender_sent_voice_message)
124
+ givenContentForId (R .string.message_reply_to_sender_sent_voice_message, content = A_NEW_CONTENT )
117
125
118
126
executeAndAssertResult()
119
127
}
@@ -122,7 +130,7 @@ class ProcessBodyOfReplyToEventUseCaseTest {
122
130
fun `given a replied event of type audio message when process the formatted body then content is replaced by correct string` () {
123
131
// Given
124
132
givenTypeOfRepliedEvent(isAudioMessage = true )
125
- givenNewContentForId (R .string.message_reply_to_sender_sent_audio_file)
133
+ givenContentForId (R .string.message_reply_to_sender_sent_audio_file, content = A_NEW_CONTENT )
126
134
127
135
executeAndAssertResult()
128
136
}
@@ -131,7 +139,7 @@ class ProcessBodyOfReplyToEventUseCaseTest {
131
139
fun `given a replied event of type image message when process the formatted body then content is replaced by correct string` () {
132
140
// Given
133
141
givenTypeOfRepliedEvent(isImageMessage = true )
134
- givenNewContentForId (R .string.message_reply_to_sender_sent_image)
142
+ givenContentForId (R .string.message_reply_to_sender_sent_image, content = A_NEW_CONTENT )
135
143
136
144
executeAndAssertResult()
137
145
}
@@ -140,7 +148,7 @@ class ProcessBodyOfReplyToEventUseCaseTest {
140
148
fun `given a replied event of type video message when process the formatted body then content is replaced by correct string` () {
141
149
// Given
142
150
givenTypeOfRepliedEvent(isVideoMessage = true )
143
- givenNewContentForId (R .string.message_reply_to_sender_sent_video)
151
+ givenContentForId (R .string.message_reply_to_sender_sent_video, content = A_NEW_CONTENT )
144
152
145
153
executeAndAssertResult()
146
154
}
@@ -149,49 +157,58 @@ class ProcessBodyOfReplyToEventUseCaseTest {
149
157
fun `given a replied event of type sticker message when process the formatted body then content is replaced by correct string` () {
150
158
// Given
151
159
givenTypeOfRepliedEvent(isStickerMessage = true )
152
- givenNewContentForId (R .string.message_reply_to_sender_sent_sticker)
160
+ givenContentForId (R .string.message_reply_to_sender_sent_sticker, content = A_NEW_CONTENT )
153
161
154
162
executeAndAssertResult()
155
163
}
156
164
157
165
@Test
158
- fun `given a replied event of type poll message with null question when process the formatted body then content is replaced by correct string` () {
166
+ fun `given a replied event of type poll start message with null question when process the formatted body then content is replaced by correct string` () {
159
167
// Given
160
- givenTypeOfRepliedEvent(isPollMessage = true )
161
- givenNewContentForId(R .string.message_reply_to_sender_created_poll)
162
- every { fakeRepliedEvent.getClearType() } returns EventType .POLL_START .unstable
168
+ givenTypeOfRepliedEvent(isPollStartMessage = true )
169
+ givenContentForId(R .string.message_reply_to_sender_created_poll, content = A_NEW_CONTENT )
163
170
every { fakeRepliedEvent.getPollQuestion() } returns null
164
171
165
172
executeAndAssertResult()
166
173
}
167
174
168
175
@Test
169
- fun `given a replied event of type poll message with existing question when process the formatted body then content is replaced by correct string` () {
176
+ fun `given a replied event of type poll start message with existing question when process the formatted body then content is replaced by correct string` () {
170
177
// Given
171
- givenTypeOfRepliedEvent(isPollMessage = true )
172
- givenNewContentForId(R .string.message_reply_to_sender_created_poll)
173
- every { fakeRepliedEvent.getClearType() } returns EventType .POLL_START .unstable
178
+ givenTypeOfRepliedEvent(isPollStartMessage = true )
179
+ givenContentForId(R .string.message_reply_to_sender_created_poll, content = " " )
174
180
every { fakeRepliedEvent.getPollQuestion() } returns A_NEW_CONTENT
175
181
176
182
executeAndAssertResult()
177
183
}
178
184
179
185
@Test
180
- fun `given a replied event of type poll end message when process the formatted body then content is replaced by correct string` () {
186
+ fun `given a replied event of type poll end message with null question when process the formatted body then content is replaced by correct string` () {
181
187
// Given
182
- givenTypeOfRepliedEvent(isPollMessage = true )
183
- givenNewContentForId (R .string.message_reply_to_sender_ended_poll)
184
- every { fakeRepliedEvent.getClearType() } returns EventType . POLL_END .unstable
188
+ givenTypeOfRepliedEvent(isPollEndMessage = true )
189
+ givenContentForId (R .string.message_reply_to_sender_ended_poll, content = A_NEW_CONTENT )
190
+ givenPollQuestionReturns(fakeRepliedEvent, null )
185
191
every { fakeRepliedEvent.getPollQuestion() } returns null
186
192
187
193
executeAndAssertResult()
188
194
}
189
195
196
+ @Test
197
+ fun `given a replied event of type poll end message with existing question when process the formatted body then content is replaced by correct string` () {
198
+ // Given
199
+ givenTypeOfRepliedEvent(isPollEndMessage = true )
200
+ givenContentForId(R .string.message_reply_to_sender_ended_poll, content = " " )
201
+ every { fakeRepliedEvent.getClearType() } returns EventType .POLL_END .unstable
202
+ givenPollQuestionReturns(fakeRepliedEvent, A_NEW_CONTENT )
203
+
204
+ executeAndAssertResult()
205
+ }
206
+
190
207
@Test
191
208
fun `given a replied event of type live location message when process the formatted body then content is replaced by correct string` () {
192
209
// Given
193
210
givenTypeOfRepliedEvent(isLiveLocationMessage = true )
194
- givenNewContentForId (R .string.live_location_description)
211
+ givenContentForId (R .string.live_location_description, content = A_NEW_CONTENT )
195
212
196
213
executeAndAssertResult()
197
214
}
@@ -242,13 +259,16 @@ class ProcessBodyOfReplyToEventUseCaseTest {
242
259
243
260
private fun givenARepliedEvent (timelineEvent : TimelineEvent ? = mockk()): Event {
244
261
val event = mockk<Event >()
262
+ val eventId = " event-id"
263
+ every { event.eventId } returns eventId
264
+ every { event.roomId } returns A_ROOM_ID
245
265
timelineEvent?.let { every { it.root } returns event }
246
266
fakeActiveSessionHolder
247
267
.fakeSession
248
268
.roomService()
249
269
.getRoom(A_ROOM_ID )
250
270
.timelineService()
251
- .givenTimelineEvent( timelineEvent)
271
+ .givenTimelineEventReturns(eventId, timelineEvent)
252
272
return event
253
273
}
254
274
@@ -259,7 +279,8 @@ class ProcessBodyOfReplyToEventUseCaseTest {
259
279
isImageMessage : Boolean = false,
260
280
isVideoMessage : Boolean = false,
261
281
isStickerMessage : Boolean = false,
262
- isPollMessage : Boolean = false,
282
+ isPollEndMessage : Boolean = false,
283
+ isPollStartMessage : Boolean = false,
263
284
isLiveLocationMessage : Boolean = false,
264
285
) {
265
286
every { fakeRepliedEvent.isFileMessage() } returns isFileMessage
@@ -268,15 +289,36 @@ class ProcessBodyOfReplyToEventUseCaseTest {
268
289
every { fakeRepliedEvent.isImageMessage() } returns isImageMessage
269
290
every { fakeRepliedEvent.isVideoMessage() } returns isVideoMessage
270
291
every { fakeRepliedEvent.isSticker() } returns isStickerMessage
271
- every { fakeRepliedEvent.isPoll() } returns isPollMessage
292
+ every { fakeRepliedEvent.isPollEnd() } returns isPollEndMessage
293
+ every { fakeRepliedEvent.isPollStart() } returns isPollStartMessage
272
294
every { fakeRepliedEvent.isLiveLocation() } returns isLiveLocationMessage
273
295
}
274
296
275
297
private fun givenNewPrefix () {
276
298
fakeStringProvider.given(R .string.message_reply_to_prefix, A_NEW_PREFIX )
277
299
}
278
300
279
- private fun givenNewContentForId (@StringRes resId : Int ) {
280
- fakeStringProvider.given(resId, A_NEW_CONTENT )
301
+ private fun givenContentForId (@StringRes resId : Int , content : String ) {
302
+ fakeStringProvider.given(resId, content)
303
+ }
304
+
305
+ private fun givenPollQuestionReturns (pollEndEvent : Event , question : String? ) {
306
+ val eventId = " start-event-id"
307
+ val relationContent = mockk<RelationDefaultContent >()
308
+ every { relationContent.eventId } returns eventId
309
+ every { pollEndEvent.getRelationContent() } returns relationContent
310
+ val timelineEvent = mockk<TimelineEvent >()
311
+ val messagePollContent = MessagePollContent (
312
+ pollCreationInfo = PollCreationInfo (
313
+ question = PollQuestion (unstableQuestion = question)
314
+ )
315
+ )
316
+ every { timelineEvent.getLastMessageContent() } returns messagePollContent
317
+ fakeActiveSessionHolder
318
+ .fakeSession
319
+ .roomService()
320
+ .getRoom(A_ROOM_ID )
321
+ .timelineService()
322
+ .givenTimelineEventReturns(eventId, timelineEvent)
281
323
}
282
324
}
0 commit comments