From 4538dc6e8fb60b7a8dc661783ff30c55442ad684 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 11 Sep 2023 10:01:14 -0400 Subject: [PATCH] [ios_platform_images] Add integration tests Currently there are no end-to-end tests for this package that would fail if the communication with the native implementation didn't work, or if the native implementation were broken. This is especially problematic since we want to convert this plugin to both Swift and Pigeon, each of which has the potential to break things that would currently not be caught. This adds basic integration tests of both methods to ensure that the simple case of a successful call works as expected. --- .../ios_platform_images_test.dart | 35 +++++++++++++++++++ .../ios_platform_images/example/pubspec.yaml | 2 ++ 2 files changed, 37 insertions(+) create mode 100644 packages/ios_platform_images/example/integration_test/ios_platform_images_test.dart diff --git a/packages/ios_platform_images/example/integration_test/ios_platform_images_test.dart b/packages/ios_platform_images/example/integration_test/ios_platform_images_test.dart new file mode 100644 index 00000000000..1561d3bfacc --- /dev/null +++ b/packages/ios_platform_images/example/integration_test/ios_platform_images_test.dart @@ -0,0 +1,35 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:ios_platform_images/ios_platform_images.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('resolves URL', (WidgetTester _) async { + final String? path = await IosPlatformImages.resolveURL('textfile'); + expect(Uri.parse(path!).scheme, 'file'); + expect(path.contains('Runner.app'), isTrue); + }); + + testWidgets('loads image', (WidgetTester _) async { + final Completer successCompleter = Completer(); + final ImageProvider provider = IosPlatformImages.load('flutter'); + final ImageStream imageStream = provider.resolve(ImageConfiguration.empty); + imageStream.addListener( + ImageStreamListener((ImageInfo image, bool synchronousCall) { + successCompleter.complete(true); + }, onError: (Object e, StackTrace? _) { + successCompleter.complete(false); + })); + + final bool succeeded = await successCompleter.future; + expect(succeeded, true); + }); +} diff --git a/packages/ios_platform_images/example/pubspec.yaml b/packages/ios_platform_images/example/pubspec.yaml index 7739d4950d4..6674a3a04ae 100644 --- a/packages/ios_platform_images/example/pubspec.yaml +++ b/packages/ios_platform_images/example/pubspec.yaml @@ -21,6 +21,8 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + integration_test: + sdk: flutter flutter: uses-material-design: true