mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-05 23:44:02 +01:00
Fix more small issues found in the sweep
This commit is contained in:
@@ -64,10 +64,8 @@ Future<List<Ingredient>> searchedIngredients(Ref ref) async {
|
||||
// If the filters change again (or the provider is disposed) before the
|
||||
// delay elapses, abort this run so we don't fire a request for an
|
||||
// intermediate keystroke.
|
||||
var disposed = false;
|
||||
ref.onDispose(() => disposed = true);
|
||||
await Future.delayed(_searchDebounce);
|
||||
if (disposed) {
|
||||
if (!ref.mounted) {
|
||||
throw StateError('search debounced');
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ class NutritionalPlansList extends riverpod.ConsumerWidget {
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'${AppLocalizations.of(context).weight} change: ',
|
||||
'${AppLocalizations.of(context).weightChangeLabel} ',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
Text(
|
||||
@@ -142,6 +142,7 @@ class NutritionalPlansList extends riverpod.ConsumerWidget {
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
itemCount: plans.length,
|
||||
itemBuilder: (context, index) {
|
||||
final i18n = AppLocalizations.of(context);
|
||||
final currentPlan = plans[index];
|
||||
return Card(
|
||||
child: ListTile(
|
||||
@@ -157,8 +158,11 @@ class NutritionalPlansList extends riverpod.ConsumerWidget {
|
||||
children: [
|
||||
Text(
|
||||
currentPlan.endDate != null
|
||||
? 'from ${localizedDate(context).format(currentPlan.startDate)} to ${localizedDate(context).format(currentPlan.endDate!)}'
|
||||
: 'from ${localizedDate(context).format(currentPlan.startDate)} (open ended)',
|
||||
? i18n.planDateRange(
|
||||
localizedDate(context).format(currentPlan.startDate),
|
||||
localizedDate(context).format(currentPlan.endDate!),
|
||||
)
|
||||
: '${i18n.planStartDate(localizedDate(context).format(currentPlan.startDate))} (${i18n.openEnded})',
|
||||
),
|
||||
_buildWeightChangeInfo(
|
||||
context,
|
||||
|
||||
@@ -100,7 +100,7 @@ class _ReorderableDaysListState extends ConsumerState<ReorderableDaysList> {
|
||||
),
|
||||
);
|
||||
},
|
||||
onReorderItem: (int oldIndex, int newIndex) {
|
||||
onReorderItem: (int oldIndex, int newIndex) async {
|
||||
setState(() {
|
||||
final Day item = widget.days.removeAt(oldIndex);
|
||||
widget.days.insert(newIndex, item);
|
||||
@@ -111,12 +111,14 @@ class _ReorderableDaysListState extends ConsumerState<ReorderableDaysList> {
|
||||
});
|
||||
|
||||
try {
|
||||
provider.editDays(widget.days);
|
||||
setState(() {
|
||||
errorMessage = const SizedBox.shrink();
|
||||
});
|
||||
await provider.editDays(widget.days);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
errorMessage = const SizedBox.shrink();
|
||||
});
|
||||
}
|
||||
} on WgerHttpException catch (error) {
|
||||
if (context.mounted) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
errorMessage = FormHttpErrorsWidget(error);
|
||||
});
|
||||
|
||||
@@ -41,27 +41,13 @@ class RoutineForm extends ConsumerStatefulWidget {
|
||||
class _RoutineFormState extends ConsumerState<RoutineForm> {
|
||||
final _form = GlobalKey<FormState>();
|
||||
|
||||
late bool fitInWeek;
|
||||
late DateTime startDate;
|
||||
late DateTime endDate;
|
||||
final workoutNameController = TextEditingController();
|
||||
final workoutDescriptionController = TextEditingController();
|
||||
/// Editable copy of the routine; the passed-in one is never mutated
|
||||
late Routine _draft;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
fitInWeek = widget._routine.fitInWeek;
|
||||
workoutNameController.text = widget._routine.name;
|
||||
workoutDescriptionController.text = widget._routine.description;
|
||||
startDate = widget._routine.start;
|
||||
endDate = widget._routine.end;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
workoutNameController.dispose();
|
||||
workoutDescriptionController.dispose();
|
||||
super.dispose();
|
||||
_draft = widget._routine.copyWith();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -73,7 +59,7 @@ class _RoutineFormState extends ConsumerState<RoutineForm> {
|
||||
TextFormField(
|
||||
key: const Key('field-name'),
|
||||
decoration: InputDecoration(labelText: i18n.name),
|
||||
controller: workoutNameController,
|
||||
initialValue: _draft.name,
|
||||
validator: (value) {
|
||||
if (value!.isEmpty ||
|
||||
value.length < Routine.MIN_LENGTH_NAME ||
|
||||
@@ -86,7 +72,7 @@ class _RoutineFormState extends ConsumerState<RoutineForm> {
|
||||
return null;
|
||||
},
|
||||
onSaved: (newValue) {
|
||||
widget._routine.name = newValue!;
|
||||
_draft = _draft.copyWith(name: newValue);
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
@@ -94,7 +80,7 @@ class _RoutineFormState extends ConsumerState<RoutineForm> {
|
||||
decoration: InputDecoration(labelText: i18n.description),
|
||||
minLines: 3,
|
||||
maxLines: 10,
|
||||
controller: workoutDescriptionController,
|
||||
initialValue: _draft.description,
|
||||
validator: (value) {
|
||||
if (value!.length > Routine.MAX_LENGTH_DESCRIPTION) {
|
||||
return i18n.enterCharacters(
|
||||
@@ -105,22 +91,23 @@ class _RoutineFormState extends ConsumerState<RoutineForm> {
|
||||
return null;
|
||||
},
|
||||
onSaved: (newValue) {
|
||||
widget._routine.description = newValue!;
|
||||
_draft = _draft.copyWith(description: newValue);
|
||||
},
|
||||
),
|
||||
DateInputWidget(
|
||||
key: const Key('field-start-date'),
|
||||
value: startDate,
|
||||
value: _draft.start,
|
||||
labelText: i18n.startDate,
|
||||
firstDate: DateTime.now().subtract(const Duration(days: 365)),
|
||||
lastDate: DateTime.now().add(const Duration(days: 365)),
|
||||
onChanged: (picked) {
|
||||
widget._routine.start = picked;
|
||||
setState(() {
|
||||
startDate = picked;
|
||||
_draft = _draft.copyWith(start: picked);
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
final startDate = _draft.start;
|
||||
final endDate = _draft.end;
|
||||
final rangeError = validateDateRange(startDate, endDate, i18n);
|
||||
if (rangeError != null) {
|
||||
return rangeError;
|
||||
@@ -136,14 +123,13 @@ class _RoutineFormState extends ConsumerState<RoutineForm> {
|
||||
),
|
||||
DateInputWidget(
|
||||
key: const Key('field-end-date'),
|
||||
value: endDate,
|
||||
value: _draft.end,
|
||||
labelText: i18n.endDate,
|
||||
firstDate: DateTime.now().subtract(const Duration(days: 365)),
|
||||
lastDate: DateTime.now().add(const Duration(days: 365)),
|
||||
onChanged: (picked) {
|
||||
widget._routine.end = picked;
|
||||
setState(() {
|
||||
endDate = picked;
|
||||
_draft = _draft.copyWith(end: picked);
|
||||
});
|
||||
},
|
||||
),
|
||||
@@ -152,19 +138,16 @@ class _RoutineFormState extends ConsumerState<RoutineForm> {
|
||||
title: Text(i18n.fitInWeek),
|
||||
subtitle: Text(i18n.fitInWeekHelp),
|
||||
isThreeLine: true,
|
||||
value: widget._routine.fitInWeek,
|
||||
value: _draft.fitInWeek,
|
||||
contentPadding: const EdgeInsets.all(4),
|
||||
onChanged: (bool? value) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
widget._routine.fitInWeek = value;
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
fitInWeek = value;
|
||||
});
|
||||
}
|
||||
setState(() {
|
||||
_draft = _draft.copyWith(fitInWeek: value);
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
@@ -172,7 +155,7 @@ class _RoutineFormState extends ConsumerState<RoutineForm> {
|
||||
// existing one syncs through PowerSync and works offline.
|
||||
FormSubmitButton(
|
||||
key: const Key(SUBMIT_BUTTON_KEY_NAME),
|
||||
enabled: !(widget._routine.id == null && !isOnline),
|
||||
enabled: !(_draft.id == null && !isOnline),
|
||||
label: AppLocalizations.of(context).save,
|
||||
onPressed: () async {
|
||||
// Validate and save
|
||||
@@ -183,10 +166,10 @@ class _RoutineFormState extends ConsumerState<RoutineForm> {
|
||||
_form.currentState!.save();
|
||||
|
||||
final routinesProvider = ref.read(routinesRiverpodProvider.notifier);
|
||||
if (widget._routine.id != null) {
|
||||
await routinesProvider.editRoutine(widget._routine);
|
||||
if (_draft.id != null) {
|
||||
await routinesProvider.editRoutine(_draft);
|
||||
} else {
|
||||
final routine = await routinesProvider.addRoutine(widget._routine);
|
||||
final routine = await routinesProvider.addRoutine(_draft);
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pushReplacementNamed(
|
||||
RoutineEditScreen.routeName,
|
||||
|
||||
@@ -361,7 +361,7 @@ class _SlotFormWidgetStateNg extends ConsumerState<ReorderableSlotList> {
|
||||
child: cardChild,
|
||||
);
|
||||
},
|
||||
onReorderItem: (int oldIndex, int newIndex) {
|
||||
onReorderItem: (int oldIndex, int newIndex) async {
|
||||
setState(() {
|
||||
// Update the order of slots in your data source
|
||||
final item = widget.slots.removeAt(oldIndex);
|
||||
@@ -370,20 +370,22 @@ class _SlotFormWidgetStateNg extends ConsumerState<ReorderableSlotList> {
|
||||
for (int i = 0; i < widget.slots.length; i++) {
|
||||
widget.slots[i].order = i + 1;
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
provider.editSlots(widget.slots, widget.day.routineId);
|
||||
try {
|
||||
await provider.editSlots(widget.slots, widget.day.routineId);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
errorMessage = const SizedBox.shrink();
|
||||
});
|
||||
} on WgerHttpException catch (error) {
|
||||
if (context.mounted) {
|
||||
setState(() {
|
||||
errorMessage = FormHttpErrorsWidget(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
} on WgerHttpException catch (error) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
errorMessage = FormHttpErrorsWidget(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
if (!widget.day.isRest)
|
||||
|
||||
@@ -573,6 +573,10 @@
|
||||
"startDate": { "type": "String" }
|
||||
}
|
||||
},
|
||||
"weightChangeLabel": "Weight change:",
|
||||
"@weightChangeLabel": {
|
||||
"description": "Label in the list of nutritional plans, followed by the body weight change (e.g. '+1.5 kg') over the plan's period"
|
||||
},
|
||||
"otherLogs": "Other logs",
|
||||
"@otherLogs": {
|
||||
"description": "Other unassigned logs. Label for the pseudo-meal section that groups all nutritional diary entries not assigned to a specific meal"
|
||||
|
||||
@@ -280,17 +280,28 @@ void main() {
|
||||
expect(wizardState(tester).category, testCategoryArms);
|
||||
});
|
||||
|
||||
testWidgets('Form contains multiple selection fields', (tester) async {
|
||||
testWidgets('Picking a primary muscle stores it in the wizard state', (tester) async {
|
||||
setTrustworthy(true);
|
||||
await tester.pumpWidget(createExerciseScreen());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(Stepper), findsOneWidget);
|
||||
// The dialog comes from multi_select_flutter, an SDK-Material package
|
||||
final button = find.descendant(
|
||||
of: find.byKey(const Key('primary-muscles-multiselect')),
|
||||
matching: find.text(l10nOf(tester).muscles),
|
||||
);
|
||||
await tester.ensureVisible(button);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(button);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.textContaining('Biceps brachii'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('OK'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final stepper = tester.widget<Stepper>(find.byType(Stepper));
|
||||
expect(stepper.steps.length, equals(6));
|
||||
|
||||
expect(find.byType(TextFormField), findsWidgets);
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(wizardState(tester).primaryMuscles, [tMuscle2]);
|
||||
expect(wizardState(tester).secondaryMuscles, isEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import 'package:wger/features/nutrition/providers/nutrition_repository.dart';
|
||||
import 'package:wger/features/nutrition/screens/nutritional_plans_screen.dart';
|
||||
import 'package:wger/features/nutrition/widgets/forms.dart';
|
||||
|
||||
import '../../../../test_data/body_weight.dart';
|
||||
import '../../../helpers/fake_connectivity.dart';
|
||||
import '../../../helpers/measurement_repository_stubs.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
@@ -187,17 +188,45 @@ void main() {
|
||||
await tester.pumpWidget(createHomeScreen());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// note .. "(open ended)" at the time, depending on localisation strings
|
||||
expect(find.textContaining('from 1/1/2021 ('), findsOneWidget);
|
||||
expect(find.textContaining('from 1/10/2021 ('), findsOneWidget);
|
||||
expect(find.text('from 1/1/2021 (Open ended)'), findsOneWidget);
|
||||
expect(find.text('from 1/10/2021 (Open ended)'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Tests the localization of dates - DE', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createHomeScreen(locale: 'de'));
|
||||
await tester.pumpAndSettle();
|
||||
// note .. "(open ended)" at the time, depending on localisation strings
|
||||
|
||||
expect(find.textContaining('from 1.1.2021 ('), findsOneWidget);
|
||||
expect(find.textContaining('from 10.1.2021 ('), findsOneWidget);
|
||||
expect(find.text('ab 1.1.2021 (Offenes Ende)'), findsOneWidget);
|
||||
expect(find.text('ab 10.1.2021 (Offenes Ende)'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('A plan with an end date shows the date range', (WidgetTester tester) async {
|
||||
when(mockNutritionRepo.watchAllDrift()).thenAnswer(
|
||||
(_) => Stream.value([
|
||||
NutritionalPlan(
|
||||
id: planUuid1,
|
||||
description: 'test plan 1',
|
||||
creationDate: DateTime(2021, 01, 01),
|
||||
startDate: DateTime(2021, 01, 01),
|
||||
endDate: DateTime(2021, 03, 31),
|
||||
),
|
||||
]),
|
||||
);
|
||||
await tester.pumpWidget(createHomeScreen(locale: 'de'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('von 1.1.2021 bis 31.3.2021'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Shows the body weight change over the plan', (WidgetTester tester) async {
|
||||
stubMeasurementReads(
|
||||
mockMeasurementRepository,
|
||||
[getBodyWeightCategory()],
|
||||
bodyWeightEntries(),
|
||||
);
|
||||
await tester.pumpWidget(createHomeScreen());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Weight change: '), findsWidgets);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:wger/core/consts.dart';
|
||||
import 'package:wger/core/error_dialogs.dart';
|
||||
import 'package:wger/core/exceptions/http_exception.dart';
|
||||
import 'package:wger/core/network/network_provider.dart';
|
||||
import 'package:wger/core/widgets/form_submit_button.dart';
|
||||
import 'package:wger/features/routines/models/day.dart';
|
||||
@@ -128,4 +130,42 @@ void main() {
|
||||
verifyNever(mockRoutinesRepository.editDayServer(any));
|
||||
});
|
||||
});
|
||||
|
||||
group('ReorderableDaysList', () {
|
||||
testWidgets('shows the server error when saving the new order fails', (tester) async {
|
||||
when(
|
||||
mockRoutinesRepository.editDayServer(any),
|
||||
).thenThrow(WgerHttpException.fromMap({'order': 'reorder rejected'}));
|
||||
final days = getTestRoutine().days;
|
||||
|
||||
await tester.pumpWidget(
|
||||
testApp(
|
||||
Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: ReorderableDaysList(
|
||||
routineId: 1,
|
||||
days: days,
|
||||
selectedDayId: null,
|
||||
onDaySelected: (_) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
overrides: [
|
||||
routinesRepositoryProvider.overrideWithValue(mockRoutinesRepository),
|
||||
networkStatusProvider.overrideWithValue(true),
|
||||
...routineFormAmbientOverrides(),
|
||||
],
|
||||
locale: const Locale('en'),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(FormHttpErrorsWidget), findsNothing);
|
||||
|
||||
tester.widget<ReorderableListView>(find.byType(ReorderableListView)).onReorderItem!(0, 1);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FormHttpErrorsWidget), findsOne);
|
||||
expect(find.textContaining('reorder rejected'), findsOne);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import 'package:mockito/mockito.dart';
|
||||
import 'package:wger/core/consts.dart';
|
||||
import 'package:wger/core/exceptions/http_exception.dart';
|
||||
import 'package:wger/core/network/network_provider.dart';
|
||||
import 'package:wger/core/widgets/datetime_input.dart';
|
||||
import 'package:wger/core/widgets/form_submit_button.dart';
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart';
|
||||
import 'package:wger/features/exercises/models/exercise.dart';
|
||||
@@ -181,6 +182,61 @@ void main() {
|
||||
//expect(find.text(('New description')), findsOneWidget, reason: 'Workout plan detail page');
|
||||
});
|
||||
|
||||
testWidgets('Leaving the form without saving leaves the passed-in routine untouched', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
await tester.pumpWidget(renderWidget(existingRoutine));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.enterText(find.byKey(const Key('field-name')), 'Renamed routine');
|
||||
await tester.enterText(find.byKey(const Key('field-description')), 'New description');
|
||||
tester
|
||||
.widget<DateInputWidget>(find.byKey(const Key('field-start-date')))
|
||||
.onChanged(DateTime(2024, 11, 10));
|
||||
tester
|
||||
.widget<DateInputWidget>(find.byKey(const Key('field-end-date')))
|
||||
.onChanged(DateTime(2025, 2, 1));
|
||||
await tester.tap(find.byType(SwitchListTile));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Leave the form without saving
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
|
||||
verifyNever(mockRoutinesRepository.editLocalDrift(any));
|
||||
expect(existingRoutine.name, 'test 1');
|
||||
expect(existingRoutine.description, 'description 1');
|
||||
expect(existingRoutine.start, DateTime(2024, 11, 1));
|
||||
expect(existingRoutine.end, DateTime(2024, 12, 1));
|
||||
expect(existingRoutine.fitInWeek, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('Saving sends the edited dates and fit-in-week flag', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(renderWidget(existingRoutine));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
tester
|
||||
.widget<DateInputWidget>(find.byKey(const Key('field-start-date')))
|
||||
.onChanged(DateTime(2024, 11, 10));
|
||||
tester
|
||||
.widget<DateInputWidget>(find.byKey(const Key('field-end-date')))
|
||||
.onChanged(DateTime(2025, 2, 1));
|
||||
await tester.tap(find.byType(SwitchListTile));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)));
|
||||
|
||||
final saved =
|
||||
verify(mockRoutinesRepository.editLocalDrift(captureAny)).captured.single as Routine;
|
||||
expect(saved.id, 1);
|
||||
expect(saved.name, 'test 1');
|
||||
expect(saved.start, DateTime(2024, 11, 10));
|
||||
expect(saved.end, DateTime(2025, 2, 1));
|
||||
expect(saved.fitInWeek, isTrue);
|
||||
|
||||
// The save works on a copy, the passed-in routine stays as it was
|
||||
expect(existingRoutine.start, DateTime(2024, 11, 1));
|
||||
expect(existingRoutine.fitInWeek, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('Test editing an existing routine - server error', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
when(mockRoutinesRepository.editLocalDrift(any)).thenThrow(
|
||||
|
||||
@@ -21,6 +21,8 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:wger/core/error_dialogs.dart';
|
||||
import 'package:wger/core/exceptions/http_exception.dart';
|
||||
import 'package:wger/core/network/network_provider.dart';
|
||||
import 'package:wger/features/routines/models/slot.dart';
|
||||
import 'package:wger/features/routines/models/slot_entry.dart';
|
||||
@@ -348,6 +350,26 @@ void main() {
|
||||
).called(1);
|
||||
});
|
||||
|
||||
testWidgets('shows the server error when saving the new order fails', (tester) async {
|
||||
when(
|
||||
mockRepo.editSlotServer(any),
|
||||
).thenThrow(WgerHttpException.fromMap({'order': 'reorder rejected'}));
|
||||
final slot1 = Slot.withData(id: 1, day: day.id, order: 1);
|
||||
slot1.entries.add(day.slots[0].entries[0]);
|
||||
final slot2 = Slot.withData(id: 2, day: day.id, order: 2);
|
||||
slot2.entries.add(day.slots[1].entries[0]);
|
||||
|
||||
await tester.pumpWidget(buildWidget([slot1, slot2]));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(FormHttpErrorsWidget), findsNothing);
|
||||
|
||||
tester.widget<ReorderableListView>(find.byType(ReorderableListView)).onReorderItem!(0, 1);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FormHttpErrorsWidget), findsOne);
|
||||
expect(find.textContaining('reorder rejected'), findsOne);
|
||||
});
|
||||
|
||||
testWidgets('"Add Set" button only appears on the last slot of a group', (tester) async {
|
||||
final benchEntry = day.slots[0].entries[0];
|
||||
final slot1 = Slot.withData(id: 1, day: day.id, order: 1);
|
||||
|
||||
@@ -20,6 +20,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_riverpod/misc.dart' show Override;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:wger/core/widgets/legacy_material_scope.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
@@ -28,7 +29,8 @@ import 'package:wger/l10n/localizations_delegates.dart';
|
||||
///
|
||||
/// Pass [container] to share a [ProviderContainer] the test reads from or
|
||||
/// seeds itself (wrapped in an [UncontrolledProviderScope]); otherwise a
|
||||
/// [ProviderScope] with [overrides] is built. [locale] null follows the test
|
||||
/// [ProviderScope] with [overrides] is built. Like the app, it wraps the
|
||||
/// navigator in a [LegacyMaterialScope]. [locale] null follows the test
|
||||
/// platform, as a plain [MaterialApp] does. [home] may be null when [routes]
|
||||
/// or [initialRoute] decide what is shown.
|
||||
Widget testApp(
|
||||
@@ -53,6 +55,9 @@ Widget testApp(
|
||||
initialRoute: initialRoute,
|
||||
routes: routes,
|
||||
home: home,
|
||||
// As in main.dart: routes pushed by SDK-Material packages (dialogs of
|
||||
// multi_select_flutter, ...) need the bridge above the navigator
|
||||
builder: (context, child) => LegacyMaterialScope(ink: false, child: child!),
|
||||
);
|
||||
|
||||
return container != null
|
||||
|
||||
Reference in New Issue
Block a user