wt1.1.1 ExercisePlan + ExercisePlan detail, Trainee
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
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());
|
||||
});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/customer.dart';
|
||||
import 'package:aitrainer_app/service/customer_service.dart';
|
||||
import 'package:aitrainer_app/util/env.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
//import 'package:mockito/mockito.dart';
|
||||
|
||||
// Create a MockClient using the Mock class provided by the Mockito package.
|
||||
// Create new instances of this class in each test.
|
||||
/* class MockClient extends Mock implements CustomerApi {
|
||||
Future<List<Customer>> getTrainees(int trainerId) async {
|
||||
if (trainerId == 62) {
|
||||
List<Customer> list = List<Customer>();
|
||||
Customer customer1 = Customer(firstname: "Zalán", name: "Boss");
|
||||
Customer customer2 = Customer(firstname: "Zétény", name: "Boss");
|
||||
list.add(customer1);
|
||||
list.add(customer2);
|
||||
return list;
|
||||
} else {
|
||||
throw Exception("No trainees found");
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
main() {
|
||||
|
||||
|
||||
setUp(() {
|
||||
Cache().setTestBaseUrl();
|
||||
});
|
||||
|
||||
group('fetchPost', () {
|
||||
test('returns a List<Customer> if the http call completes successfully', () async {
|
||||
final client = CustomerApi();
|
||||
|
||||
// Use Mockito to return a successful response when it calls the
|
||||
// provided http.Client.
|
||||
List<Customer> trainees = List<Customer>();
|
||||
trainees = await client.getTrainees(62);
|
||||
|
||||
expect(trainees.length, 2);
|
||||
expect(trainees[0].firstname, "Zalán");
|
||||
});
|
||||
|
||||
test('throws an exception if the http call completes with an error', () async {
|
||||
final client = CustomerApi();
|
||||
|
||||
expect(client.getTrainees(22), throwsException);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/exercise_plan.dart';
|
||||
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
|
||||
import 'package:aitrainer_app/service/exercise_plan_service.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
main() {
|
||||
|
||||
setUp(() {
|
||||
Cache().setTestBaseUrl();
|
||||
});
|
||||
|
||||
group('new Plan', () {
|
||||
test('add new plan and plan details', () async {
|
||||
final client = ExercisePlanApi();
|
||||
|
||||
ExercisePlan exercisePlan = ExercisePlan(
|
||||
"Test plan " + DateTime.now().toIso8601String(),
|
||||
62
|
||||
);
|
||||
exercisePlan.dateAdd = DateTime.now();
|
||||
|
||||
ExercisePlan savedPlan = await client.saveExercisePlan(exercisePlan);
|
||||
expect(savedPlan.name.substring(0, 9), "Test plan");
|
||||
expect(savedPlan.customerId, 62);
|
||||
|
||||
|
||||
|
||||
int newPlanId = savedPlan.exercisePlanId;
|
||||
//savedPlan.exercisePlanId = newPlanId;
|
||||
|
||||
ExercisePlanDetail detail = ExercisePlanDetail(
|
||||
39 //exerciseTypeId
|
||||
);
|
||||
detail.serie = 3;
|
||||
detail.repeats = 12;
|
||||
detail.weightEquation = "90";
|
||||
detail.exercisePlanId = newPlanId;
|
||||
|
||||
ExercisePlanDetail savedDetail = await client.saveExercisePlanDetail(detail);
|
||||
|
||||
expect(savedDetail.weightEquation, "90");
|
||||
expect(savedDetail.repeats, 12);
|
||||
expect(savedDetail.exercisePlanId, newPlanId);
|
||||
|
||||
await client.deleteExercisePlanDetail(savedDetail.exercisePlanDetailId);
|
||||
await client.deleteExercisePlan(savedPlan.exercisePlanId);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
test('get the last plan and change plan details', () async {
|
||||
final client = ExercisePlanApi();
|
||||
|
||||
ExercisePlan exercisePlan = await client.getLastExercisePlan(61);
|
||||
List<ExercisePlanDetail> list = await client.getExercisePlanDetail(exercisePlan.exercisePlanId);
|
||||
|
||||
expect(list.length, 2);
|
||||
ExercisePlanDetail detail = ExercisePlanDetail(3);
|
||||
detail.serie = 4;
|
||||
detail.repeats = 12;
|
||||
detail.weightEquation = "10";
|
||||
detail.exercisePlanId = exercisePlan.exercisePlanId;
|
||||
//list.add(detail);
|
||||
ExercisePlanDetail newObjectToSave = await client.saveExercisePlanDetail(detail);
|
||||
List<ExercisePlanDetail> list2 = await client.getExercisePlanDetail(exercisePlan.exercisePlanId);
|
||||
expect(list2.length, 3);
|
||||
expect(list2.last.weightEquation, "10");
|
||||
await client.deleteExercisePlanDetail(newObjectToSave.exercisePlanDetailId);
|
||||
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user