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;
  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());
    });

}