From e1c85828e0c3c192bdd23a6d8f047decbfbe6ee2 Mon Sep 17 00:00:00 2001 From: bizz84 Date: Tue, 20 Aug 2019 14:29:33 +0100 Subject: [PATCH] Complete bloc tests --- test/email_sign_in_bloc_test.dart | 48 +++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/test/email_sign_in_bloc_test.dart b/test/email_sign_in_bloc_test.dart index 0765734..c9568ad 100644 --- a/test/email_sign_in_bloc_test.dart +++ b/test/email_sign_in_bloc_test.dart @@ -1,4 +1,6 @@ +import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; import 'package:time_tracker_flutter_course/app/sign_in/email_sign_in_bloc.dart'; import 'package:time_tracker_flutter_course/app/sign_in/email_sign_in_model.dart'; @@ -17,10 +19,44 @@ void main() { bloc.dispose(); }); - test('WHEN email is updated' - 'AND password is updated' - 'AND submit is called' - 'THEN modelStream emits the correct events', () async { - expect(bloc.modelStream, emits(EmailSignInModel())); + test( + 'WHEN email is updated' + 'AND password is updated' + 'AND submit is called' + 'THEN modelStream emits the correct events', () async { + when(mockAuth.signInWithEmailAndPassword(any, any)) + .thenThrow(PlatformException(code: 'ERROR')); + expect( + bloc.modelStream, + emitsInOrder([ + EmailSignInModel(), + EmailSignInModel(email: 'email@email.com'), + EmailSignInModel( + email: 'email@email.com', + password: 'password', + ), + EmailSignInModel( + email: 'email@email.com', + password: 'password', + submitted: true, + isLoading: true, + ), + EmailSignInModel( + email: 'email@email.com', + password: 'password', + submitted: true, + isLoading: false, + ), + ]) + ); + + bloc.updateEmail('email@email.com'); + + bloc.updatePassword('password'); + + try { + await bloc.submit(); + } catch (_) { + } }); -} \ No newline at end of file +}