wt1.1.2 new treeview, bar chart for muscle development
This commit is contained in:
@@ -0,0 +1,193 @@
|
||||
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/repository/workout_tree_repository.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'mocks.dart';
|
||||
|
||||
main() {
|
||||
SimExercisePlanRepository _exercisePlanRepository;
|
||||
ExercisePlanBloc bloc;
|
||||
|
||||
int _customerId;
|
||||
|
||||
Future<void> setUpPlan() async {
|
||||
final String planName2 = "Test Plan2";
|
||||
ExercisePlan plan2 = ExercisePlan(planName2, 101);
|
||||
_exercisePlanRepository.setCustomerId(101);
|
||||
_exercisePlanRepository.setExercisePlan(plan2);
|
||||
|
||||
ExercisePlanDetail detail3 = ExercisePlanDetail(3);
|
||||
detail3.repeats = 23;
|
||||
detail3.weightEquation = "60";
|
||||
detail3.serie = 4;
|
||||
|
||||
_exercisePlanRepository.setActualPlanDetail(detail3);
|
||||
_exercisePlanRepository.addDetailToPlan();
|
||||
|
||||
ExercisePlanDetail detail4 = ExercisePlanDetail(4);
|
||||
detail4.repeats = 12;
|
||||
detail4.weightEquation = "95";
|
||||
detail4.serie = 3;
|
||||
|
||||
_exercisePlanRepository.setActualPlanDetail(detail4);
|
||||
_exercisePlanRepository.addDetailToPlan();
|
||||
await _exercisePlanRepository.saveExercisePlan();
|
||||
}
|
||||
|
||||
setUp(() async {
|
||||
_exercisePlanRepository = SimExercisePlanRepository();
|
||||
WorkoutTreeRepository menuTreeRepository = WorkoutTreeRepository();
|
||||
bloc = ExercisePlanBloc(menuTreeRepository: menuTreeRepository);
|
||||
bloc.setExercisePlanRepository(_exercisePlanRepository);
|
||||
_customerId = 62;
|
||||
await setUpPlan();
|
||||
});
|
||||
|
||||
/*
|
||||
group('New Plan', () {
|
||||
test('Get Data', () async {
|
||||
});
|
||||
|
||||
test('Add bloc', () async {
|
||||
|
||||
});
|
||||
test('Update bloc', () async {
|
||||
|
||||
});
|
||||
test('Delete bloc', () async {
|
||||
|
||||
});
|
||||
|
||||
});*/
|
||||
|
||||
group('Existing Plan', () {
|
||||
test('Get Data', () async {
|
||||
bloc.customerId = 101;
|
||||
bloc.add(ExercisePlanLoad());
|
||||
|
||||
final expectedResponse = [
|
||||
ExercisePlanLoading(),
|
||||
ExercisePlanReady()
|
||||
];
|
||||
|
||||
expectLater(
|
||||
bloc,
|
||||
emitsInOrder(expectedResponse),
|
||||
).then((_) {
|
||||
expect(bloc.exercisePlanRepository.newPlan, false);
|
||||
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");
|
||||
});
|
||||
});
|
||||
|
||||
test('Add bloc', () async {
|
||||
bloc.customerId = 101;
|
||||
|
||||
bloc.exercisePlanRepository.getLastExercisePlan();
|
||||
bloc.exercisePlanRepository.getExercisePlanDetails();
|
||||
|
||||
ExercisePlanDetail detail4 = ExercisePlanDetail(5);
|
||||
detail4.repeats = 20;
|
||||
detail4.weightEquation = "55";
|
||||
detail4.serie = 3;
|
||||
|
||||
|
||||
|
||||
bloc.add(ExercisePlanAddExercise(exercisePlanDetail: detail4));
|
||||
|
||||
final expectedResponse2 = [
|
||||
ExercisePlanLoading(),
|
||||
ExercisePlanReady()
|
||||
];
|
||||
|
||||
expectLater(
|
||||
bloc,
|
||||
emitsInOrder(expectedResponse2),
|
||||
).then((_) {
|
||||
expect(bloc.exercisePlanRepository.newPlan, false);
|
||||
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(Cache().getMyExercisePlanDetails()[5].weightEquation, "55");
|
||||
expect(Cache().getMyExercisePlanDetails()[5].repeats, 20);
|
||||
});
|
||||
});
|
||||
test('Update bloc', () async {
|
||||
bloc.customerId = 101;
|
||||
|
||||
bloc.exercisePlanRepository.getLastExercisePlan();
|
||||
bloc.exercisePlanRepository.getExercisePlanDetails();
|
||||
bloc.exercisePlanRepository.exercisePlanDetails[3].repeats = 25;
|
||||
|
||||
bloc.add(ExercisePlanAddExercise(exercisePlanDetail: bloc.exercisePlanRepository.exercisePlanDetails[3]));
|
||||
|
||||
final expectedResponse2 = [
|
||||
ExercisePlanLoading(),
|
||||
ExercisePlanReady()
|
||||
];
|
||||
|
||||
expectLater(
|
||||
bloc,
|
||||
emitsInOrder(expectedResponse2),
|
||||
).then((_) {
|
||||
expect(bloc.exercisePlanRepository.newPlan, false);
|
||||
expect(bloc.exercisePlanRepository.exercisePlanDetails[3].repeats, 25);
|
||||
expect(Cache().getMyExercisePlanDetails()[3].repeats, 25);
|
||||
});
|
||||
|
||||
});
|
||||
test('Delete bloc', () async {
|
||||
bloc.customerId = 101;
|
||||
bloc.exercisePlanRepository.getLastExercisePlan();
|
||||
bloc.exercisePlanRepository.getExercisePlanDetails();
|
||||
bloc.add(ExercisePlanRemoveExercise(exercisePlanDetail: bloc.exercisePlanRepository.exercisePlanDetails[3]));
|
||||
|
||||
final expectedResponse2 = [
|
||||
ExercisePlanLoading(),
|
||||
ExercisePlanReady()
|
||||
];
|
||||
|
||||
expectLater(
|
||||
bloc,
|
||||
emitsInOrder(expectedResponse2),
|
||||
).then((_) {
|
||||
expect(bloc.exercisePlanRepository.newPlan, false);
|
||||
expect(bloc.exercisePlanRepository.exercisePlanDetails.length, 2);
|
||||
expect(bloc.exercisePlanRepository.exercisePlanDetails[3], isNull);
|
||||
expect(Cache().getMyExercisePlanDetails()[3], isNull);
|
||||
});
|
||||
});
|
||||
|
||||
test('Test Trainee', () async {
|
||||
/*bloc.customerId = 102;
|
||||
bloc.exercisePlanRepository.customerId = 102;
|
||||
|
||||
bloc.add(ExercisePlanLoad());
|
||||
|
||||
final expectedResponse = [
|
||||
ExercisePlanLoading(),
|
||||
ExercisePlanReady()
|
||||
];
|
||||
|
||||
|
||||
expectLater(
|
||||
bloc,
|
||||
emitsInOrder(expectedResponse),
|
||||
).then((_) {
|
||||
expect(bloc.exercisePlanRepository.newPlan, true);
|
||||
expect(bloc.exercisePlanRepository.exercisePlanDetails.length, 0);
|
||||
});*/
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
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:mockito/mockito.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);
|
||||
_exercisePlanRepository.setExercisePlan(plan2);
|
||||
|
||||
ExercisePlanDetail detail3 = ExercisePlanDetail(3);
|
||||
detail3.repeats = 23;
|
||||
detail3.weightEquation = "60";
|
||||
detail3.serie = 4;
|
||||
|
||||
_exercisePlanRepository.setActualPlanDetail(detail3);
|
||||
_exercisePlanRepository.addDetailToPlan();
|
||||
|
||||
ExercisePlanDetail detail4 = ExercisePlanDetail(4);
|
||||
detail4.repeats = 12;
|
||||
detail4.weightEquation = "95";
|
||||
detail4.serie = 3;
|
||||
|
||||
_exercisePlanRepository.setActualPlanDetail(detail4);
|
||||
_exercisePlanRepository.addDetailToPlan();
|
||||
await _exercisePlanRepository.saveExercisePlan();
|
||||
}
|
||||
|
||||
setUp(() async {
|
||||
_exercisePlanRepository = SimExercisePlanRepository();
|
||||
_customerId = 62;
|
||||
await setUpPlan();
|
||||
});
|
||||
|
||||
|
||||
|
||||
group('New Plan', () {
|
||||
test('add new plan and plan details and save', () async {
|
||||
final String planName = "Boss Test Plan";
|
||||
ExercisePlan plan = ExercisePlan(planName, _customerId);
|
||||
_exercisePlanRepository.setExercisePlan(plan);
|
||||
|
||||
ExercisePlanDetail detail1 = ExercisePlanDetail(37);
|
||||
detail1.repeats = 12;
|
||||
detail1.weightEquation = "80";
|
||||
detail1.serie = 4;
|
||||
|
||||
_exercisePlanRepository.setActualPlanDetail(detail1);
|
||||
_exercisePlanRepository.addDetailToPlan();
|
||||
|
||||
ExercisePlanDetail detail2 = ExercisePlanDetail(55);
|
||||
detail2.repeats = 13;
|
||||
detail2.weightEquation = "55";
|
||||
detail2.serie = 3;
|
||||
|
||||
_exercisePlanRepository.setActualPlanDetail(detail2);
|
||||
_exercisePlanRepository.addDetailToPlan();
|
||||
|
||||
await _exercisePlanRepository.saveExercisePlan();
|
||||
|
||||
expect(_exercisePlanRepository.getExercisePlan().name, planName);
|
||||
expect(_exercisePlanRepository.getExercisePlan().exercisePlanId > 0, true);
|
||||
|
||||
ExercisePlanDetail detail =
|
||||
_exercisePlanRepository.getExercisePlanDetailByExerciseId(55);
|
||||
expect(detail.exercisePlanId, _exercisePlanRepository.getExercisePlan().exercisePlanId);
|
||||
|
||||
|
||||
});
|
||||
test('save new plan and plan details second', () async {
|
||||
int customerId = 100;
|
||||
final String planName = "Boss2 Test Plan";
|
||||
ExercisePlan plan = ExercisePlan(planName, customerId);
|
||||
_exercisePlanRepository.setExercisePlan(plan);
|
||||
|
||||
ExercisePlanDetail detail1 = ExercisePlanDetail(12);
|
||||
detail1.repeats = 10;
|
||||
detail1.weightEquation = "40";
|
||||
detail1.serie = 5;
|
||||
|
||||
_exercisePlanRepository.setActualPlanDetail(detail1);
|
||||
_exercisePlanRepository.addDetailToPlan();
|
||||
|
||||
ExercisePlanDetail detail2 = ExercisePlanDetail(13);
|
||||
detail2.repeats = 33;
|
||||
detail2.weightEquation = "15";
|
||||
detail2.serie = 3;
|
||||
_exercisePlanRepository.setActualPlanDetail(detail2);
|
||||
_exercisePlanRepository.addDetailToPlan();
|
||||
|
||||
await _exercisePlanRepository.saveExercisePlan();
|
||||
|
||||
expect(_exercisePlanRepository.getExercisePlan().name, planName);
|
||||
expectLater(_exercisePlanRepository.getExercisePlan().exercisePlanId > 0, true);
|
||||
|
||||
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);
|
||||
|
||||
await _exercisePlanRepository.getExercisePlanDetails();
|
||||
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");
|
||||
});
|
||||
|
||||
test('Add new PlanDetail', () async {
|
||||
_exercisePlanRepository.newPlan = false;
|
||||
ExercisePlanDetail detail4 = ExercisePlanDetail(5);
|
||||
detail4.repeats = 6;
|
||||
detail4.weightEquation = "105";
|
||||
detail4.serie = 3;
|
||||
|
||||
_exercisePlanRepository.setActualPlanDetail(detail4);
|
||||
_exercisePlanRepository.addDetailToPlan();
|
||||
|
||||
await _exercisePlanRepository.saveExercisePlan();
|
||||
|
||||
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(Cache().getMyExercisePlanDetails()[4], isNull);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
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/repository/exercise_plan_repository.dart';
|
||||
import 'package:aitrainer_app/service/exercise_plan_service.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
class MockExercisePlanApi extends Mock implements ExercisePlanApi {
|
||||
static final MockExercisePlanApi _singleton = MockExercisePlanApi._internal();
|
||||
factory MockExercisePlanApi() {
|
||||
return _singleton;
|
||||
}
|
||||
|
||||
MockExercisePlanApi._internal() {}
|
||||
|
||||
final List<ExercisePlan> memoryExercisePlan = List();
|
||||
final List<ExercisePlanDetail> memoryExercisePlanDetail = List();
|
||||
|
||||
Future<ExercisePlan> saveExercisePlan(ExercisePlan plan) async {
|
||||
memoryExercisePlan.add(plan);
|
||||
plan.exercisePlanId = memoryExercisePlan.length;
|
||||
return plan;
|
||||
}
|
||||
|
||||
Future<ExercisePlanDetail> saveExercisePlanDetail(ExercisePlanDetail detail) async {
|
||||
memoryExercisePlanDetail.add(detail);
|
||||
detail.exercisePlanDetailId = memoryExercisePlanDetail.length;
|
||||
return detail;
|
||||
}
|
||||
|
||||
Future<ExercisePlanDetail> updateExercisePlanDetail(ExercisePlanDetail detail, int planDetailId) async {
|
||||
ExercisePlanDetail updated;
|
||||
memoryExercisePlanDetail.forEach((element) {
|
||||
if ( element.exercisePlanDetailId == planDetailId ) {
|
||||
element = detail;
|
||||
}
|
||||
});
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
Future<void> deleteExercisePlanDetail(int exercisePlanId) async {
|
||||
int index = -1;
|
||||
int countIndex = 0;
|
||||
memoryExercisePlanDetail.forEach((element) {
|
||||
if ( element.exercisePlanId == exercisePlanId ) {
|
||||
index = countIndex;
|
||||
}
|
||||
countIndex++;
|
||||
});
|
||||
if ( index > -1) {
|
||||
memoryExercisePlanDetail.removeAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<ExercisePlanDetail>> getExercisePlanDetail(int exercisePlanId) async {
|
||||
List<ExercisePlanDetail> foundList = List();
|
||||
memoryExercisePlanDetail.forEach((element) {
|
||||
if ( element.exercisePlanId == exercisePlanId ) {
|
||||
foundList.add(element);
|
||||
}
|
||||
});
|
||||
return foundList;
|
||||
}
|
||||
|
||||
Future<ExercisePlan> getLastExercisePlan(int customerId) async {
|
||||
ExercisePlan found;
|
||||
memoryExercisePlan.forEach((element) {
|
||||
if ( element.customerId == customerId ) {
|
||||
found = element;
|
||||
}
|
||||
});
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
class SimExercisePlanRepository with ExercisePlanRepository {
|
||||
|
||||
Future<void> getExercisePlanDetails() async {
|
||||
if (exercisePlan == null) {
|
||||
ExercisePlan exercisePlan = await this.getLastExercisePlan();
|
||||
if ( exercisePlan == null ) {
|
||||
exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
List<ExercisePlanDetail> list = List();
|
||||
LinkedHashMap<int, ExercisePlanDetail> listCache = Cache().getMyExercisePlanDetails();
|
||||
if ( listCache.length > 0) {
|
||||
exercisePlanDetails = listCache;
|
||||
return;
|
||||
} else {
|
||||
list = await MockExercisePlanApi().getExercisePlanDetail(exercisePlan.exercisePlanId);
|
||||
}
|
||||
|
||||
exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
|
||||
|
||||
list.forEach((element) {
|
||||
newPlan = false;
|
||||
ExercisePlanDetail detail = element;
|
||||
exercisePlanDetails[detail.exerciseTypeId] = detail;
|
||||
});
|
||||
Cache().setMyExercisePlanDetails(exercisePlanDetails);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Future<ExercisePlan> getLastExercisePlan() async {
|
||||
if ( customerId == 0) {
|
||||
return null;
|
||||
}
|
||||
ExercisePlan myExercisePlan = Cache().getMyExercisePlan();
|
||||
if ( myExercisePlan != null ) {
|
||||
newPlan = false;
|
||||
return myExercisePlan;
|
||||
}
|
||||
|
||||
exercisePlan = await MockExercisePlanApi().getLastExercisePlan(customerId);
|
||||
newPlan = (exercisePlan == null);
|
||||
Cache().setMyExercisePlan(exercisePlan);
|
||||
return exercisePlan;
|
||||
}
|
||||
|
||||
Future<void> saveExercisePlan() async {
|
||||
if ( exercisePlan == null ) {
|
||||
if ( Cache().userLoggedIn == null ) {
|
||||
throw Exception("please log in");
|
||||
}
|
||||
|
||||
String exercisePlanName;
|
||||
if ( this.customerId == Cache().userLoggedIn.customerId) {
|
||||
exercisePlanName = Cache().userLoggedIn.name + " private";
|
||||
} else {
|
||||
exercisePlanName = Cache().getTrainee().name + " " + Cache().getTrainee().firstname + " private";
|
||||
}
|
||||
|
||||
exercisePlan = ExercisePlan(exercisePlanName, this.customerId);
|
||||
}
|
||||
if ( newPlan ) {
|
||||
exercisePlan.dateAdd = DateTime.now();
|
||||
exercisePlan.private = true;
|
||||
|
||||
ExercisePlan savedExercisePlan
|
||||
= await MockExercisePlanApi().saveExercisePlan(exercisePlan);
|
||||
|
||||
|
||||
LinkedHashMap<int, ExercisePlanDetail> savedExercisePlanDetails = LinkedHashMap();
|
||||
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
|
||||
exercisePlanDetail.exercisePlanId = savedExercisePlan.exercisePlanId;
|
||||
|
||||
ExercisePlanDetail savedDetail = await MockExercisePlanApi().saveExercisePlanDetail(exercisePlanDetail);
|
||||
|
||||
savedExercisePlanDetails[savedDetail.exerciseTypeId] = savedDetail;
|
||||
});
|
||||
|
||||
exercisePlan = savedExercisePlan;
|
||||
} else {
|
||||
|
||||
await MockExercisePlanApi().updateExercisePlan(exercisePlan, exercisePlan.exercisePlanId);
|
||||
|
||||
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
|
||||
if ( exercisePlanDetail.change == ExercisePlanDetailChange.delete ) {
|
||||
await MockExercisePlanApi()
|
||||
.deleteExercisePlanDetail(exercisePlanDetail.exercisePlanDetailId);
|
||||
Cache().deleteMyExercisePlanDetail(exercisePlanDetail);
|
||||
} else if ( exercisePlanDetail.change == ExercisePlanDetailChange.update ) {
|
||||
await MockExercisePlanApi()
|
||||
.updateExercisePlanDetail(exercisePlanDetail, exercisePlanDetail.exercisePlanDetailId);
|
||||
Cache().updateMyExercisePlanDetail(exercisePlanDetail);
|
||||
} else if ( exercisePlanDetail.change == ExercisePlanDetailChange.add ) {
|
||||
await MockExercisePlanApi()
|
||||
.saveExercisePlanDetail(exercisePlanDetail);
|
||||
Cache().addToMyExercisePlanDetails(exercisePlanDetail);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user