mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-30 01:41:05 +01:00
Fix tests
This commit is contained in:
@@ -98,7 +98,6 @@ class WorkoutSessionTable extends Table {
|
||||
const PowersyncWorkoutSessionTable = ps.Table(
|
||||
'manager_workoutsession',
|
||||
[
|
||||
ps.Column.text('id'),
|
||||
ps.Column.integer('routine_id'),
|
||||
ps.Column.integer('day_id'),
|
||||
ps.Column.text('date'),
|
||||
|
||||
@@ -157,7 +157,7 @@ class Log {
|
||||
out.weightUnitObj = weightUnitObj;
|
||||
out.weightUnitId = weightUnitObj.id;
|
||||
}
|
||||
// out.exercise = exercise;
|
||||
out.exerciseObj = exerciseObj;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ final class WeightEntryNotifierProvider
|
||||
WeightEntryNotifier create() => WeightEntryNotifier();
|
||||
}
|
||||
|
||||
String _$weightEntryNotifierHash() => r'd7ebd22ba0ee1f4aa4b27367f921e4e4c6c7c619';
|
||||
String _$weightEntryNotifierHash() => r'c5cc65c04a047dc44bc02ae33ea45e76cd81894a';
|
||||
|
||||
abstract class _$WeightEntryNotifier extends $StreamNotifier<List<WeightEntry>> {
|
||||
Stream<List<WeightEntry>> build();
|
||||
|
||||
@@ -32,7 +32,7 @@ final class IngredientNotifierProvider extends $AsyncNotifierProvider<Ingredient
|
||||
IngredientNotifier create() => IngredientNotifier();
|
||||
}
|
||||
|
||||
String _$ingredientNotifierHash() => r'85cc77d8bdda350aecf85f6c3f20aaa391c13f0b';
|
||||
String _$ingredientNotifierHash() => r'746f1f3b19d2df68724a60e51bba69b67121f801';
|
||||
|
||||
abstract class _$IngredientNotifier extends $AsyncNotifier<void> {
|
||||
FutureOr<void> build();
|
||||
|
||||
@@ -33,7 +33,7 @@ final class MeasurementNotifierProvider
|
||||
MeasurementNotifier create() => MeasurementNotifier();
|
||||
}
|
||||
|
||||
String _$measurementNotifierHash() => r'6ed254d220689a83db007053f2bbbe69693f45f9';
|
||||
String _$measurementNotifierHash() => r'94978ed841f94d3481322dc144ef82da95cfb62c';
|
||||
|
||||
abstract class _$MeasurementNotifier extends $StreamNotifier<List<MeasurementCategory>> {
|
||||
Stream<List<MeasurementCategory>> build();
|
||||
|
||||
@@ -33,7 +33,7 @@ final class WorkoutLogNotifierProvider
|
||||
WorkoutLogNotifier create() => WorkoutLogNotifier();
|
||||
}
|
||||
|
||||
String _$workoutLogNotifierHash() => r'532917be5ce98bf849b8a16b401d89e934483e67';
|
||||
String _$workoutLogNotifierHash() => r'ecc623162bd8e9c315335cab649a671c9e15759e';
|
||||
|
||||
abstract class _$WorkoutLogNotifier extends $StreamNotifier<List<Log>> {
|
||||
Stream<List<Log>> build();
|
||||
|
||||
@@ -66,7 +66,7 @@ final class WorkoutSessionNotifierProvider
|
||||
WorkoutSessionNotifier create() => WorkoutSessionNotifier();
|
||||
}
|
||||
|
||||
String _$workoutSessionNotifierHash() => r'10a3dc311941aac5efa09e047f97bc1387ccd0ef';
|
||||
String _$workoutSessionNotifierHash() => r'bedc3970574da989a49286f24c9ad57e256eca7c';
|
||||
|
||||
abstract class _$WorkoutSessionNotifier extends $StreamNotifier<List<WorkoutSession>> {
|
||||
Stream<List<WorkoutSession>> build();
|
||||
|
||||
@@ -46,7 +46,7 @@ class EntriesList extends ConsumerWidget {
|
||||
.toList();
|
||||
final entries7dAvg = moving7dAverage(entriesAll);
|
||||
|
||||
final datetimeFormat = DateFormat.yMd(Localizations.localeOf(context).languageCode).add_Hm();
|
||||
final datetimeFormat = DateFormat.yMd(Localizations.localeOf(context).languageCode);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
|
||||
@@ -32,11 +32,13 @@ class SessionForm extends ConsumerStatefulWidget {
|
||||
final _logger = Logger('SessionForm');
|
||||
final WorkoutSession _session;
|
||||
final Function()? _onSaved;
|
||||
final bool _isNew;
|
||||
|
||||
static const SLIDER_START = -0.5;
|
||||
|
||||
SessionForm(int routineId, {Function()? onSaved, WorkoutSession? session, int? dayId})
|
||||
: _onSaved = onSaved,
|
||||
_isNew = session == null,
|
||||
_session =
|
||||
session ??
|
||||
WorkoutSession(
|
||||
@@ -250,7 +252,7 @@ class _SessionFormState extends ConsumerState<SessionForm> {
|
||||
|
||||
// Save the entry on the server
|
||||
try {
|
||||
if (widget._session.id == null) {
|
||||
if (widget._isNew) {
|
||||
widget._logger.fine('Adding new session');
|
||||
await sessionProvider.addEntry(widget._session);
|
||||
} else {
|
||||
|
||||
@@ -38,64 +38,47 @@ class SessionPage extends ConsumerStatefulWidget {
|
||||
}
|
||||
|
||||
class _SessionPageState extends ConsumerState<SessionPage> {
|
||||
late Future<void> _initData;
|
||||
List<WorkoutSession> sessions = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initData = _reloadRoutineData();
|
||||
}
|
||||
|
||||
Future<void> _reloadRoutineData() async {
|
||||
sessions = await ref.read(workoutSessionProvider.future);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final i18n = AppLocalizations.of(context);
|
||||
final gymState = ref.read(gymStateProvider);
|
||||
final sessionsAsync = ref.watch(workoutSessionProvider);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
NavigationHeader(i18n.workoutSession, widget._controller),
|
||||
Expanded(
|
||||
child: FutureBuilder<void>(
|
||||
future: _initData,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (snapshot.hasError) {
|
||||
return Center(child: Text('Error: ${snapshot.error}'));
|
||||
} else {
|
||||
final session = sessions.firstWhere(
|
||||
(s) => s.date.isSameDayAs(clock.now()) && s.routineId == gymState.routine.id,
|
||||
orElse: () => WorkoutSession(
|
||||
dayId: gymState.dayId,
|
||||
date: clock.now(),
|
||||
routineId: gymState.routine.id,
|
||||
timeStart: gymState.startTime,
|
||||
timeEnd: TimeOfDay.fromDateTime(clock.now()),
|
||||
),
|
||||
);
|
||||
child: sessionsAsync.when(
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, _) => Center(child: Text('Error: $error')),
|
||||
data: (sessions) {
|
||||
final session = sessions.firstWhere(
|
||||
(s) => s.date.isSameDayAs(clock.now()) && s.routineId == gymState.routine.id,
|
||||
orElse: () => WorkoutSession(
|
||||
dayId: gymState.dayId,
|
||||
date: clock.now(),
|
||||
routineId: gymState.routine.id,
|
||||
timeStart: gymState.startTime,
|
||||
timeEnd: TimeOfDay.fromDateTime(clock.now()),
|
||||
),
|
||||
);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(child: Container()),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15),
|
||||
child: SessionForm(
|
||||
gymState.routine.id!,
|
||||
onSaved: () => widget._controller.nextPage(
|
||||
duration: DEFAULT_ANIMATION_DURATION,
|
||||
curve: DEFAULT_ANIMATION_CURVE,
|
||||
),
|
||||
session: session,
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(child: Container()),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15),
|
||||
child: SessionForm(
|
||||
gymState.routine.id!,
|
||||
onSaved: () => widget._controller.nextPage(
|
||||
duration: DEFAULT_ANIMATION_DURATION,
|
||||
curve: DEFAULT_ANIMATION_CURVE,
|
||||
),
|
||||
session: session,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
@@ -22,6 +22,7 @@ import 'package:wger/helpers/date.dart';
|
||||
import 'package:wger/helpers/errors.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/models/workouts/routine.dart';
|
||||
import 'package:wger/providers/network_provider.dart';
|
||||
import 'package:wger/providers/trophies.dart';
|
||||
|
||||
import '../gym_mode/summary.dart';
|
||||
@@ -40,6 +41,7 @@ class DayLogWidget extends ConsumerWidget {
|
||||
final i18n = AppLocalizations.of(context);
|
||||
final theme = Theme.of(context);
|
||||
final trophyState = ref.read(trophyStateProvider);
|
||||
final isOnline = ref.watch(networkStatusProvider);
|
||||
|
||||
final session = _routine.sessions.firstWhere(
|
||||
(s) => s.date.isSameDayAs(_date),
|
||||
@@ -101,9 +103,11 @@ class DayLogWidget extends ConsumerWidget {
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
key: ValueKey('delete-log-${log.id}'),
|
||||
onPressed: () {
|
||||
showDeleteLogDialog(context, translation.name, log);
|
||||
},
|
||||
onPressed: isOnline
|
||||
? () {
|
||||
showDeleteLogDialog(context, translation.name, log);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -20,12 +20,17 @@ import 'package:clock/clock.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart' as riverpod;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
||||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/models/exercises/exercise.dart';
|
||||
import 'package:wger/models/workouts/routine.dart';
|
||||
import 'package:wger/models/workouts/session.dart';
|
||||
import 'package:wger/providers/exercise_data.dart';
|
||||
import 'package:wger/providers/routines.dart';
|
||||
import 'package:wger/providers/workout_session_repository.dart';
|
||||
import 'package:wger/screens/gym_mode.dart';
|
||||
import 'package:wger/screens/routine_screen.dart';
|
||||
import 'package:wger/widgets/routines/forms/repetitions.dart';
|
||||
@@ -40,6 +45,20 @@ import 'package:wger/widgets/routines/gym_mode/timer.dart';
|
||||
|
||||
import '../../../test_data/exercises.dart';
|
||||
import '../../../test_data/routines.dart';
|
||||
import 'gym_mode_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([WorkoutSessionRepository])
|
||||
class _FakeRoutinesRiverpod extends RoutinesRiverpod {
|
||||
_FakeRoutinesRiverpod(this._routine);
|
||||
|
||||
final Routine _routine;
|
||||
|
||||
@override
|
||||
RoutinesState build() => RoutinesState(routines: [_routine]);
|
||||
|
||||
@override
|
||||
Future<Routine> fetchAndSetRoutineFull(int routineId) async => _routine;
|
||||
}
|
||||
|
||||
void main() {
|
||||
final key = GlobalKey<NavigatorState>();
|
||||
@@ -47,15 +66,23 @@ void main() {
|
||||
final testRoutine = getTestRoutine();
|
||||
final testExercises = getTestExercises();
|
||||
|
||||
final mockSessionRepo = MockWorkoutSessionRepository();
|
||||
|
||||
setUp(() {
|
||||
SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty();
|
||||
when(mockSessionRepo.watchAllDrift()).thenAnswer(
|
||||
(_) => Stream<List<WorkoutSession>>.multi((controller) {
|
||||
controller.add(testRoutine.sessions);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
Widget renderGymMode({locale = 'en'}) {
|
||||
return riverpod.ProviderScope(
|
||||
overrides: [
|
||||
routinesRiverpodProvider.overrideWithValue(RoutinesState(routines: [testRoutine])),
|
||||
routinesRiverpodProvider.overrideWith(() => _FakeRoutinesRiverpod(testRoutine)),
|
||||
exercisesProvider.overrideWith((ref) => Stream<List<Exercise>>.value(<Exercise>[])),
|
||||
workoutSessionRepositoryProvider.overrideWithValue(mockSessionRepo),
|
||||
],
|
||||
child: MaterialApp(
|
||||
locale: Locale(locale),
|
||||
|
||||
@@ -43,6 +43,11 @@ void main() {
|
||||
setUp(() {
|
||||
testRoutine = getTestRoutine();
|
||||
mockRepository = MockWorkoutSessionRepository();
|
||||
when(mockRepository.watchAllDrift()).thenAnswer(
|
||||
(_) => Stream<List<WorkoutSession>>.multi((controller) {
|
||||
controller.add(testRoutine.sessions);
|
||||
}),
|
||||
);
|
||||
|
||||
container = ProviderContainer.test(
|
||||
overrides: [
|
||||
@@ -55,7 +60,7 @@ void main() {
|
||||
showTimerPages: true,
|
||||
dayId: 1,
|
||||
iteration: 1,
|
||||
routine: getTestRoutine(),
|
||||
routine: testRoutine,
|
||||
);
|
||||
notifier.calculatePages();
|
||||
when(mockRepository.editLocalDrift(any)).thenAnswer(
|
||||
|
||||
@@ -132,7 +132,7 @@ void main() {
|
||||
late Exercise exercise;
|
||||
|
||||
setUp(() {
|
||||
exercise = Exercise(id: 1);
|
||||
exercise = Exercise(id: 1, uuid: 'test-uuid', categoryId: 1);
|
||||
});
|
||||
|
||||
test('uses default unit IDs when unit objects are not loaded', () {
|
||||
|
||||
@@ -65,17 +65,14 @@ void main() {
|
||||
overrides: [
|
||||
networkStatusProvider.overrideWithValue(isOnline),
|
||||
workoutLogRepositoryProvider.overrideWithValue(mockWorkoutLogRepository),
|
||||
trophyRepositoryProvider.overrideWithValue(mockRepository),
|
||||
],
|
||||
);
|
||||
|
||||
container.read(routinesRiverpodProvider.notifier).state = RoutinesState(routines: [routine]);
|
||||
|
||||
return ProviderScope(
|
||||
overrides: [
|
||||
networkStatusProvider.overrideWithValue(isOnline),
|
||||
workoutLogRepositoryProvider.overrideWithValue(mockWorkoutLogRepository),
|
||||
trophyRepositoryProvider.overrideWithValue(mockRepository),
|
||||
],
|
||||
return UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
locale: Locale(locale),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
|
||||
Reference in New Issue
Block a user