2022-11-01 08:24:41 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022 Iconica
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
2024-08-07 13:31:53 +02:00
|
|
|
import "dart:typed_data";
|
2022-09-02 16:14:24 +02:00
|
|
|
|
2024-08-07 13:31:53 +02:00
|
|
|
import "package:flutter/material.dart";
|
|
|
|
import "package:flutter_image_picker/flutter_image_picker.dart"
|
2022-09-05 11:13:07 +02:00
|
|
|
as iconica_image_picker;
|
2024-08-07 13:31:53 +02:00
|
|
|
import "package:flutter_test/flutter_test.dart";
|
|
|
|
import "package:image_picker/image_picker.dart" as image_picker;
|
|
|
|
import "package:mocktail/mocktail.dart";
|
2022-09-02 16:14:24 +02:00
|
|
|
|
2024-08-07 13:31:53 +02:00
|
|
|
import "mocks/image_picker_service_mock.dart";
|
2022-09-02 14:13:58 +02:00
|
|
|
|
|
|
|
void main() {
|
2024-02-06 16:18:57 +01:00
|
|
|
var cameraImage = Uint8List(10);
|
|
|
|
var galleryImage = Uint8List(44);
|
2022-09-02 16:14:24 +02:00
|
|
|
|
2024-08-07 13:31:53 +02:00
|
|
|
testWidgets("Image Picker Shows With Normal Theme", (tester) async {
|
2022-09-26 12:00:55 +02:00
|
|
|
await tester.pumpWidget(
|
|
|
|
const MaterialApp(
|
|
|
|
home: Material(
|
|
|
|
child: iconica_image_picker.ImagePicker(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2022-09-02 14:13:58 +02:00
|
|
|
|
2024-02-06 16:18:57 +01:00
|
|
|
var makePhotoIconFinder = find.byIcon(Icons.camera_alt_rounded);
|
|
|
|
var makePhotoTextFinder =
|
2022-09-02 16:14:24 +02:00
|
|
|
find.text(const iconica_image_picker.ImagePickerTheme().makePhotoText);
|
2024-02-06 16:18:57 +01:00
|
|
|
var selectImageIconFinder = find.byIcon(Icons.image);
|
|
|
|
var selectImageTextFinder = find
|
2022-09-02 16:14:24 +02:00
|
|
|
.text(const iconica_image_picker.ImagePickerTheme().selectImageText);
|
2024-08-07 13:31:53 +02:00
|
|
|
var closebuttonTextFinder = find.text("Close");
|
2022-09-02 14:13:58 +02:00
|
|
|
|
|
|
|
expect(makePhotoIconFinder, findsOneWidget);
|
|
|
|
expect(makePhotoTextFinder, findsOneWidget);
|
|
|
|
expect(selectImageIconFinder, findsOneWidget);
|
|
|
|
expect(selectImageTextFinder, findsOneWidget);
|
|
|
|
expect(closebuttonTextFinder, findsOneWidget);
|
|
|
|
});
|
|
|
|
|
2022-09-02 16:14:24 +02:00
|
|
|
testWidgets(
|
2024-08-07 13:31:53 +02:00
|
|
|
"Image Picker Calls Function Correctly When ImageSource Is Gallery",
|
2022-09-02 16:14:24 +02:00
|
|
|
(tester) async {
|
2024-02-06 16:18:57 +01:00
|
|
|
var serviceMock = ImagePickerServiceMock();
|
2022-09-02 16:14:24 +02:00
|
|
|
|
|
|
|
when(() => serviceMock.pickImage(image_picker.ImageSource.gallery))
|
|
|
|
.thenAnswer((_) => Future.value(galleryImage));
|
|
|
|
|
2024-02-06 16:18:57 +01:00
|
|
|
await tester.pumpWidget(
|
|
|
|
MaterialApp(
|
2022-09-02 16:14:24 +02:00
|
|
|
home: Material(
|
2024-02-06 16:18:57 +01:00
|
|
|
child: iconica_image_picker.ImagePicker(
|
2024-02-22 16:22:22 +01:00
|
|
|
service: serviceMock,
|
2024-02-06 16:18:57 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2022-09-02 16:14:24 +02:00
|
|
|
|
2024-02-06 16:18:57 +01:00
|
|
|
var finder = find.byKey(
|
|
|
|
Key(const iconica_image_picker.ImagePickerTheme().selectImageText),
|
|
|
|
);
|
2022-09-02 16:14:24 +02:00
|
|
|
|
|
|
|
await tester.tap(finder);
|
|
|
|
|
|
|
|
verify(() => serviceMock.pickImage(image_picker.ImageSource.gallery))
|
|
|
|
.called(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets(
|
2024-08-07 13:31:53 +02:00
|
|
|
"Image Picker Calls Function Correctly When ImageSource Is Camera",
|
2022-09-02 16:14:24 +02:00
|
|
|
(tester) async {
|
2024-02-06 16:18:57 +01:00
|
|
|
var serviceMock = ImagePickerServiceMock();
|
2022-09-02 16:14:24 +02:00
|
|
|
|
|
|
|
when(() => serviceMock.pickImage(image_picker.ImageSource.camera))
|
|
|
|
.thenAnswer((_) => Future.value(cameraImage));
|
|
|
|
|
2024-02-06 16:18:57 +01:00
|
|
|
await tester.pumpWidget(
|
|
|
|
MaterialApp(
|
2022-09-02 16:14:24 +02:00
|
|
|
home: Material(
|
2024-02-06 16:18:57 +01:00
|
|
|
child: iconica_image_picker.ImagePicker(
|
2024-02-22 16:22:22 +01:00
|
|
|
service: serviceMock,
|
2024-02-06 16:18:57 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2022-09-02 16:14:24 +02:00
|
|
|
|
2024-02-06 16:18:57 +01:00
|
|
|
var finder = find.byKey(
|
|
|
|
Key(const iconica_image_picker.ImagePickerTheme().makePhotoText),
|
|
|
|
);
|
2022-09-02 16:14:24 +02:00
|
|
|
|
|
|
|
await tester.tap(finder);
|
|
|
|
|
|
|
|
verify(() => serviceMock.pickImage(image_picker.ImageSource.camera))
|
|
|
|
.called(1);
|
|
|
|
});
|
|
|
|
|
2024-08-07 13:31:53 +02:00
|
|
|
testWidgets("Image Picker Shows With Custom Theme", (tester) async {
|
2022-09-26 12:00:55 +02:00
|
|
|
Widget makePhotoIcon = Container(
|
|
|
|
height: 125,
|
|
|
|
width: 125,
|
|
|
|
color: Colors.red,
|
|
|
|
);
|
2024-08-07 13:31:53 +02:00
|
|
|
var makePhotoText = "taaaake image";
|
2022-09-26 12:00:55 +02:00
|
|
|
Widget selectImageIcon = Container(
|
|
|
|
height: 125,
|
|
|
|
width: 125,
|
|
|
|
color: Colors.blue,
|
|
|
|
);
|
2024-08-07 13:31:53 +02:00
|
|
|
var selectImageText = "seleeeeect image";
|
|
|
|
var closeButtonText = "Close";
|
2022-09-02 14:13:58 +02:00
|
|
|
|
2024-02-06 16:18:57 +01:00
|
|
|
await tester.pumpWidget(
|
|
|
|
MaterialApp(
|
2022-09-02 14:13:58 +02:00
|
|
|
home: Material(
|
2024-02-06 16:18:57 +01:00
|
|
|
child: iconica_image_picker.ImagePicker(
|
2024-02-22 16:22:22 +01:00
|
|
|
theme: iconica_image_picker.ImagePickerTheme(
|
2024-02-06 16:18:57 +01:00
|
|
|
makePhotoIcon: makePhotoIcon,
|
|
|
|
makePhotoText: makePhotoText,
|
|
|
|
selectImageIcon: selectImageIcon,
|
|
|
|
selectImageText: selectImageText,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
var makePhotoIconFinder = find.byWidget(makePhotoIcon);
|
|
|
|
var makePhotoTextFinder = find.text(makePhotoText);
|
|
|
|
var selectImageIconFinder = find.byWidget(selectImageIcon);
|
|
|
|
var selectImageTextFinder = find.text(selectImageText);
|
|
|
|
var closebuttonTextFinder = find.text(closeButtonText);
|
2022-09-02 14:13:58 +02:00
|
|
|
|
|
|
|
expect(makePhotoIconFinder, findsOneWidget);
|
|
|
|
expect(makePhotoTextFinder, findsOneWidget);
|
|
|
|
expect(selectImageIconFinder, findsOneWidget);
|
|
|
|
expect(selectImageTextFinder, findsOneWidget);
|
|
|
|
expect(closebuttonTextFinder, findsOneWidget);
|
|
|
|
});
|
|
|
|
}
|