Skip to content

Commit bbefad3

Browse files
committed
test: reuse the internal EventFactory of the TestTimeline in more places
Also rename a few `factory` to `f`, for consistency with the rest of the testing code.
1 parent b00f58a commit bbefad3

File tree

11 files changed

+45
-52
lines changed

11 files changed

+45
-52
lines changed

crates/matrix-sdk-ui/src/timeline/tests/basic.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use assert_matches::assert_matches;
1616
use assert_matches2::assert_let;
1717
use eyeball_im::VectorDiff;
18-
use matrix_sdk::test_utils::events::EventFactory;
1918
use matrix_sdk_test::{async_test, sync_timeline_event, ALICE, BOB, CAROL};
2019
use ruma::{
2120
events::{
@@ -45,7 +44,7 @@ async fn test_initial_events() {
4544
let timeline = TestTimeline::new();
4645
let mut stream = timeline.subscribe().await;
4746

48-
let f = EventFactory::new();
47+
let f = &timeline.factory;
4948
timeline
5049
.inner
5150
.add_events_at(
@@ -87,8 +86,8 @@ async fn test_replace_with_initial_events_and_read_marker() {
8786
)
8887
.with_settings(TimelineInnerSettings { track_read_receipts: true, ..Default::default() });
8988

90-
let factory = EventFactory::new();
91-
let ev = factory.text_msg("hey").sender(*ALICE).into_sync();
89+
let f = &timeline.factory;
90+
let ev = f.text_msg("hey").sender(*ALICE).into_sync();
9291

9392
timeline.inner.add_events_at(vec![ev], TimelineEnd::Back, RemoteEventOrigin::Sync).await;
9493

@@ -97,7 +96,7 @@ async fn test_replace_with_initial_events_and_read_marker() {
9796
assert!(items[0].is_day_divider());
9897
assert_eq!(items[1].as_event().unwrap().content().as_message().unwrap().body(), "hey");
9998

100-
let ev = factory.text_msg("yo").sender(*BOB).into_sync();
99+
let ev = f.text_msg("yo").sender(*BOB).into_sync();
101100
timeline.inner.replace_with_initial_remote_events(vec![ev], RemoteEventOrigin::Sync).await;
102101

103102
let items = timeline.inner.items().await;
@@ -298,10 +297,10 @@ async fn test_dedup_pagination() {
298297
async fn test_dedup_initial() {
299298
let timeline = TestTimeline::new();
300299

301-
let factory = EventFactory::new();
302-
let event_a = factory.text_msg("A").sender(*ALICE).into_sync();
303-
let event_b = factory.text_msg("B").sender(*BOB).into_sync();
304-
let event_c = factory.text_msg("C").sender(*CAROL).into_sync();
300+
let f = &timeline.factory;
301+
let event_a = f.text_msg("A").sender(*ALICE).into_sync();
302+
let event_b = f.text_msg("B").sender(*BOB).into_sync();
303+
let event_c = f.text_msg("C").sender(*CAROL).into_sync();
305304

306305
timeline
307306
.inner
@@ -346,10 +345,10 @@ async fn test_dedup_initial() {
346345
async fn test_internal_id_prefix() {
347346
let timeline = TestTimeline::with_internal_id_prefix("le_prefix_".to_owned());
348347

349-
let factory = EventFactory::new();
350-
let ev_a = factory.text_msg("A").sender(*ALICE).into_sync();
351-
let ev_b = factory.text_msg("B").sender(*BOB).into_sync();
352-
let ev_c = factory.text_msg("C").sender(*CAROL).into_sync();
348+
let f = &timeline.factory;
349+
let ev_a = f.text_msg("A").sender(*ALICE).into_sync();
350+
let ev_b = f.text_msg("B").sender(*BOB).into_sync();
351+
let ev_c = f.text_msg("C").sender(*CAROL).into_sync();
353352

354353
timeline
355354
.inner
@@ -380,7 +379,7 @@ async fn test_sanitized() {
380379
let timeline = TestTimeline::new();
381380
let mut stream = timeline.subscribe().await;
382381

383-
let f = EventFactory::new();
382+
let f = &timeline.factory;
384383

385384
timeline
386385
.handle_live_event(
@@ -424,7 +423,7 @@ async fn test_reply() {
424423
let timeline = TestTimeline::new();
425424
let mut stream = timeline.subscribe().await;
426425

427-
let f = EventFactory::new();
426+
let f = &timeline.factory;
428427
timeline.handle_live_event(f.text_msg("I want you to reply").sender(&ALICE)).await;
429428

430429
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
@@ -476,7 +475,7 @@ async fn test_thread() {
476475
let timeline = TestTimeline::new();
477476
let mut stream = timeline.subscribe().await;
478477

479-
let f = EventFactory::new();
478+
let f = &timeline.factory;
480479
timeline.handle_live_event(f.text_msg("I want you to reply").sender(&ALICE)).await;
481480

482481
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);

crates/matrix-sdk-ui/src/timeline/tests/echo.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async fn test_remote_echo_full_trip() {
131131
async fn test_remote_echo_new_position() {
132132
let timeline = TestTimeline::new();
133133
let mut stream = timeline.subscribe().await;
134-
let f = EventFactory::new();
134+
let f = &timeline.factory;
135135

136136
// Given a local event…
137137
let txn_id = timeline
@@ -234,7 +234,7 @@ async fn test_day_divider_duplication() {
234234
async fn test_day_divider_removed_after_local_echo_disappeared() {
235235
let timeline = TestTimeline::new();
236236

237-
let f = EventFactory::new();
237+
let f = &timeline.factory;
238238

239239
timeline
240240
.handle_live_event(
@@ -282,15 +282,15 @@ async fn test_day_divider_removed_after_local_echo_disappeared() {
282282

283283
#[async_test]
284284
async fn test_read_marker_removed_after_local_echo_disappeared() {
285-
let f = EventFactory::new();
286-
287285
let event_id = event_id!("$1");
288286

289287
let timeline = TestTimeline::with_room_data_provider(
290288
TestRoomDataProvider::default().with_fully_read_marker(event_id.to_owned()),
291289
)
292290
.with_settings(TimelineInnerSettings { track_read_receipts: true, ..Default::default() });
293291

292+
let f = &timeline.factory;
293+
294294
// Use `replace_with_initial_remote_events` which initializes the read marker;
295295
// other methods don't, by default.
296296
timeline

crates/matrix-sdk-ui/src/timeline/tests/edit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
use assert_matches2::assert_let;
1616
use eyeball_im::VectorDiff;
17-
use matrix_sdk::test_utils::events::EventFactory;
1817
use matrix_sdk_test::{async_test, sync_timeline_event, ALICE};
1918
use ruma::{
2019
events::room::message::{MessageType, RedactedRoomMessageEventContent},
@@ -30,7 +29,8 @@ async fn test_live_redacted() {
3029
let timeline = TestTimeline::new();
3130
let mut stream = timeline.subscribe().await;
3231

33-
let f = EventFactory::new();
32+
let f = &timeline.factory;
33+
3434
timeline
3535
.handle_live_redacted_message_event(*ALICE, RedactedRoomMessageEventContent::new())
3636
.await;
@@ -57,7 +57,7 @@ async fn test_live_sanitized() {
5757
let timeline = TestTimeline::new();
5858
let mut stream = timeline.subscribe().await;
5959

60-
let f = EventFactory::new();
60+
let f = &timeline.factory;
6161
timeline
6262
.handle_live_event(
6363
f.text_html("**original** message", "<strong>original</strong> message").sender(&ALICE),

crates/matrix-sdk-ui/src/timeline/tests/encryption.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use assert_matches2::assert_let;
2525
use eyeball_im::VectorDiff;
2626
use matrix_sdk::{
2727
crypto::{decrypt_room_key_export, types::events::UtdCause, OlmMachine},
28-
test_utils::{events::EventFactory, test_client_builder},
28+
test_utils::test_client_builder,
2929
};
3030
use matrix_sdk_test::{async_test, BOB};
3131
use ruma::{
@@ -85,7 +85,7 @@ async fn test_retry_message_decryption() {
8585
let timeline = TestTimeline::with_unable_to_decrypt_hook(utd_hook.clone());
8686
let mut stream = timeline.subscribe().await;
8787

88-
let f = EventFactory::new();
88+
let f = &timeline.factory;
8989
timeline
9090
.handle_live_event(
9191
f.event(RoomEncryptedEventContent::new(
@@ -200,7 +200,7 @@ async fn test_retry_edit_decryption() {
200200
-----END MEGOLM SESSION DATA-----";
201201

202202
let timeline = TestTimeline::new();
203-
let f = EventFactory::new();
203+
let f = &timeline.factory;
204204

205205
let encrypted = EncryptedEventScheme::MegolmV1AesSha2(
206206
MegolmV1AesSha2ContentInit {
@@ -313,7 +313,7 @@ async fn test_retry_edit_and_more() {
313313
}
314314

315315
let timeline = TestTimeline::new();
316-
let f = EventFactory::new();
316+
let f = &timeline.factory;
317317

318318
timeline
319319
.handle_live_event(
@@ -401,7 +401,7 @@ async fn test_retry_message_decryption_highlighted() {
401401
-----END MEGOLM SESSION DATA-----";
402402

403403
let timeline = TestTimeline::new();
404-
let f = EventFactory::new();
404+
let f = &timeline.factory;
405405
let mut stream = timeline.subscribe().await;
406406

407407
timeline

crates/matrix-sdk-ui/src/timeline/tests/event_filter.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use std::sync::Arc;
1717
use assert_matches::assert_matches;
1818
use assert_matches2::assert_let;
1919
use eyeball_im::VectorDiff;
20-
use matrix_sdk::test_utils::events::EventFactory;
2120
use matrix_sdk_test::{async_test, sync_timeline_event, ALICE, BOB};
2221
use ruma::events::{
2322
room::{
@@ -41,7 +40,7 @@ async fn test_default_filter() {
4140
let timeline = TestTimeline::new();
4241
let mut stream = timeline.subscribe().await;
4342

44-
let f = EventFactory::new();
43+
let f = &timeline.factory;
4544

4645
// Test edits work.
4746
timeline.handle_live_event(f.text_msg("The first message").sender(&ALICE)).await;
@@ -99,7 +98,7 @@ async fn test_filter_always_false() {
9998
..Default::default()
10099
});
101100

102-
let f = EventFactory::new();
101+
let f = &timeline.factory;
103102
timeline.handle_live_event(f.text_msg("The first message").sender(&ALICE)).await;
104103

105104
timeline
@@ -131,7 +130,7 @@ async fn test_custom_filter() {
131130
});
132131
let mut stream = timeline.subscribe().await;
133132

134-
let f = EventFactory::new();
133+
let f = &timeline.factory;
135134
timeline.handle_live_event(f.text_msg("The first message").sender(&ALICE)).await;
136135
let _item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
137136
let _day_divider = assert_next_matches!(stream, VectorDiff::PushFront { value } => value);
@@ -199,7 +198,7 @@ async fn test_event_type_filter_include_only_room_names() {
199198
event_filter: Arc::new(move |event, _| event_filter.filter(event)),
200199
..Default::default()
201200
});
202-
let f = EventFactory::new();
201+
let f = &timeline.factory;
203202

204203
// Add a non-encrypted message event
205204
timeline.handle_live_event(f.text_msg("The first message").sender(&ALICE)).await;
@@ -247,7 +246,7 @@ async fn test_event_type_filter_exclude_messages() {
247246
event_filter: Arc::new(move |event, _| event_filter.filter(event)),
248247
..Default::default()
249248
});
250-
let f = EventFactory::new();
249+
let f = &timeline.factory;
251250

252251
// Add a message event
253252
timeline.handle_live_event(f.text_msg("The first message").sender(&ALICE)).await;

crates/matrix-sdk-ui/src/timeline/tests/invalid.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
use assert_matches2::assert_let;
1616
use eyeball_im::VectorDiff;
17-
use matrix_sdk::test_utils::events::EventFactory;
1817
use matrix_sdk_test::{async_test, sync_timeline_event, ALICE, BOB};
1918
use ruma::{
2019
events::{room::message::MessageType, MessageLikeEventType, StateEventType},
@@ -30,7 +29,7 @@ async fn invalid_edit() {
3029
let timeline = TestTimeline::new();
3130
let mut stream = timeline.subscribe_events().await;
3231

33-
let f = EventFactory::new();
32+
let f = &timeline.factory;
3433
timeline.handle_live_event(f.text_msg("test").sender(&ALICE)).await;
3534
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
3635
let msg = item.content().as_message().unwrap();

crates/matrix-sdk-ui/src/timeline/tests/polls.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ impl TestTimeline {
201201
}
202202

203203
async fn send_poll_start(&self, sender: &UserId, content: UnstablePollStartContentBlock) {
204-
// TODO: consider putting it in the `TestTimeline` itself?
205204
let event_content = AnyMessageLikeEventContent::UnstablePollStart(
206205
NewUnstablePollStartEventContent::new(content).into(),
207206
);

crates/matrix-sdk-ui/src/timeline/tests/reactions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ async fn test_add_reaction_success() {
9494

9595
#[async_test]
9696
async fn test_redact_reaction_success() {
97-
let f = EventFactory::new();
98-
9997
let timeline = TestTimeline::new();
98+
let f = &timeline.factory;
99+
100100
let mut stream = timeline.subscribe().await;
101101
let (msg_id, msg_pos) = send_first_message(&timeline, &mut stream).await;
102102
let reaction = create_reaction(&msg_id);
@@ -127,7 +127,7 @@ async fn test_redact_reaction_failure() {
127127
let mut stream = timeline.subscribe().await;
128128
let (msg_id, msg_pos) = send_first_message(&timeline, &mut stream).await;
129129

130-
let f = EventFactory::new();
130+
let f = &timeline.factory;
131131

132132
let event_id = event_id!("$1");
133133
timeline

crates/matrix-sdk-ui/src/timeline/tests/redaction.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use assert_matches::assert_matches;
1616
use assert_matches2::assert_let;
1717
use eyeball_im::VectorDiff;
18-
use matrix_sdk::test_utils::events::EventFactory;
1918
use matrix_sdk_base::deserialized_responses::SyncTimelineEvent;
2019
use matrix_sdk_test::{async_test, ALICE, BOB};
2120
use ruma::events::{
@@ -39,7 +38,7 @@ async fn test_redact_state_event() {
3938
let timeline = TestTimeline::new();
4039
let mut stream = timeline.subscribe_events().await;
4140

42-
let f = EventFactory::new();
41+
let f = &timeline.factory;
4342

4443
timeline
4544
.handle_live_state_event(
@@ -71,7 +70,7 @@ async fn test_redact_replied_to_event() {
7170
let timeline = TestTimeline::new();
7271
let mut stream = timeline.subscribe_events().await;
7372

74-
let f = EventFactory::new();
73+
let f = &timeline.factory;
7574

7675
timeline.handle_live_event(f.text_msg("Hello, world!").sender(&ALICE)).await;
7776

@@ -110,7 +109,7 @@ async fn test_reaction_redaction() {
110109
let timeline = TestTimeline::new();
111110
let mut stream = timeline.subscribe_events().await;
112111

113-
let f = EventFactory::new();
112+
let f = &timeline.factory;
114113

115114
timeline.handle_live_event(f.text_msg("hi!").sender(&ALICE)).await;
116115
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
@@ -136,7 +135,7 @@ async fn test_reaction_redaction_timeline_filter() {
136135
let timeline = TestTimeline::new();
137136
let mut stream = timeline.subscribe_events().await;
138137

139-
let f = EventFactory::new();
138+
let f = &timeline.factory;
140139

141140
// Initialise a timeline with a redacted reaction.
142141
timeline
@@ -183,7 +182,7 @@ async fn test_reaction_redaction_timeline_filter() {
183182
async fn test_receive_unredacted() {
184183
let timeline = TestTimeline::new();
185184

186-
let f = EventFactory::new();
185+
let f = &timeline.factory;
187186

188187
// send two events, second one redacted
189188
timeline.handle_live_event(f.text_msg("about to be redacted").sender(&ALICE)).await;

crates/matrix-sdk-ui/src/timeline/tests/shields.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use assert_matches::assert_matches;
22
use eyeball_im::VectorDiff;
3-
use matrix_sdk::test_utils::events::EventFactory;
43
use matrix_sdk_base::deserialized_responses::{ShieldState, ShieldStateCode};
54
use matrix_sdk_test::{async_test, sync_timeline_event, ALICE};
65
use ruma::{
@@ -15,7 +14,7 @@ use crate::timeline::{tests::TestTimeline, EventSendState};
1514
async fn test_no_shield_in_unencrypted_room() {
1615
let timeline = TestTimeline::new();
1716
let mut stream = timeline.subscribe().await;
18-
let f = EventFactory::new();
17+
let f = &timeline.factory;
1918

2019
timeline.handle_live_event(f.text_msg("Unencrypted message.").sender(&ALICE)).await;
2120

@@ -29,7 +28,7 @@ async fn test_sent_in_clear_shield() {
2928
let timeline = TestTimeline::with_is_room_encrypted(true);
3029
let mut stream = timeline.subscribe().await;
3130

32-
let f = EventFactory::new();
31+
let f = &timeline.factory;
3332
timeline.handle_live_event(f.text_msg("Unencrypted message.").sender(&ALICE)).await;
3433

3534
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);

0 commit comments

Comments
 (0)