-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
244 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:random_workout/providers/app_state.dart'; | ||
// import 'package:random_workout/models/exercise.dart'; | ||
|
||
@GenerateNiceMocks([MockSpec<AppState>()]) | ||
void main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Mocks generated by Mockito 5.4.4 from annotations | ||
// in random_workout/test/mocks/mock_app_state.dart. | ||
// Do not manually edit this file. | ||
|
||
// ignore_for_file: no_leading_underscores_for_library_prefixes | ||
import 'dart:ui' as _i4; | ||
|
||
import 'package:mockito/mockito.dart' as _i1; | ||
import 'package:random_workout/models/exercise.dart' as _i3; | ||
import 'package:random_workout/providers/app_state.dart' as _i2; | ||
|
||
// ignore_for_file: type=lint | ||
// ignore_for_file: avoid_redundant_argument_values | ||
// ignore_for_file: avoid_setters_without_getters | ||
// ignore_for_file: comment_references | ||
// ignore_for_file: deprecated_member_use | ||
// ignore_for_file: deprecated_member_use_from_same_package | ||
// ignore_for_file: implementation_imports | ||
// ignore_for_file: invalid_use_of_visible_for_testing_member | ||
// ignore_for_file: prefer_const_constructors | ||
// ignore_for_file: unnecessary_parenthesis | ||
// ignore_for_file: camel_case_types | ||
// ignore_for_file: subtype_of_sealed_class | ||
|
||
/// A class which mocks [AppState]. | ||
/// | ||
/// See the documentation for Mockito's code generation for more information. | ||
class MockAppState extends _i1.Mock implements _i2.AppState { | ||
@override | ||
bool get isDarkMode => (super.noSuchMethod( | ||
Invocation.getter(#isDarkMode), | ||
returnValue: false, | ||
returnValueForMissingStub: false, | ||
) as bool); | ||
|
||
@override | ||
List<_i3.Exercise> get currentWorkout => (super.noSuchMethod( | ||
Invocation.getter(#currentWorkout), | ||
returnValue: <_i3.Exercise>[], | ||
returnValueForMissingStub: <_i3.Exercise>[], | ||
) as List<_i3.Exercise>); | ||
|
||
@override | ||
bool get hasListeners => (super.noSuchMethod( | ||
Invocation.getter(#hasListeners), | ||
returnValue: false, | ||
returnValueForMissingStub: false, | ||
) as bool); | ||
|
||
@override | ||
void toggleTheme() => super.noSuchMethod( | ||
Invocation.method( | ||
#toggleTheme, | ||
[], | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
|
||
@override | ||
void generateWorkout(_i3.ExerciseCategory? category) => super.noSuchMethod( | ||
Invocation.method( | ||
#generateWorkout, | ||
[category], | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
|
||
@override | ||
void removeExercise(int? index) => super.noSuchMethod( | ||
Invocation.method( | ||
#removeExercise, | ||
[index], | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
|
||
@override | ||
void addExercise(_i3.Exercise? exercise) => super.noSuchMethod( | ||
Invocation.method( | ||
#addExercise, | ||
[exercise], | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
|
||
@override | ||
void addListener(_i4.VoidCallback? listener) => super.noSuchMethod( | ||
Invocation.method( | ||
#addListener, | ||
[listener], | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
|
||
@override | ||
void removeListener(_i4.VoidCallback? listener) => super.noSuchMethod( | ||
Invocation.method( | ||
#removeListener, | ||
[listener], | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
|
||
@override | ||
void dispose() => super.noSuchMethod( | ||
Invocation.method( | ||
#dispose, | ||
[], | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
|
||
@override | ||
void notifyListeners() => super.noSuchMethod( | ||
Invocation.method( | ||
#notifyListeners, | ||
[], | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:random_workout/models/exercise.dart'; | ||
import 'package:random_workout/pages/workout_page.dart'; | ||
import 'package:random_workout/providers/app_state.dart'; | ||
import 'package:random_workout/widgets/exercise/add_exercise_options_dialog.dart'; | ||
import '../mocks/mock_app_state.mocks.dart'; | ||
|
||
void main() { | ||
late MockAppState mockAppState; | ||
|
||
setUp(() { | ||
mockAppState = MockAppState(); | ||
|
||
// Set up default stubs | ||
when(mockAppState.isDarkMode).thenReturn(false); | ||
when(mockAppState.currentWorkout).thenReturn([]); | ||
when(mockAppState.generateWorkout(any)).thenReturn(null); | ||
}); | ||
|
||
testWidgets('Add exercise button opens AddExerciseOptionsDialog', | ||
(WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: ChangeNotifierProvider<AppState>.value( | ||
value: mockAppState, | ||
child: const WorkoutPage(category: ExerciseCategory.strength), | ||
), | ||
), | ||
); | ||
|
||
expect(find.byType(WorkoutPage), findsOneWidget); | ||
|
||
final addButton = find.byTooltip('Add exercise'); | ||
expect(addButton, findsOneWidget); | ||
|
||
await tester.tap(addButton); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.byType(AddExerciseOptionsDialog), findsOneWidget); | ||
expect(find.text('Add Exercise'), findsOneWidget); | ||
expect(find.text('Choose from pre-defined exercises'), findsOneWidget); | ||
expect(find.text('Create a custom exercise'), findsOneWidget); | ||
|
||
verifyNever(mockAppState.generateWorkout(any)); | ||
verifyNever(mockAppState.addExercise(any)); | ||
}); | ||
|
||
testWidgets('Generate new workout button calls generateWorkout', | ||
(WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: ChangeNotifierProvider<AppState>.value( | ||
value: mockAppState, | ||
child: const WorkoutPage(category: ExerciseCategory.strength), | ||
), | ||
), | ||
); | ||
|
||
final generateButton = find.byTooltip('Generate new workout'); | ||
expect(generateButton, findsOneWidget); | ||
|
||
await tester.tap(generateButton); | ||
await tester.pumpAndSettle(); | ||
|
||
verify(mockAppState.generateWorkout(ExerciseCategory.strength)).called(1); | ||
verifyNever(mockAppState.addExercise(any)); | ||
}); | ||
|
||
testWidgets('WorkoutPage displays current workout', | ||
(WidgetTester tester) async { | ||
final testExercises = [ | ||
Exercise( | ||
name: 'Push-ups', | ||
description: 'Do push-ups', | ||
category: ExerciseCategory.strength), | ||
Exercise( | ||
name: 'Squats', | ||
description: 'Do squats', | ||
category: ExerciseCategory.strength), | ||
]; | ||
|
||
when(mockAppState.currentWorkout).thenReturn(testExercises); | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: ChangeNotifierProvider<AppState>.value( | ||
value: mockAppState, | ||
child: const WorkoutPage(category: ExerciseCategory.strength), | ||
), | ||
), | ||
); | ||
|
||
expect(find.text('Push-ups'), findsOneWidget); | ||
expect(find.text('Squats'), findsOneWidget); | ||
}); | ||
} |