Convert the reps and weight log widgets back to stateful.

This solves some problems with the keyboard focus changing or the quick-add
buttons for reps and weight. Also, add some tests for these.
This commit is contained in:
Roland Geider
2026-01-29 17:43:31 +01:00
parent 330ad382a4
commit f06a15ebac
2 changed files with 211 additions and 25 deletions

View File

@@ -237,5 +237,125 @@ void main() {
expect(capturedLog!.routineId, equals(notifier.state.routine.id));
expect(capturedLog!.iteration, equals(notifier.state.iteration));
});
testWidgets('LogsRepsWidget quick buttons update values', (tester) async {
// Arrange
final notifier = container.read(gymStateProvider.notifier);
final routine = testdata.getTestRoutine();
routine.dayDataGym[0].slots[0].setConfigs[0].repetitions = 0;
notifier.state = notifier.state.copyWith(
dayId: routine.days.first.id,
routine: routine,
iteration: 1,
);
notifier.calculatePages();
notifier.setCurrentPage(2);
notifier.state = notifier.state.copyWith(currentPage: 2);
final mockRoutines = MockRoutinesProvider();
await pumpLogPage(tester, routinesProvider: mockRoutines);
// Act
final repsWidgetFinder = find.byKey(const ValueKey('logs-reps-widget'));
expect(repsWidgetFinder, findsOneWidget);
final addBtn = find.descendant(
of: repsWidgetFinder,
matching: find.byIcon(Icons.add),
);
final removeBtn = find.descendant(
of: repsWidgetFinder,
matching: find.byIcon(Icons.remove),
);
// Assert
// Increment 0 -> 1
await tester.tap(addBtn);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await tester.pumpAndSettle();
expect(
find.descendant(of: repsWidgetFinder, matching: find.text('1')),
findsOneWidget,
);
// Increment 1 -> 2
await tester.tap(addBtn);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await tester.pumpAndSettle();
expect(
find.descendant(of: repsWidgetFinder, matching: find.text('2')),
findsOneWidget,
);
// Decrement 2 -> 1
await tester.tap(removeBtn);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await tester.pumpAndSettle();
expect(
find.descendant(of: repsWidgetFinder, matching: find.text('1')),
findsOneWidget,
);
});
testWidgets('LogsWeightWidget quick buttons update values', (tester) async {
// Arrange
final notifier = container.read(gymStateProvider.notifier);
final routine = testdata.getTestRoutine();
routine.dayDataGym[0].slots[0].setConfigs[0].weight = 0;
notifier.state = notifier.state.copyWith(
dayId: routine.days.first.id,
routine: routine,
iteration: 1,
);
notifier.calculatePages();
notifier.setCurrentPage(2);
notifier.state = notifier.state.copyWith(currentPage: 2);
final mockRoutines = MockRoutinesProvider();
await pumpLogPage(tester, routinesProvider: mockRoutines);
// Act
final weightWidgetFinder = find.byKey(const ValueKey('logs-weight-widget'));
expect(weightWidgetFinder, findsOneWidget);
final addBtn = find.descendant(
of: weightWidgetFinder,
matching: find.byIcon(Icons.add),
);
final removeBtn = find.descendant(
of: weightWidgetFinder,
matching: find.byIcon(Icons.remove),
);
// Assert
// Increment 0 -> 1.25
await tester.tap(addBtn);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await tester.pumpAndSettle();
expect(
find.descendant(of: weightWidgetFinder, matching: find.text('1.25')),
findsOneWidget,
);
// Increment 1.25 -> 2.5
await tester.tap(addBtn);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await tester.pumpAndSettle();
expect(
find.descendant(of: weightWidgetFinder, matching: find.text('2.5')),
findsOneWidget,
);
// Decrement 2.5 -> 1.25
await tester.tap(removeBtn);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await tester.pumpAndSettle();
expect(
find.descendant(of: weightWidgetFinder, matching: find.text('1.25')),
findsOneWidget,
);
});
});
}