Skip to content

Commit dce75e3

Browse files
committed
test [nfc]: Extract TypingEvent example data.
This will be useful when we implement tests for the UI counterpart of the feature. Signed-off-by: Zixuan James Li <[email protected]>
1 parent f1c68fd commit dce75e3

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

test/example_data.dart

+16
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,22 @@ UpdateMessageFlagsRemoveEvent updateMessageFlagsRemoveEvent(
504504
})));
505505
}
506506

507+
TypingEvent typingEvent(SendableNarrow narrow, TypingOp op, int senderId) {
508+
switch (narrow) {
509+
case TopicNarrow():
510+
return TypingEvent(id: 1, op: op, senderId: senderId,
511+
messageType: MessageType.stream,
512+
streamId: narrow.streamId,
513+
topic: narrow.topic,
514+
recipientIds: null);
515+
case DmNarrow():
516+
return TypingEvent(id: 1, op: op, senderId: senderId,
517+
messageType: MessageType.private,
518+
recipientIds: narrow.allRecipientIds,
519+
streamId: null,
520+
topic: null);
521+
}
522+
}
507523

508524
ReactionEvent reactionEvent(Reaction reaction, ReactionOp op, int messageId) {
509525
return ReactionEvent(

test/model/typing_status_test.dart

+23-40
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,6 @@ void main() {
4242
notifiedCount = 0;
4343
}
4444

45-
TypingEvent mkTypingEvent(SendableNarrow narrow, TypingOp op, int senderId) {
46-
switch (narrow) {
47-
case TopicNarrow():
48-
return TypingEvent(id: 1, op: op, senderId: senderId,
49-
messageType: MessageType.stream,
50-
streamId: narrow.streamId,
51-
topic: narrow.topic,
52-
recipientIds: null);
53-
case DmNarrow():
54-
return TypingEvent(id: 1, op: op, senderId: senderId,
55-
messageType: MessageType.private,
56-
recipientIds: narrow.allRecipientIds,
57-
streamId: null,
58-
topic: null);
59-
}
60-
}
61-
6245
final stream = eg.stream();
6346
final topicNarrow = TopicNarrow(stream.streamId, 'foo');
6447

@@ -75,20 +58,20 @@ void main() {
7558
prepareModel();
7659

7760
model.handleTypingEvent(
78-
mkTypingEvent(dmNarrow, TypingOp.start, otherUser.userId));
61+
eg.typingEvent(dmNarrow, TypingOp.start, otherUser.userId));
7962
check(model).typistsByLocation.deepEquals(
8063
{dmNarrow: {otherUser.userId: anyTimer}});
8164
checkNotifiedOnce();
8265

8366
model.handleTypingEvent(
84-
mkTypingEvent(groupNarrow, TypingOp.start, thirdUser.userId));
67+
eg.typingEvent(groupNarrow, TypingOp.start, thirdUser.userId));
8568
check(model).typistsByLocation.deepEquals({
8669
dmNarrow: {otherUser.userId: anyTimer},
8770
groupNarrow: {thirdUser.userId: anyTimer}});
8871
checkNotifiedOnce();
8972

9073
model.handleTypingEvent(
91-
mkTypingEvent(topicNarrow, TypingOp.start, eg.selfUser.userId));
74+
eg.typingEvent(topicNarrow, TypingOp.start, eg.selfUser.userId));
9275
check(model).typistsByLocation.deepEquals({
9376
dmNarrow: {otherUser.userId: anyTimer},
9477
groupNarrow: {thirdUser.userId: anyTimer},
@@ -100,13 +83,13 @@ void main() {
10083
prepareModel();
10184

10285
model.handleTypingEvent(
103-
mkTypingEvent(groupNarrow, TypingOp.start, eg.selfUser.userId));
86+
eg.typingEvent(groupNarrow, TypingOp.start, eg.selfUser.userId));
10487
check(model).typistsByLocation.deepEquals({
10588
groupNarrow: {eg.selfUser.userId: anyTimer}});
10689
checkNotifiedOnce();
10790

10891
model.handleTypingEvent(
109-
mkTypingEvent(groupNarrow, TypingOp.start, thirdUser.userId));
92+
eg.typingEvent(groupNarrow, TypingOp.start, thirdUser.userId));
11093
check(model).typistsByLocation.deepEquals({
11194
groupNarrow: {eg.selfUser.userId: anyTimer, thirdUser.userId: anyTimer}});
11295
checkNotifiedOnce();
@@ -131,14 +114,14 @@ void main() {
131114
prepareModel();
132115

133116
model.handleTypingEvent(
134-
mkTypingEvent(groupNarrow, TypingOp.start, otherUser.userId));
117+
eg.typingEvent(groupNarrow, TypingOp.start, otherUser.userId));
135118
checkNotifiedOnce();
136119

137120
check(model).typistsByLocation.deepEquals({
138121
groupNarrow: {otherUser.userId: anyTimer}});
139122

140123
model.handleTypingEvent(
141-
mkTypingEvent(dmNarrow, TypingOp.stop, otherUser.userId));
124+
eg.typingEvent(dmNarrow, TypingOp.stop, otherUser.userId));
142125
check(model).typistsByLocation.deepEquals({
143126
groupNarrow: {otherUser.userId: anyTimer}});
144127
checkNotNotified();
@@ -148,17 +131,17 @@ void main() {
148131
prepareModel();
149132

150133
model.handleTypingEvent(
151-
mkTypingEvent(groupNarrow, TypingOp.start, otherUser.userId));
134+
eg.typingEvent(groupNarrow, TypingOp.start, otherUser.userId));
152135
checkNotifiedOnce();
153136
model.handleTypingEvent(
154-
mkTypingEvent(groupNarrow, TypingOp.start, eg.selfUser.userId));
137+
eg.typingEvent(groupNarrow, TypingOp.start, eg.selfUser.userId));
155138
checkNotifiedOnce();
156139

