From fd258efd9ee0f32bc8a37e00ea8c238fdc2bebfe Mon Sep 17 00:00:00 2001 From: hmartiins Date: Sun, 5 Jan 2025 17:14:10 -0300 Subject: [PATCH] test: ensure NextEventRxPresenter emits ViewModel on load and reload with success --- .../rx/next_event_rx_presenter_test.dart | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/presentation/rx/next_event_rx_presenter_test.dart b/test/presentation/rx/next_event_rx_presenter_test.dart index ba3201b..4e83b8e 100644 --- a/test/presentation/rx/next_event_rx_presenter_test.dart +++ b/test/presentation/rx/next_event_rx_presenter_test.dart @@ -1,6 +1,7 @@ @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'; @@ -8,12 +9,12 @@ import '../../helpers/fakes.dart'; final class NextEventRxPresenter { final Future Function({required String groupId}) nextEventLoader; - final nextEventSubject = BehaviorSubject(); + final nextEventSubject = BehaviorSubject(); final isBusySubject = BehaviorSubject(); NextEventRxPresenter({required this.nextEventLoader}); - Stream get nextEventStream => nextEventSubject.stream; + Stream get nextEventStream => nextEventSubject.stream; Stream get isBusyStream => isBusySubject.stream; Future loadNextEvent({ @@ -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 { @@ -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()), + ); 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()), + ); await sut.loadNextEvent(groupId: groupId); }); }