Merge ssh://git.aitrainer.app:6622/bossanyit/aitrainer_app
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:aitrainer_app/bloc/exercise_plan/exercise_plan_bloc.dart';
|
||||
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/model/model_change.dart';
|
||||
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
@@ -65,17 +66,14 @@ main() {
|
||||
bloc.customerId = 101;
|
||||
bloc.add(ExercisePlanLoad());
|
||||
|
||||
final expectedResponse = [
|
||||
ExercisePlanLoading(),
|
||||
ExercisePlanReady()
|
||||
];
|
||||
final expectedResponse = [ExercisePlanLoading(), ExercisePlanReady()];
|
||||
|
||||
expectLater(
|
||||
bloc,
|
||||
emitsInOrder(expectedResponse),
|
||||
).then((_) {
|
||||
expect(bloc.exercisePlanRepository.newPlan, false);
|
||||
expect(bloc.exercisePlanRepository.exercisePlan.name, "Test Plan2" );
|
||||
expect(bloc.exercisePlanRepository.exercisePlan.name, "Test Plan2");
|
||||
expect(bloc.exercisePlanRepository.exercisePlanDetails[4].weightEquation, "95");
|
||||
expect(Cache().getMyExercisePlan().name, "Test Plan2");
|
||||
expect(Cache().getMyExercisePlanDetails()[4].weightEquation, "95");
|
||||
@@ -93,14 +91,9 @@ main() {
|
||||
detail4.weightEquation = "55";
|
||||
detail4.serie = 3;
|
||||
|
||||
|
||||
|
||||
bloc.add(ExercisePlanAddExercise(exercisePlanDetail: detail4));
|
||||
|
||||
final expectedResponse2 = [
|
||||
ExercisePlanLoading(),
|
||||
ExercisePlanReady()
|
||||
];
|
||||
final expectedResponse2 = [ExercisePlanLoading(), ExercisePlanReady()];
|
||||
|
||||
expectLater(
|
||||
bloc,
|
||||
@@ -110,10 +103,8 @@ main() {
|
||||
expect(bloc.exercisePlanRepository.exercisePlan.customerId, 101);
|
||||
expect(bloc.exercisePlanRepository.exercisePlanDetails.length, 3);
|
||||
expect(bloc.exercisePlanRepository.exercisePlanDetails[5].repeats, 20);
|
||||
expect(bloc.exercisePlanRepository.exercisePlanDetails[5].change, ExercisePlanDetailChange.add);
|
||||
expect(Cache()
|
||||
.getMyExercisePlan()
|
||||
.name, "Test Plan2");
|
||||
expect(bloc.exercisePlanRepository.exercisePlanDetails[5].change, ModelChange.add);
|
||||
expect(Cache().getMyExercisePlan().name, "Test Plan2");
|
||||
expect(Cache().getMyExercisePlanDetails()[5].weightEquation, "55");
|
||||
expect(Cache().getMyExercisePlanDetails()[5].repeats, 20);
|
||||
});
|
||||
@@ -127,10 +118,7 @@ main() {
|
||||
|
||||
bloc.add(ExercisePlanAddExercise(exercisePlanDetail: bloc.exercisePlanRepository.exercisePlanDetails[3]));
|
||||
|
||||
final expectedResponse2 = [
|
||||
ExercisePlanLoading(),
|
||||
ExercisePlanReady()
|
||||
];
|
||||
final expectedResponse2 = [ExercisePlanLoading(), ExercisePlanReady()];
|
||||
|
||||
expectLater(
|
||||
bloc,
|
||||
@@ -140,7 +128,6 @@ main() {
|
||||
expect(bloc.exercisePlanRepository.exercisePlanDetails[3].repeats, 25);
|
||||
expect(Cache().getMyExercisePlanDetails()[3].repeats, 25);
|
||||
});
|
||||
|
||||
});
|
||||
test('Delete bloc', () async {
|
||||
bloc.customerId = 101;
|
||||
@@ -148,10 +135,7 @@ main() {
|
||||
bloc.exercisePlanRepository.getExercisePlanDetails();
|
||||
bloc.add(ExercisePlanRemoveExercise(exercisePlanDetail: bloc.exercisePlanRepository.exercisePlanDetails[3]));
|
||||
|
||||
final expectedResponse2 = [
|
||||
ExercisePlanLoading(),
|
||||
ExercisePlanReady()
|
||||
];
|
||||
final expectedResponse2 = [ExercisePlanLoading(), ExercisePlanReady()];
|
||||
|
||||
expectLater(
|
||||
bloc,
|
||||
@@ -164,8 +148,8 @@ main() {
|
||||
});
|
||||
});
|
||||
|
||||
test('Test Trainee', () async {
|
||||
/*bloc.customerId = 102;
|
||||
test('Test Trainee', () async {
|
||||
/*bloc.customerId = 102;
|
||||
bloc.exercisePlanRepository.customerId = 102;
|
||||
|
||||
bloc.add(ExercisePlanLoad());
|
||||
@@ -183,8 +167,6 @@ main() {
|
||||
expect(bloc.exercisePlanRepository.newPlan, true);
|
||||
expect(bloc.exercisePlanRepository.exercisePlanDetails.length, 0);
|
||||
});*/
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
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/model/model_change.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'mocks.dart';
|
||||
|
||||
|
||||
main() {
|
||||
SimExercisePlanRepository _exercisePlanRepository;
|
||||
int _customerId;
|
||||
|
||||
Future<void> setUpPlan() async {
|
||||
|
||||
final String planName2 = "Test Plan2";
|
||||
ExercisePlan plan2 = ExercisePlan(planName2, 101);
|
||||
_exercisePlanRepository.setCustomerId(101);
|
||||
@@ -40,8 +39,6 @@ main() {
|
||||
await setUpPlan();
|
||||
});
|
||||
|
||||
|
||||
|
||||
group('New Plan', () {
|
||||
test('add new plan and plan details and save', () async {
|
||||
final String planName = "Boss Test Plan";
|
||||
@@ -69,11 +66,8 @@ main() {
|
||||
expect(_exercisePlanRepository.getExercisePlan().name, planName);
|
||||
expect(_exercisePlanRepository.getExercisePlan().exercisePlanId > 0, true);
|
||||
|
||||
ExercisePlanDetail detail =
|
||||
_exercisePlanRepository.getExercisePlanDetailByExerciseId(55);
|
||||
ExercisePlanDetail detail = _exercisePlanRepository.getExercisePlanDetailByExerciseId(55);
|
||||
expect(detail.exercisePlanId, _exercisePlanRepository.getExercisePlan().exercisePlanId);
|
||||
|
||||
|
||||
});
|
||||
test('save new plan and plan details second', () async {
|
||||
int customerId = 100;
|
||||
@@ -104,23 +98,21 @@ main() {
|
||||
ExercisePlanDetail detail = _exercisePlanRepository.getExercisePlanDetailByExerciseId(13);
|
||||
expect(detail.exercisePlanId, _exercisePlanRepository.getExercisePlan().exercisePlanId);
|
||||
expect(detail.repeats, 33);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
group('Existing Plan', () {
|
||||
test('Get Last Plan and Details from DB', () async {
|
||||
ExercisePlan exercisePlan = await _exercisePlanRepository.getLastExercisePlan();
|
||||
expect(exercisePlan.customerId,101);
|
||||
expect(exercisePlan.customerId, 101);
|
||||
|
||||
await _exercisePlanRepository.getExercisePlanDetails();
|
||||
expect(_exercisePlanRepository.exercisePlanDetails[3].repeats,23 );
|
||||
expect(_exercisePlanRepository.exercisePlanDetails[4].weightEquation,"95" );
|
||||
expect(_exercisePlanRepository.exercisePlanDetails[3].repeats, 23);
|
||||
expect(_exercisePlanRepository.exercisePlanDetails[4].weightEquation, "95");
|
||||
|
||||
//Test Cache
|
||||
expect(Cache().getMyExercisePlan().name,"Test Plan2");
|
||||
expect(Cache().getMyExercisePlanDetails()[3].weightEquation,"60");
|
||||
expect(Cache().getMyExercisePlan().name, "Test Plan2");
|
||||
expect(Cache().getMyExercisePlanDetails()[3].weightEquation, "60");
|
||||
});
|
||||
|
||||
test('Add new PlanDetail', () async {
|
||||
@@ -138,20 +130,14 @@ main() {
|
||||
expect(_exercisePlanRepository.getExercisePlan().name, "Test Plan2");
|
||||
expect(Cache().getMyExercisePlanDetails()[5].weightEquation, "105");
|
||||
expect(Cache().getMyExercisePlanDetails()[5].repeats, 6);
|
||||
|
||||
});
|
||||
|
||||
test('Delete from PlanDetails', () async {
|
||||
_exercisePlanRepository.removeExerciseTypeFromPlanByExerciseTypeId(4);
|
||||
_exercisePlanRepository.saveExercisePlan();
|
||||
|
||||
expect(_exercisePlanRepository.exercisePlanDetails[4].change, ExercisePlanDetailChange.delete);
|
||||
expect(_exercisePlanRepository.exercisePlanDetails[4].change, ModelChange.delete);
|
||||
expect(Cache().getMyExercisePlanDetails()[4], isNull);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+23
-29
@@ -3,6 +3,7 @@ import 'dart:collection';
|
||||
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/model/model_change.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
|
||||
import 'package:aitrainer_app/service/exercise_plan_service.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
@@ -33,7 +34,7 @@ class MockExercisePlanApi extends Mock implements ExercisePlanApi {
|
||||
Future<ExercisePlanDetail> updateExercisePlanDetail(ExercisePlanDetail detail, int planDetailId) async {
|
||||
ExercisePlanDetail updated;
|
||||
memoryExercisePlanDetail.forEach((element) {
|
||||
if ( element.exercisePlanDetailId == planDetailId ) {
|
||||
if (element.exercisePlanDetailId == planDetailId) {
|
||||
element = detail;
|
||||
}
|
||||
});
|
||||
@@ -45,12 +46,12 @@ class MockExercisePlanApi extends Mock implements ExercisePlanApi {
|
||||
int index = -1;
|
||||
int countIndex = 0;
|
||||
memoryExercisePlanDetail.forEach((element) {
|
||||
if ( element.exercisePlanId == exercisePlanId ) {
|
||||
if (element.exercisePlanId == exercisePlanId) {
|
||||
index = countIndex;
|
||||
}
|
||||
countIndex++;
|
||||
});
|
||||
if ( index > -1) {
|
||||
if (index > -1) {
|
||||
memoryExercisePlanDetail.removeAt(index);
|
||||
}
|
||||
}
|
||||
@@ -58,7 +59,7 @@ class MockExercisePlanApi extends Mock implements ExercisePlanApi {
|
||||
Future<List<ExercisePlanDetail>> getExercisePlanDetail(int exercisePlanId) async {
|
||||
List<ExercisePlanDetail> foundList = List();
|
||||
memoryExercisePlanDetail.forEach((element) {
|
||||
if ( element.exercisePlanId == exercisePlanId ) {
|
||||
if (element.exercisePlanId == exercisePlanId) {
|
||||
foundList.add(element);
|
||||
}
|
||||
});
|
||||
@@ -68,7 +69,7 @@ class MockExercisePlanApi extends Mock implements ExercisePlanApi {
|
||||
Future<ExercisePlan> getLastExercisePlan(int customerId) async {
|
||||
ExercisePlan found;
|
||||
memoryExercisePlan.forEach((element) {
|
||||
if ( element.customerId == customerId ) {
|
||||
if (element.customerId == customerId) {
|
||||
found = element;
|
||||
}
|
||||
});
|
||||
@@ -77,19 +78,18 @@ class MockExercisePlanApi extends Mock implements ExercisePlanApi {
|
||||
}
|
||||
|
||||
class SimExercisePlanRepository with ExercisePlanRepository {
|
||||
|
||||
Future<void> getExercisePlanDetails() async {
|
||||
if (exercisePlan == null) {
|
||||
ExercisePlan exercisePlan = await this.getLastExercisePlan();
|
||||
if ( exercisePlan == null ) {
|
||||
if (exercisePlan == null) {
|
||||
exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
List<ExercisePlanDetail> list = List();
|
||||
LinkedHashMap<int, ExercisePlanDetail> listCache = Cache().getMyExercisePlanDetails();
|
||||
if ( listCache.length > 0) {
|
||||
LinkedHashMap<int, ExercisePlanDetail> listCache = Cache().getMyExercisePlanDetails();
|
||||
if (listCache.length > 0) {
|
||||
exercisePlanDetails = listCache;
|
||||
return;
|
||||
} else {
|
||||
@@ -109,11 +109,11 @@ class SimExercisePlanRepository with ExercisePlanRepository {
|
||||
}
|
||||
|
||||
Future<ExercisePlan> getLastExercisePlan() async {
|
||||
if ( customerId == 0) {
|
||||
if (customerId == 0) {
|
||||
return null;
|
||||
}
|
||||
ExercisePlan myExercisePlan = Cache().getMyExercisePlan();
|
||||
if ( myExercisePlan != null ) {
|
||||
if (myExercisePlan != null) {
|
||||
newPlan = false;
|
||||
return myExercisePlan;
|
||||
}
|
||||
@@ -125,13 +125,13 @@ class SimExercisePlanRepository with ExercisePlanRepository {
|
||||
}
|
||||
|
||||
Future<void> saveExercisePlan() async {
|
||||
if ( exercisePlan == null ) {
|
||||
if ( Cache().userLoggedIn == null ) {
|
||||
if (exercisePlan == null) {
|
||||
if (Cache().userLoggedIn == null) {
|
||||
throw Exception("please log in");
|
||||
}
|
||||
|
||||
String exercisePlanName;
|
||||
if ( this.customerId == Cache().userLoggedIn.customerId) {
|
||||
if (this.customerId == Cache().userLoggedIn.customerId) {
|
||||
exercisePlanName = Cache().userLoggedIn.name + " private";
|
||||
} else {
|
||||
exercisePlanName = Cache().getTrainee().name + " " + Cache().getTrainee().firstname + " private";
|
||||
@@ -139,13 +139,11 @@ class SimExercisePlanRepository with ExercisePlanRepository {
|
||||
|
||||
exercisePlan = ExercisePlan(exercisePlanName, this.customerId);
|
||||
}
|
||||
if ( newPlan ) {
|
||||
if (newPlan) {
|
||||
exercisePlan.dateAdd = DateTime.now();
|
||||
exercisePlan.private = true;
|
||||
|
||||
ExercisePlan savedExercisePlan
|
||||
= await MockExercisePlanApi().saveExercisePlan(exercisePlan);
|
||||
|
||||
ExercisePlan savedExercisePlan = await MockExercisePlanApi().saveExercisePlan(exercisePlan);
|
||||
|
||||
LinkedHashMap<int, ExercisePlanDetail> savedExercisePlanDetails = LinkedHashMap();
|
||||
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
|
||||
@@ -158,24 +156,20 @@ class SimExercisePlanRepository with ExercisePlanRepository {
|
||||
|
||||
exercisePlan = savedExercisePlan;
|
||||
} else {
|
||||
|
||||
await MockExercisePlanApi().updateExercisePlan(exercisePlan, exercisePlan.exercisePlanId);
|
||||
|
||||
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
|
||||
if ( exercisePlanDetail.change == ExercisePlanDetailChange.delete ) {
|
||||
await MockExercisePlanApi()
|
||||
.deleteExercisePlanDetail(exercisePlanDetail.exercisePlanDetailId);
|
||||
if (exercisePlanDetail.change == ModelChange.delete) {
|
||||
await MockExercisePlanApi().deleteExercisePlanDetail(exercisePlanDetail.exercisePlanDetailId);
|
||||
Cache().deleteMyExercisePlanDetail(exercisePlanDetail);
|
||||
} else if ( exercisePlanDetail.change == ExercisePlanDetailChange.update ) {
|
||||
await MockExercisePlanApi()
|
||||
.updateExercisePlanDetail(exercisePlanDetail, exercisePlanDetail.exercisePlanDetailId);
|
||||
} else if (exercisePlanDetail.change == ModelChange.update) {
|
||||
await MockExercisePlanApi().updateExercisePlanDetail(exercisePlanDetail, exercisePlanDetail.exercisePlanDetailId);
|
||||
Cache().updateMyExercisePlanDetail(exercisePlanDetail);
|
||||
} else if ( exercisePlanDetail.change == ExercisePlanDetailChange.add ) {
|
||||
await MockExercisePlanApi()
|
||||
.saveExercisePlanDetail(exercisePlanDetail);
|
||||
} else if (exercisePlanDetail.change == ModelChange.add) {
|
||||
await MockExercisePlanApi().saveExercisePlanDetail(exercisePlanDetail);
|
||||
Cache().addToMyExercisePlanDetails(exercisePlanDetail);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user