|
| 1 | +import 'dart:async'; |
1 | 2 | import 'dart:convert'; |
2 | 3 | import 'dart:io'; |
3 | 4 |
|
@@ -427,6 +428,58 @@ void main() { |
427 | 428 | }); |
428 | 429 | }); |
429 | 430 |
|
| 431 | + group('renarrowAndFetch', () { |
| 432 | + test('smoke', () => awaitFakeAsync((async) async { |
| 433 | + final channel = eg.stream(); |
| 434 | + |
| 435 | + const narrow = CombinedFeedNarrow(); |
| 436 | + await prepare(narrow: narrow, stream: channel); |
| 437 | + final messages = List.generate(100, |
| 438 | + (i) => eg.streamMessage(id: 1000 + i, stream: channel)); |
| 439 | + await prepareMessages(foundOldest: false, messages: messages); |
| 440 | + |
| 441 | + // Start a fetchOlder, so we can check that renarrowAndFetch causes its |
| 442 | + // result to be discarded. |
| 443 | + connection.prepare( |
| 444 | + json: olderResult( |
| 445 | + anchor: 1000, foundOldest: false, |
| 446 | + messages: List.generate(100, |
| 447 | + (i) => eg.streamMessage(id: 900 + i, stream: channel)), |
| 448 | + ).toJson(), |
| 449 | + delay: Duration(milliseconds: 500), |
| 450 | + ); |
| 451 | + unawaited(model.fetchOlder()); |
| 452 | + checkNotifiedOnce(); |
| 453 | + |
| 454 | + // Start the renarrowAndFetch. |
| 455 | + final newNarrow = ChannelNarrow(channel.streamId); |
| 456 | + final result = eg.getMessagesResult( |
| 457 | + anchor: model.anchor, foundOldest: false, messages: messages); |
| 458 | + connection.prepare(json: result.toJson(), delay: Duration(seconds: 1)); |
| 459 | + model.renarrowAndFetch(newNarrow); |
| 460 | + checkNotifiedOnce(); |
| 461 | + check(model) |
| 462 | + ..fetched.isFalse() |
| 463 | + ..narrow.equals(newNarrow) |
| 464 | + ..messages.isEmpty(); |
| 465 | + |
| 466 | + // Elapse until the fetchOlder is done but renarrowAndFetch is still |
| 467 | + // pending; check that the list is still empty despite the fetchOlder. |
| 468 | + async.elapse(Duration(milliseconds: 750)); |
| 469 | + check(model) |
| 470 | + ..fetched.isFalse() |
| 471 | + ..narrow.equals(newNarrow) |
| 472 | + ..messages.isEmpty(); |
| 473 | + |
| 474 | + // Elapse until the renarrowAndFetch completes. |
| 475 | + async.elapse(Duration(seconds: 250)); |
| 476 | + check(model) |
| 477 | + ..fetched.isTrue() |
| 478 | + ..narrow.equals(newNarrow) |
| 479 | + ..messages.length.equals(100); |
| 480 | + })); |
| 481 | + }); |
| 482 | + |
430 | 483 | group('fetching more', () { |
431 | 484 | test('fetchOlder smoke', () async { |
432 | 485 | const narrow = CombinedFeedNarrow(); |
|
0 commit comments