157140
check(model).typistsByLocation.deepEquals({
158141
groupNarrow: {otherUser.userId: anyTimer, eg.selfUser.userId: anyTimer}});
159142

160143
model.handleTypingEvent(
161-
mkTypingEvent(groupNarrow, TypingOp.stop, otherUser.userId));
144+
eg.typingEvent(groupNarrow, TypingOp.stop, otherUser.userId));
162145
check(model).typistsByLocation.deepEquals({
163146
groupNarrow: {eg.selfUser.userId: anyTimer}});
164147
checkNotifiedOnce();
@@ -168,13 +151,13 @@ void main() {
168151
prepareModel();
169152

170153
model.handleTypingEvent(
171-
mkTypingEvent(dmNarrow, TypingOp.start, otherUser.userId));
154+
eg.typingEvent(dmNarrow, TypingOp.start, otherUser.userId));
172155
checkNotifiedOnce();
173156
model.handleTypingEvent(
174-
mkTypingEvent(groupNarrow, TypingOp.start, thirdUser.userId));
157+
eg.typingEvent(groupNarrow, TypingOp.start, thirdUser.userId));
175158
checkNotifiedOnce();
176159
model.handleTypingEvent(
177-
mkTypingEvent(topicNarrow, TypingOp.start, eg.selfUser.userId));
160+
eg.typingEvent(topicNarrow, TypingOp.start, eg.selfUser.userId));
178161
checkNotifiedOnce();
179162

180163
async.elapse(const Duration(seconds: 5));
@@ -184,20 +167,20 @@ void main() {
184167
topicNarrow: {eg.selfUser.userId: anyTimer}});
185168

186169
model.handleTypingEvent(
187-
mkTypingEvent(groupNarrow, TypingOp.stop, thirdUser.userId));
170+
eg.typingEvent(groupNarrow, TypingOp.stop, thirdUser.userId));
188171
check(model).typistsByLocation.deepEquals({
189172
dmNarrow: {otherUser.userId: anyTimer},
190173
topicNarrow: {eg.selfUser.userId: anyTimer}});
191174
checkNotifiedOnce();
192175

