workouttest_app/test/account_bloc_test.dart
2021-04-02 11:42:26 +02:00

74 lines
1.7 KiB
Dart

import 'package:aitrainer_app/bloc/account/account_bloc.dart';
import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart' as test;
import 'package:flutter_test/flutter_test.dart';
class MockCustomerRepository extends Mock implements CustomerRepository {}
void main() {
MockCustomerRepository customerRepository;
late AccountBloc accountBloc;
TestWidgetsFlutterBinding.ensureInitialized();
test.setUp(() {
customerRepository = MockCustomerRepository();
accountBloc = AccountBloc(customerRepository: customerRepository);
});
test.tearDown(() {
accountBloc.close();
});
test.test('initial state is correct', () {
expect(accountBloc.state, AccountInitial());
});
group('Account', () {
test.test('emits [loading, logged in] when the customer clicked login', () {
final expectedResponse = [
AccountLoading(),
AccountLoggedIn(),
];
//verify(accountBloc.customerRepository.customer == null);
expectLater(
accountBloc,
emitsInOrder(expectedResponse),
);
accountBloc.add(AccountLogin());
});
});
test.test('emits [loading, logged out] when the customer clicked logout', () {
final expectedResponse = [
AccountLoading(),
AccountLoggedOut(),
];
expectLater(
accountBloc,
emitsInOrder(expectedResponse),
);
accountBloc.add(AccountLogout());
});
test.test('emits [loading, logged out] when the customer data changed', () {
final expectedResponse = [
AccountLoading(),
AccountReady(),
];
expectLater(
accountBloc,
emitsInOrder(expectedResponse),
);
accountBloc.add(AccountChangeCustomer());
});
}