Skip to content

Commit 9d54124

Browse files
committed
message test [nfc]: Move UpdateMessageEvent edit tests from msglist tests
1 parent 62fb55a commit 9d54124

File tree

2 files changed

+83
-82
lines changed

2 files changed

+83
-82
lines changed

test/model/message_list_test.dart

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -306,88 +306,6 @@ void main() {
306306
});
307307
});
308308

309-
group('UpdateMessageEvent', () {
310-
test('update a message', () async {
311-
final originalMessage = eg.streamMessage(
312-
content: "<p>Hello, world</p>");
313-
final updateEvent = eg.updateMessageEditEvent(originalMessage,
314-
flags: [MessageFlag.starred],
315-
renderedContent: "<p>Hello, edited</p>",
316-
editTimestamp: 99999,
317-
isMeMessage: true,
318-
);
319-
await prepare();
320-
await prepareMessages(foundOldest: true, messages: [originalMessage]);
321-
322-
final message = model.messages.single;
323-
check(message)
324-
..content.not((it) => it.equals(updateEvent.renderedContent!))
325-
..lastEditTimestamp.isNull()
326-
..flags.not((it) => it.deepEquals(updateEvent.flags))
327-
..isMeMessage.not((it) => it.equals(updateEvent.isMeMessage!));
328-
329-
await store.handleEvent(updateEvent);
330-
checkNotifiedOnce();
331-
check(model).messages.single
332-
..identicalTo(message)
333-
..content.equals(updateEvent.renderedContent!)
334-
..lastEditTimestamp.equals(updateEvent.editTimestamp)
335-
..flags.equals(updateEvent.flags)
336-
..isMeMessage.equals(updateEvent.isMeMessage!);
337-
});
338-
339-
test('ignore when message not present', () async {
340-
final originalMessage = eg.streamMessage(
341-
content: "<p>Hello, world</p>");
342-
final updateEvent = eg.updateMessageEditEvent(originalMessage,
343-
messageId: originalMessage.id + 1,
344-
renderedContent: "<p>Hello, edited</p>",
345-
);
346-
await prepare();
347-
await prepareMessages(foundOldest: true, messages: [originalMessage]);
348-
349-
await store.handleEvent(updateEvent);
350-
checkNotNotified();
351-
check(model).messages.single
352-
..content.equals(originalMessage.content)
353-
..content.not((it) => it.equals(updateEvent.renderedContent!));
354-
});
355-
356-
// TODO(server-5): Cut legacy case for rendering-only message update
357-
Future<void> checkRenderingOnly({required bool legacy}) async {
358-
final originalMessage = eg.streamMessage(
359-
lastEditTimestamp: 78492,
360-
content: "<p>Hello, world</p>");
361-
final updateEvent = eg.updateMessageEditEvent(originalMessage,
362-
renderedContent: "<p>Hello, world</p> <div>Some link preview</div>",
363-
editTimestamp: 99999,
364-
renderingOnly: legacy ? null : true,
365-
userId: null,
366-
);
367-
await prepare();
368-
await prepareMessages(foundOldest: true, messages: [originalMessage]);
369-
final message = model.messages.single;
370-
371-
await store.handleEvent(updateEvent);
372-
checkNotifiedOnce();
373-
check(model).messages.single
374-
..identicalTo(message)
375-
// Content is updated...
376-
..content.equals(updateEvent.renderedContent!)
377-
// ... edit timestamp is not.
378-
..lastEditTimestamp.equals(originalMessage.lastEditTimestamp)
379-
..lastEditTimestamp.not((it) => it.equals(updateEvent.editTimestamp));
380-
}
381-
382-
test('rendering-only update does not change timestamp', () async {
383-
await checkRenderingOnly(legacy: false);
384-
});
385-
386-
test('rendering-only update does not change timestamp (for old server versions)', () async {
387-
await checkRenderingOnly(legacy: true);
388-
});
389-
});
390-
391309
group('maybeUpdateMessageFlags', () {
392310
UpdateMessageFlagsAddEvent mkAddEvent(
393311
MessageFlag flag,

test/model/message_test.dart

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import '../api/model/model_checks.dart';
1111
import '../example_data.dart' as eg;
1212
import '../stdlib_checks.dart';
1313
import 'message_list_test.dart';
14+
import 'store_checks.dart';
1415
import 'test_store.dart';
1516

1617
void main() {
@@ -160,6 +161,88 @@ void main() {
160161
});
161162
});
162163

164+
group('handleUpdateMessageEvent', () {
165+
test('update a message', () async {
166+
final originalMessage = eg.streamMessage(
167+
content: "<p>Hello, world</p>");
168+
final updateEvent = eg.updateMessageEditEvent(originalMessage,
169+
flags: [MessageFlag.starred],
170+
renderedContent: "<p>Hello, edited</p>",
171+
editTimestamp: 99999,
172+
isMeMessage: true,
173+
);
174+
await prepare();
175+
await prepareMessages([originalMessage]);
176+
177+
final message = store.messages.values.single;
178+
check(message)
179+
..content.not((it) => it.equals(updateEvent.renderedContent!))
180+
..lastEditTimestamp.isNull()
181+
..flags.not((it) => it.deepEquals(updateEvent.flags))
182+
..isMeMessage.not((it) => it.equals(updateEvent.isMeMessage!));
183+
184+
await store.handleEvent(updateEvent);
185+
checkNotifiedOnce();
186+
check(store).messages.values.single
187+
..identicalTo(message)
188+
..content.equals(updateEvent.renderedContent!)
189+
..lastEditTimestamp.equals(updateEvent.editTimestamp)
190+
..flags.equals(updateEvent.flags)
191+
..isMeMessage.equals(updateEvent.isMeMessage!);
192+
});
193+
194+
test('ignore when message unknown', () async {
195+
final originalMessage = eg.streamMessage(
196+
content: "<p>Hello, world</p>");
197+
final updateEvent = eg.updateMessageEditEvent(originalMessage,
198+
messageId: originalMessage.id + 1,
199+
renderedContent: "<p>Hello, edited</p>",
200+
);
201+
await prepare();
202+
await prepareMessages([originalMessage]);
203+
204+
await store.handleEvent(updateEvent);
205+
checkNotNotified();
206+
check(store).messages.values.single
207+
..content.equals(originalMessage.content)
208+
..content.not((it) => it.equals(updateEvent.renderedContent!));
209+
});
210+
211+
// TODO(server-5): Cut legacy case for rendering-only message update
212+
Future<void> checkRenderingOnly({required bool legacy}) async {
213+
final originalMessage = eg.streamMessage(
214+
lastEditTimestamp: 78492,
215+
content: "<p>Hello, world</p>");
216+
final updateEvent = eg.updateMessageEditEvent(originalMessage,
217+
renderedContent: "<p>Hello, world</p> <div>Some link preview</div>",
218+
editTimestamp: 99999,
219+
renderingOnly: legacy ? null : true,
220+
userId: null,
221+
);
222+
await prepare();
223+
await prepareMessages([originalMessage]);
224+
final message = store.messages.values.single;
225+
226+
await store.handleEvent(updateEvent);
227+
checkNotifiedOnce();
228+
check(store).messages.values.single
229+
..identicalTo(message)
230+
// Content is updated...
231+
..content.equals(updateEvent.renderedContent!)
232+
// ... edit timestamp is not.
233+
..lastEditTimestamp.equals(originalMessage.lastEditTimestamp)
234+
..lastEditTimestamp.not((it) => it.equals(updateEvent.editTimestamp));
235+
}
236+
237+
test('rendering-only update does not change timestamp', () async {
238+
await checkRenderingOnly(legacy: false);
239+
});
240+
241+
test('rendering-only update does not change timestamp (for old server versions)', () async {
242+
await checkRenderingOnly(legacy: true);
243+
});
244+
});
245+
163246
group('handleReactionEvent', () {
164247
test('add reaction', () async {
165248
final originalMessage = eg.streamMessage(reactions: []);

0 commit comments

Comments
 (0)