193176
model.handleTypingEvent(
194-
mkTypingEvent(dmNarrow, TypingOp.stop, otherUser.userId));
177+
eg.typingEvent(dmNarrow, TypingOp.stop, otherUser.userId));
195178
check(model).typistsByLocation.deepEquals({
196179
topicNarrow: {eg.selfUser.userId: anyTimer}});
197180
checkNotifiedOnce();
198181

199182
model.handleTypingEvent(
200-
mkTypingEvent(topicNarrow, TypingOp.stop, eg.selfUser.userId));
183+
eg.typingEvent(topicNarrow, TypingOp.stop, eg.selfUser.userId));
201184
check(model).typistsByLocation.isEmpty();
202185
checkNotifiedOnce();
203186
}));
@@ -208,12 +191,12 @@ void main() {
208191
prepareModel();
209192

210193
model.handleTypingEvent(
211-
mkTypingEvent(dmNarrow, TypingOp.start, otherUser.userId));
194+
eg.typingEvent(dmNarrow, TypingOp.start, otherUser.userId));
212195
var oldTimer = check(model).typistsByLocation[dmNarrow][otherUser.userId]
213196
..isActive.isTrue();
214197
checkNotifiedOnce();
215198
model.handleTypingEvent(
216-
mkTypingEvent(dmNarrow, TypingOp.stop, otherUser.userId));
199+
eg.typingEvent(dmNarrow, TypingOp.stop, otherUser.userId));
217200
oldTimer.isActive.isFalse();
218201
checkNotifiedOnce();
219202
}));
@@ -222,12 +205,12 @@ void main() {
222205
prepareModel();
223206

224207
model.handleTypingEvent(
225-
mkTypingEvent(groupNarrow, TypingOp.start, otherUser.userId));
208+
eg.typingEvent(groupNarrow, TypingOp.start, otherUser.userId));
226209
var oldTimer = check(model).typistsByLocation[groupNarrow][otherUser.userId]
227210
..isActive.isTrue();
228211
checkNotifiedOnce();
229212
model.handleTypingEvent(
230-
mkTypingEvent(groupNarrow, TypingOp.start, otherUser.userId));
213+
eg.typingEvent(groupNarrow, TypingOp.start, otherUser.userId));
231214
oldTimer.isActive.isFalse();
232215
checkNotNotified();
233216
}));
@@ -238,7 +221,7 @@ void main() {
238221
prepareModel();
239222

240223
model.handleTypingEvent(
241-
mkTypingEvent(dmNarrow, TypingOp.start, otherUser.userId));
224+
eg.typingEvent(dmNarrow, TypingOp.start, otherUser.userId));
242225
checkNotifiedOnce();
243226

244227
async.elapse(const Duration(seconds: 10));
@@ -247,7 +230,7 @@ void main() {
247230
});
248231
// We expect the timer to restart from the event.
249232
model.handleTypingEvent(
250-
mkTypingEvent(dmNarrow, TypingOp.start, otherUser.userId));
233+
eg.typingEvent(dmNarrow, TypingOp.start, otherUser.userId));
251234
checkNotNotified();
252235

253236
async.elapse(const Duration(seconds: 10));
@@ -266,7 +249,7 @@ void main() {
266249
prepareModel();
267250

268251
model.handleTypingEvent(
269-
mkTypingEvent(dmNarrow, TypingOp.start, otherUser.userId));
252+
eg.typingEvent(dmNarrow, TypingOp.start, otherUser.userId));
270253
async.elapse(const Duration(seconds: 5));
271254
check(model).typistsByLocation.deepEquals({
272255
dmNarrow: {otherUser.userId: anyTimer}

0 commit comments

Comments
 (0)