From 4e18cc716438bca3e54f879dff3616537f58aa1e Mon Sep 17 00:00:00 2001 From: Thiago Bomfim Date: Thu, 6 Aug 2020 19:18:15 -0300 Subject: [PATCH] Update method write file sync. Create testing for PDFViewer --- example/test/viewer_test.dart | 59 +++++++++++++++++++++++++++++++++++ lib/src/document.dart | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 example/test/viewer_test.dart diff --git a/example/test/viewer_test.dart b/example/test/viewer_test.dart new file mode 100644 index 0000000..31c2bcc --- /dev/null +++ b/example/test/viewer_test.dart @@ -0,0 +1,59 @@ +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_plugin_pdf_viewer/flutter_plugin_pdf_viewer.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + const MethodChannel channel = MethodChannel('flutter_plugin_pdf_viewer'); + List log; + + channel.setMockMethodCallHandler((MethodCall methodCall) async { + log.add(methodCall); + switch (methodCall.method) { + case 'getNumberOfPages': + return '5'; + default: + return null; + } + }); + + TestWidgetsFlutterBinding.ensureInitialized(); + + const MethodChannel channelPath = + MethodChannel('plugins.flutter.io/path_provider'); + List logPath; + + channelPath.setMockMethodCallHandler((MethodCall methodCall) async { + logPath.add(methodCall); + switch (methodCall.method) { + case 'getApplicationDocumentsDirectory': + return Directory.current.path; + default: + return null; + } + }); + + setUp(() { + logPath = []; + log = []; + }); + + Widget createWidgetForTesting({Widget child}) { + return MaterialApp( + home: child, + ); + } + + testWidgets('PDFViewer with BottomAppBar', (WidgetTester tester) async { + PDFDocument _document = await PDFDocument.fromAsset('assets/sample2.pdf'); + await tester.pumpWidget( + createWidgetForTesting(child: PDFViewer(document: _document))); + + var bottomBar = find.byType(BottomAppBar); + expect(bottomBar, findsOneWidget); + }); +} diff --git a/lib/src/document.dart b/lib/src/document.dart index 4844297..5825891 100644 --- a/lib/src/document.dart +++ b/lib/src/document.dart @@ -59,7 +59,7 @@ class PDFDocument { file = File("${dir.path}/file.pdf"); var data = await rootBundle.load(asset); var bytes = data.buffer.asUint8List(); - await file.writeAsBytes(bytes, flush: true); + file.writeAsBytesSync(bytes, flush: true); } catch (e) { throw Exception('Error parsing asset file!'); }