Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
proninyaroslav committed Oct 2, 2024
1 parent 61c71af commit 7897720
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/ui/camera_picker/camera_confirmation_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import 'package:material_symbols_icons/symbols.dart';
import 'package:responsive_builder/responsive_builder.dart';

import '../../locale.dart';
import 'components/edit_image_metadata_sheet.dart';

@RoutePage()
class CameraConfirmationPage extends StatefulWidget {
Expand Down Expand Up @@ -107,12 +108,32 @@ class _CameraConfirmationPageState extends State<CameraConfirmationPage>
),
floatingActionButtonLocation:
FloatingActionButtonLocation.miniEndFloat,
floatingActionButton: FloatingActionButton.small(
onPressed: () => _showEditPropertiesSheet(context),
tooltip: 'Edit properties',
child: const Icon(Symbols.edit),
),
),
),
);
},
);
}

void _showEditPropertiesSheet(BuildContext context) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (context) {
return Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: const EditImagePropertiesSheet(),
);
},
);
}
}

class _ButtonBar extends StatelessWidget {
Expand Down
13 changes: 13 additions & 0 deletions test/settings/settings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,18 @@ void main() {
isTrue,
);
});

test('Camera autofocus', () async {
expect(
await pref.cameraAutofocus,
AppSettingsDefault.cameraAutofocus,
);
await pref.setCameraAutofocus(false);
expect(await pref.cameraAutofocus, false);
expect(
await sharedPref.containsKey('pref_key_camera_autofocus'),
isTrue,
);
});
});
}
8 changes: 8 additions & 0 deletions test/ui/camera/camera_provider_cubit_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void main() {
when(() => mockProvider.availableCameras())
.thenAnswer((_) async => expectedCameras);
when(() => mockPref.enableFlashByDefault).thenAnswer((_) async => true);
when(() => mockPref.cameraAutofocus).thenAnswer((_) async => true);
await cubit.loadAvailableCameras();
},
expect: () => [
Expand All @@ -80,6 +81,7 @@ void main() {
),
],
enableFlashByDefault: true,
autofocus: true,
),
],
);
Expand All @@ -103,6 +105,7 @@ void main() {
when(() => mockProvider.availableCameras())
.thenAnswer((_) async => expectedCameras);
when(() => mockPref.enableFlashByDefault).thenAnswer((_) async => true);
when(() => mockPref.cameraAutofocus).thenAnswer((_) async => true);
await cubit.loadAvailableCameras();
await cubit.loadAvailableCameras();
verify(() => mockProvider.availableCameras()).called(1);
Expand All @@ -123,6 +126,7 @@ void main() {
),
],
enableFlashByDefault: true,
autofocus: true,
),
const CameraProviderState.loading(),
const CameraProviderState.loaded(
Expand All @@ -139,6 +143,7 @@ void main() {
),
],
enableFlashByDefault: true,
autofocus: true,
),
],
);
Expand Down Expand Up @@ -177,6 +182,7 @@ void main() {
when(() => mockProvider.availableCameras())
.thenAnswer((_) async => expectedCameras);
when(() => mockPref.enableFlashByDefault).thenAnswer((_) async => true);
when(() => mockPref.cameraAutofocus).thenAnswer((_) async => true);
await cubit.loadAvailableCameras();
await cubit.switchCamera(expectedCameras.last);
},
Expand All @@ -196,6 +202,7 @@ void main() {
),
],
enableFlashByDefault: true,
autofocus: true,
),
const CameraProviderState.loading(),
const CameraProviderState.loaded(
Expand All @@ -212,6 +219,7 @@ void main() {
),
],
enableFlashByDefault: true,
autofocus: true,
),
],
);
Expand Down
36 changes: 36 additions & 0 deletions test/ui/settings/camera_cubit_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void main() {
setUp(() async {
when(() => mockPref.enableFlashByDefault).thenAnswer((_) async => true);
when(() => mockPref.cameraFullscreenMode).thenAnswer((_) async => true);
when(() => mockPref.cameraAutofocus).thenAnswer((_) async => true);
cubit = CameraSettingsCubit(mockPref);
await cubit.load();
});
Expand Down Expand Up @@ -64,12 +65,14 @@ void main() {
CameraInfo(
enableFlashByDefault: false,
fullscreenMode: true,
autofocus: true,
),
),
const CameraState.enableFlashChanged(
CameraInfo(
enableFlashByDefault: true,
fullscreenMode: true,
autofocus: true,
),
),
],
Expand All @@ -93,12 +96,45 @@ void main() {
CameraInfo(
enableFlashByDefault: true,
fullscreenMode: false,
autofocus: true,
),
),
const CameraState.fullscreenModeChanged(
CameraInfo(
enableFlashByDefault: true,
fullscreenMode: true,
autofocus: true,
),
),
],
);

blocTest(
'Autofocus',
build: () => cubit,
act: (CameraSettingsCubit cubit) async {
when(() => mockPref.setCameraAutofocus(any()))
.thenAnswer((_) => Future.value());

await cubit.setAutofocus(false);
verify(() => mockPref.setCameraAutofocus(false)).called(1);

await cubit.setAutofocus(true);
verify(() => mockPref.setCameraAutofocus(true)).called(1);
},
expect: () => [
const CameraState.autofocusChanged(
CameraInfo(
enableFlashByDefault: true,
fullscreenMode: true,
autofocus: false,
),
),
const CameraState.autofocusChanged(
CameraInfo(
enableFlashByDefault: true,
fullscreenMode: true,
autofocus: true,
),
),
],
Expand Down

0 comments on commit 7897720

Please sign in to comment.