Skip to content

Commit

Permalink
test: ensure NextEventRxPresenter emits ViewModel on load and reload …
Browse files Browse the repository at this point in the history
…with success
  • Loading branch information
hmartiins committed Jan 5, 2025
1 parent 30f69ad commit fd258ef
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions test/presentation/rx/next_event_rx_presenter_test.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
@Timeout(Duration(seconds: 1))
library;

import 'package:advanced_flutter/presentation/presenters/next_event_presenter.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:rxdart/subjects.dart';

import '../../helpers/fakes.dart';

final class NextEventRxPresenter {
final Future<void> Function({required String groupId}) nextEventLoader;
final nextEventSubject = BehaviorSubject();
final nextEventSubject = BehaviorSubject<NextEventViewModel>();
final isBusySubject = BehaviorSubject<bool>();

NextEventRxPresenter({required this.nextEventLoader});

Stream get nextEventStream => nextEventSubject.stream;
Stream<NextEventViewModel> get nextEventStream => nextEventSubject.stream;
Stream<bool> get isBusyStream => isBusySubject.stream;

Future<void> loadNextEvent({
Expand All @@ -23,6 +24,7 @@ final class NextEventRxPresenter {
try {
if (isReload) isBusySubject.add(true);
await nextEventLoader(groupId: groupId);
nextEventSubject.add(const NextEventViewModel());
} catch (error) {
nextEventSubject.addError(error);
} finally {
Expand Down Expand Up @@ -76,11 +78,19 @@ void main() {

test('should emit correct events on reload with success', () async {
expectLater(sut.isBusyStream, emitsInOrder([true, false]));
expectLater(
sut.nextEventStream,
emits(const TypeMatcher<NextEventViewModel>()),
);
await sut.loadNextEvent(groupId: groupId, isReload: true);
});

test('should emit correct events on load with success', () async {
sut.isBusyStream.listen(neverCalled);
expectLater(
sut.nextEventStream,
emits(const TypeMatcher<NextEventViewModel>()),
);
await sut.loadNextEvent(groupId: groupId);
});
}

0 comments on commit fd258ef

Please sign in to comment.