Skip to content

Commit 1ffa4e7

Browse files
committed
msglist test: Make groups for fetchInitial and fetchOlder tests
1 parent dd4cdde commit 1ffa4e7

File tree

1 file changed

+166
-162
lines changed

1 file changed

+166
-162
lines changed

test/model/message_list_test.dart

Lines changed: 166 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -91,188 +91,192 @@ void main() {
9191
});
9292
}
9393

94-
test('fetchInitial', () async {
95-
const narrow = CombinedFeedNarrow();
96-
await prepare(narrow: narrow);
97-
connection.prepare(json: newestResult(
98-
foundOldest: false,
99-
messages: List.generate(kMessageListFetchBatchSize,
100-
(i) => eg.streamMessage()),
101-
).toJson());
102-
final fetchFuture = model.fetchInitial();
103-
check(model).fetched.isFalse();
94+
group('fetchInitial', () {
95+
test('smoke', () async {
96+
const narrow = CombinedFeedNarrow();
97+
await prepare(narrow: narrow);
98+
connection.prepare(json: newestResult(
99+
foundOldest: false,
100+
messages: List.generate(kMessageListFetchBatchSize,
101+
(i) => eg.streamMessage()),
102+
).toJson());
103+
final fetchFuture = model.fetchInitial();
104+
check(model).fetched.isFalse();
104105

105-
checkNotNotified();
106-
await fetchFuture;
107-
checkNotifiedOnce();
108-
check(model)
109-
..messages.length.equals(kMessageListFetchBatchSize)
110-
..haveOldest.isFalse();
111-
checkLastRequest(
112-
narrow: narrow.apiEncode(),
113-
anchor: 'newest',
114-
numBefore: kMessageListFetchBatchSize,
115-
numAfter: 0,
116-
);
117-
});
106+
checkNotNotified();
107+
await fetchFuture;
108+
checkNotifiedOnce();
109+
check(model)
110+
..messages.length.equals(kMessageListFetchBatchSize)
111+
..haveOldest.isFalse();
112+
checkLastRequest(
113+
narrow: narrow.apiEncode(),
114+
anchor: 'newest',
115+
numBefore: kMessageListFetchBatchSize,
116+
numAfter: 0,
117+
);
118+
});
118119

119-
test('fetchInitial, short history', () async {
120-
await prepare();
121-
connection.prepare(json: newestResult(
122-
foundOldest: true,
123-
messages: List.generate(30, (i) => eg.streamMessage()),
124-
).toJson());
125-
await model.fetchInitial();
126-
checkNotifiedOnce();
127-
check(model)
128-
..messages.length.equals(30)
129-
..haveOldest.isTrue();
130-
});
120+
test('short history', () async {
121+
await prepare();
122+
connection.prepare(json: newestResult(
123+
foundOldest: true,
124+
messages: List.generate(30, (i) => eg.streamMessage()),
125+
).toJson());
126+
await model.fetchInitial();
127+
checkNotifiedOnce();
128+
check(model)
129+
..messages.length.equals(30)
130+
..haveOldest.isTrue();
131+
});
131132

132-
test('fetchInitial, no messages found', () async {
133-
await prepare();
134-
connection.prepare(json: newestResult(
135-
foundOldest: true,
136-
messages: [],
137-
).toJson());
138-
await model.fetchInitial();
139-
checkNotifiedOnce();
140-
check(model)
141-
..fetched.isTrue()
142-
..messages.isEmpty()
143-
..haveOldest.isTrue();
144-
});
133+
test('no messages found', () async {
134+
await prepare();
135+
connection.prepare(json: newestResult(
136+
foundOldest: true,
137+
messages: [],
138+
).toJson());
139+
await model.fetchInitial();
140+
checkNotifiedOnce();
141+
check(model)
142+
..fetched.isTrue()
143+
..messages.isEmpty()
144+
..haveOldest.isTrue();
145+
});
145146

146-
// TODO(#824): move this test
147-
test('fetchInitial, recent senders track all the messages', () async {
148-
const narrow = CombinedFeedNarrow();
149-
await prepare(narrow: narrow);
150-
final messages = [
151-
eg.streamMessage(),
152-
// Not subscribed to the stream with id 10.
153-
eg.streamMessage(stream: eg.stream(streamId: 10)),
154-
];
155-
connection.prepare(json: newestResult(
156-
foundOldest: false,
157-
messages: messages,
158-
).toJson());
159-
await model.fetchInitial();
147+
// TODO(#824): move this test
148+
test('recent senders track all the messages', () async {
149+
const narrow = CombinedFeedNarrow();
150+
await prepare(narrow: narrow);
151+
final messages = [
152+
eg.streamMessage(),
153+
// Not subscribed to the stream with id 10.
154+
eg.streamMessage(stream: eg.stream(streamId: 10)),
155+
];
156+
connection.prepare(json: newestResult(
157+
foundOldest: false,
158+
messages: messages,
159+
).toJson());
160+
await model.fetchInitial();
160161

161-
check(model).messages.length.equals(1);
162-
recent_senders_test.checkMatchesMessages(store.recentSenders, messages);
162+
check(model).messages.length.equals(1);
163+
recent_senders_test.checkMatchesMessages(store.recentSenders, messages);
164+
});
163165
});
164166

165-
test('fetchOlder', () async {
166-
const narrow = CombinedFeedNarrow();
167-
await prepare(narrow: narrow);
168-
await prepareMessages(foundOldest: false,
169-
messages: List.generate(100, (i) => eg.streamMessage(id: 1000 + i)));
167+
group('fetchOlder', () {
168+
test('smoke', () async {
169+
const narrow = CombinedFeedNarrow();
170+
await prepare(narrow: narrow);
171+
await prepareMessages(foundOldest: false,
172+
messages: List.generate(100, (i) => eg.streamMessage(id: 1000 + i)));
170173

171-
connection.prepare(json: olderResult(
172-
anchor: 1000, foundOldest: false,
173-
messages: List.generate(100, (i) => eg.streamMessage(id: 900 + i)),
174-
).toJson());
175-
final fetchFuture = model.fetchOlder();
176-
checkNotifiedOnce();
177-
check(model).fetchingOlder.isTrue();
174+
connection.prepare(json: olderResult(
175+
anchor: 1000, foundOldest: false,
176+
messages: List.generate(100, (i) => eg.streamMessage(id: 900 + i)),
177+
).toJson());
178+
final fetchFuture = model.fetchOlder();
179+
checkNotifiedOnce();
180+
check(model).fetchingOlder.isTrue();
178181

179-
await fetchFuture;
180-
checkNotifiedOnce();
181-
check(model)
182-
..fetchingOlder.isFalse()
183-
..messages.length.equals(200);
184-
checkLastRequest(
185-
narrow: narrow.apiEncode(),
186-
anchor: '1000',
187-
includeAnchor: false,
188-
numBefore: kMessageListFetchBatchSize,
189-
numAfter: 0,
190-
);
191-
});
182+
await fetchFuture;
183+
checkNotifiedOnce();
184+
check(model)
185+
..fetchingOlder.isFalse()
186+
..messages.length.equals(200);
187+
checkLastRequest(
188+
narrow: narrow.apiEncode(),
189+
anchor: '1000',
190+
includeAnchor: false,
191+
numBefore: kMessageListFetchBatchSize,
192+
numAfter: 0,
193+
);
194+
});
192195

193-
test('fetchOlder nop when already fetching', () async {
194-
const narrow = CombinedFeedNarrow();
195-
await prepare(narrow: narrow);
196-
await prepareMessages(foundOldest: false,
197-
messages: List.generate(100, (i) => eg.streamMessage(id: 1000 + i)));
196+
test('nop when already fetching', () async {
197+
const narrow = CombinedFeedNarrow();
198+
await prepare(narrow: narrow);
199+
await prepareMessages(foundOldest: false,
200+
messages: List.generate(100, (i) => eg.streamMessage(id: 1000 + i)));
198201

199-
connection.prepare(json: olderResult(
200-
anchor: 1000, foundOldest: false,
201-
messages: List.generate(100, (i) => eg.streamMessage(id: 900 + i)),
202-
).toJson());
203-
final fetchFuture = model.fetchOlder();
204-
checkNotifiedOnce();
205-
check(model).fetchingOlder.isTrue();
202+
connection.prepare(json: olderResult(
203+
anchor: 1000, foundOldest: false,
204+
messages: List.generate(100, (i) => eg.streamMessage(id: 900 + i)),
205+
).toJson());
206+
final fetchFuture = model.fetchOlder();
207+
checkNotifiedOnce();
208+
check(model).fetchingOlder.isTrue();
206209

207-
// Don't prepare another response.
208-
final fetchFuture2 = model.fetchOlder();
209-
checkNotNotified();
210-
check(model).fetchingOlder.isTrue();
210+
// Don't prepare another response.
211+
final fetchFuture2 = model.fetchOlder();
212+
checkNotNotified();
213+
check(model).fetchingOlder.isTrue();
211214

212-
await fetchFuture;
213-
await fetchFuture2;
214-
// We must not have made another request, because we didn't
215-
// prepare another response and didn't get an exception.
216-
checkNotifiedOnce();
217-
check(model)
218-
..fetchingOlder.isFalse()
219-
..messages.length.equals(200);
220-
});
215+
await fetchFuture;
216+
await fetchFuture2;
217+
// We must not have made another request, because we didn't
218+
// prepare another response and didn't get an exception.
219+
checkNotifiedOnce();
220+
check(model)
221+
..fetchingOlder.isFalse()
222+
..messages.length.equals(200);
223+
});
221224

222-
test('fetchOlder nop when already haveOldest true', () async {
223-
await prepare(narrow: const CombinedFeedNarrow());
224-
await prepareMessages(foundOldest: true, messages:
225-
List.generate(30, (i) => eg.streamMessage()));
226-
check(model)
227-
..haveOldest.isTrue()
228-
..messages.length.equals(30);
225+
test('nop when already haveOldest true', () async {
226+
await prepare(narrow: const CombinedFeedNarrow());
227+
await prepareMessages(foundOldest: true, messages:
228+
List.generate(30, (i) => eg.streamMessage()));
229+
check(model)
230+
..haveOldest.isTrue()
231+
..messages.length.equals(30);
229232

230-
await model.fetchOlder();
231-
// We must not have made a request, because we didn't
232-
// prepare a response and didn't get an exception.
233-
checkNotNotified();
234-
check(model)
235-
..haveOldest.isTrue()
236-
..messages.length.equals(30);
237-
});
233+
await model.fetchOlder();
234+
// We must not have made a request, because we didn't
235+
// prepare a response and didn't get an exception.
236+
checkNotNotified();
237+
check(model)
238+
..haveOldest.isTrue()
239+
..messages.length.equals(30);
240+
});
238241

239-
test('fetchOlder handles servers not understanding includeAnchor', () async {
240-
const narrow = CombinedFeedNarrow();
241-
await prepare(narrow: narrow);
242-
await prepareMessages(foundOldest: false,
243-
messages: List.generate(100, (i) => eg.streamMessage(id: 1000 + i)));
242+
test('handles servers not understanding includeAnchor', () async {
243+
const narrow = CombinedFeedNarrow();
244+
await prepare(narrow: narrow);
245+
await prepareMessages(foundOldest: false,
246+
messages: List.generate(100, (i) => eg.streamMessage(id: 1000 + i)));
244247

245-
// The old behavior is to include the anchor message regardless of includeAnchor.
246-
connection.prepare(json: olderResult(
247-
anchor: 1000, foundOldest: false, foundAnchor: true,
248-
messages: List.generate(101, (i) => eg.streamMessage(id: 900 + i)),
249-
).toJson());
250-
await model.fetchOlder();
251-
checkNotified(count: 2);
252-
check(model)
253-
..fetchingOlder.isFalse()
254-
..messages.length.equals(200);
255-
});
248+
// The old behavior is to include the anchor message regardless of includeAnchor.
249+
connection.prepare(json: olderResult(
250+
anchor: 1000, foundOldest: false, foundAnchor: true,
251+
messages: List.generate(101, (i) => eg.streamMessage(id: 900 + i)),
252+
).toJson());
253+
await model.fetchOlder();
254+
checkNotified(count: 2);
255+
check(model)
256+
..fetchingOlder.isFalse()
257+
..messages.length.equals(200);
258+
});
256259

257-
// TODO(#824): move this test
258-
test('fetchOlder, recent senders track all the messages', () async {
259-
const narrow = CombinedFeedNarrow();
260-
await prepare(narrow: narrow);
261-
final initialMessages = List.generate(10, (i) => eg.streamMessage(id: 100 + i));
262-
await prepareMessages(foundOldest: false, messages: initialMessages);
260+
// TODO(#824): move this test
261+
test('recent senders track all the messages', () async {
262+
const narrow = CombinedFeedNarrow();
263+
await prepare(narrow: narrow);
264+
final initialMessages = List.generate(10, (i) => eg.streamMessage(id: 100 + i));
265+
await prepareMessages(foundOldest: false, messages: initialMessages);
263266

264-
final oldMessages = List.generate(10, (i) => eg.streamMessage(id: 89 + i))
265-
// Not subscribed to the stream with id 10.
266-
..add(eg.streamMessage(id: 99, stream: eg.stream(streamId: 10)));
267-
connection.prepare(json: olderResult(
268-
anchor: 100, foundOldest: false,
269-
messages: oldMessages,
270-
).toJson());
271-
await model.fetchOlder();
267+
final oldMessages = List.generate(10, (i) => eg.streamMessage(id: 89 + i))
268+
// Not subscribed to the stream with id 10.
269+
..add(eg.streamMessage(id: 99, stream: eg.stream(streamId: 10)));
270+
connection.prepare(json: olderResult(
271+
anchor: 100, foundOldest: false,
272+
messages: oldMessages,
273+
).toJson());
274+
await model.fetchOlder();
272275

273-
check(model).messages.length.equals(20);
274-
recent_senders_test.checkMatchesMessages(store.recentSenders,
275-
[...initialMessages, ...oldMessages]);
276+
check(model).messages.length.equals(20);
277+
recent_senders_test.checkMatchesMessages(store.recentSenders,
278+
[...initialMessages, ...oldMessages]);
279+
});
276280
});
277281

278282
test('MessageEvent', () async {

0 commit comments

Comments
 (0)