Skip to content

Commit

Permalink
Merge branch 'test/appl-user-details' into test/application
Browse files Browse the repository at this point in the history
  • Loading branch information
saksham-gt committed Jun 13, 2022
2 parents e7a984d + 0ac904e commit 0abb746
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 113 deletions.
113 changes: 0 additions & 113 deletions test/application/auth/auth_bloc_tests.dart

This file was deleted.

38 changes: 38 additions & 0 deletions test/application/user_details/user_details_bloc_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'dart:async';

import 'package:bloc_test/bloc_test.dart';
import 'package:collaction_app/application/user_details/user_details_bloc.dart';
import 'package:collaction_app/domain/user/user.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

import 'user_details_fixtures.dart';

void main() {
group('test User Details BLoC', () {
final UserDetailsBloc tUserBloc = UserDetailsBloc(tUserRepo);

test('testing Initial UserDetails BLoC State', () {
expect(tUserBloc.state, const UserDetailsState.initial());
});

when(() => tUserRepo.observeUser()).thenAnswer((_) {
final x = StreamController<User>();
x.add(tUser);
print('x.stream is User? ${x.stream.distinct() is Stream<User>}');
return x.stream.distinct();
});

blocTest(
'testing fetchDetails event',
build: () => tUserBloc,
act: (UserDetailsBloc bloc) {
bloc.add(const UserDetailsEvent.fetchDetails());
},
expect: () => [
const UserDetailsState.fetchingDetails(),
const UserDetailsState.fetchingDetailsFailed(),
],
);
});
}
17 changes: 17 additions & 0 deletions test/application/user_details/user_details_fixtures.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:collaction_app/domain/user/i_user_repository.dart';
import 'package:collaction_app/domain/user/user.dart';

import 'package:mocktail/mocktail.dart';

class MockUserRepository extends Mock implements IUserRepository {}

final IUserRepository tUserRepo = MockUserRepository();

// ignore: avoid_positional_boolean_parameters
Future<String?> testGetAnonymousTokenId([bool forceRefresh = false]) =>
Future.value(null);

const User tUser = User(
id: 'tId',
getIdToken: testGetAnonymousTokenId,
);

0 comments on commit 0abb746

Please sign in to comment.