126 lines
4.8 KiB
Dart
126 lines
4.8 KiB
Dart
import 'dart:io';
|
|
import 'package:cpd_app/session_list.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:cpd_app/main.dart';
|
|
import 'package:cpd_app/ocr_page.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
Future<Uint8List> loadImageBytesFromAssets(String imagePath) async {
|
|
final ByteData data = await rootBundle.load(imagePath);
|
|
return data.buffer.asUint8List();
|
|
}
|
|
|
|
void main() {
|
|
setUpAll(() {
|
|
HttpOverrides.global = null;
|
|
});
|
|
testWidgets('Check ocr UI', (WidgetTester tester) async {
|
|
await tester.pumpWidget(const MyApp());
|
|
|
|
final buttonsFinder = find.byType(ElevatedButton);
|
|
|
|
expect(buttonsFinder, findsWidgets);
|
|
await tester.tap(find.widgetWithText(ElevatedButton, "Image Tools"));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('OCR'), findsOneWidget);
|
|
|
|
var ocrbtn = find.widgetWithText(ElevatedButton, "OCR");
|
|
expect(ocrbtn, findsOneWidget);
|
|
|
|
var imgtrans = find.widgetWithText(ElevatedButton, "Image Translation");
|
|
expect(imgtrans, findsOneWidget);
|
|
var prev = find.widgetWithText(ElevatedButton, "Previous Images");
|
|
expect(prev, findsOneWidget);
|
|
|
|
await tester.tap(find.widgetWithText(ElevatedButton, "OCR"));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('OCR'), findsOneWidget);
|
|
expect(find.text('Select Image'), findsOneWidget);
|
|
expect(find.widgetWithText(DropdownButton<String>, 'Auto'), findsOneWidget);
|
|
await tester.tap(find.widgetWithText(DropdownButton<String>, 'Auto'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('German'), findsOneWidget);
|
|
expect(find.text('English'), findsOneWidget);
|
|
expect(find.text('French'), findsOneWidget);
|
|
expect(find.text('Russian'), findsOneWidget);
|
|
await tester.tap(find.widgetWithText(DropdownMenuItem<String>, 'German'));
|
|
await tester.tap(find.widgetWithText(ElevatedButton, "Select Image"));
|
|
await tester.pump();
|
|
|
|
final ocrFinder = find.byType(OCRPage);
|
|
final ocrState = tester.state<OCRPageState>(ocrFinder);
|
|
Uint8List bytes = await loadImageBytesFromAssets('assets/schild.png');
|
|
|
|
ocrState.setState(() {
|
|
var image = XFile.fromData(bytes);
|
|
ocrState.selectedImage = image;
|
|
});
|
|
expect(ocrState.selectedImage, isNotNull);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.widgetWithText(ElevatedButton, "Extract Text"), findsOneWidget);
|
|
});
|
|
testWidgets('Check imageTranslateUI', (WidgetTester tester) async {
|
|
await tester.pumpWidget(const MyApp());
|
|
final buttonsFinder = find.byType(ElevatedButton);
|
|
expect(buttonsFinder, findsWidgets);
|
|
await tester.tap(find.widgetWithText(ElevatedButton, "Image Tools"));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Image Translation'), findsOneWidget);
|
|
var btn1 = find.widgetWithText(ElevatedButton, "Image Translation");
|
|
expect(btn1, findsOneWidget);
|
|
await tester.tap(btn1);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Image Translation'), findsOneWidget);
|
|
expect(
|
|
find.widgetWithText(DropdownButton<String>, 'English'), findsOneWidget);
|
|
await tester.tap(find.widgetWithText(DropdownButton<String>, 'English'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('German'), findsExactly(2));
|
|
expect(find.text('English'), findsExactly(2));
|
|
expect(find.text('French'), findsExactly(1));
|
|
expect(find.text('Russian'), findsExactly(1));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.widgetWithText(DropdownButton<String>, 'German'));
|
|
expect(find.text('German'), findsExactly(2));
|
|
expect(find.text('English'), findsExactly(2));
|
|
expect(find.text('French'), findsExactly(1));
|
|
expect(find.text('Russian'), findsExactly(1));
|
|
//
|
|
});
|
|
|
|
testWidgets('Check listPreview', (WidgetTester tester) async {
|
|
ImageList.addImage(
|
|
"test1", await loadImageBytesFromAssets('assets/schild.png'));
|
|
ImageList.addImage(
|
|
"test2", await loadImageBytesFromAssets('assets/schild.png'));
|
|
ImageList.addImage(
|
|
"test3", await loadImageBytesFromAssets('assets/schild.png'));
|
|
ImageList.addImage(
|
|
"test3", await loadImageBytesFromAssets('assets/schild.png'));
|
|
|
|
await tester.pumpWidget(const MyApp());
|
|
|
|
final buttonsFinder = find.byType(ElevatedButton);
|
|
expect(buttonsFinder, findsWidgets);
|
|
|
|
await tester.tap(find.widgetWithText(ElevatedButton, "Image Tools"));
|
|
await tester.pumpAndSettle();
|
|
|
|
var btn1 = find.widgetWithText(ElevatedButton, "Previous Images");
|
|
expect(btn1, findsOneWidget);
|
|
await tester.tap(btn1);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Image Gallery'), findsOneWidget);
|
|
|
|
final gridViewFinder = find.byType(GridView);
|
|
expect(gridViewFinder, findsOneWidget);
|
|
|
|
const numberOfEntries = 4;
|
|
expect(find.byType(GestureDetector), findsNWidgets(numberOfEntries));
|
|
});
|
|
}
|