[quick_actions] Add DartDoc and test coverage (#2298)
Also adds a lint to prevent undocumented DartDocs from being added in
the future.
Some of the APIs were public when they really should have been
`@visibleForTesting` or even private. Added some `@visibleForTesting`
annotations as well.
diff --git a/packages/quick_actions/CHANGELOG.md b/packages/quick_actions/CHANGELOG.md
index ca7b674..2c9aea7 100644
--- a/packages/quick_actions/CHANGELOG.md
+++ b/packages/quick_actions/CHANGELOG.md
@@ -1,6 +1,15 @@
+## 0.4.0
+
+- Added missing documentation.
+- **Breaking change**. `channel` and `withMethodChannel` are now
+ `@visibleForTesting`. These methods are for plugin unit tests only and may be
+ removed in the future.
+- **Breaking change**. Removed `runLaunchAction` from public API. This method
+ was not meant to be used by consumers of the plugin.
+
## 0.3.3+1
-* Update and migrate iOS example project by removing flutter_assets, change
+* Update and migrate iOS example project by removing flutter_assets, change
"English" to "en", remove extraneous xcconfigs, update to Xcode 11 build
settings, and remove ARCHS and DEVELOPMENT_TEAM.
diff --git a/packages/quick_actions/analysis_options.yaml b/packages/quick_actions/analysis_options.yaml
deleted file mode 100644
index d4ccef6..0000000
--- a/packages/quick_actions/analysis_options.yaml
+++ /dev/null
@@ -1,11 +0,0 @@
-# This is a temporary file to allow us to land a new set of linter rules in a
-# series of manageable patches instead of one gigantic PR. It disables some of
-# the new lints that are already failing on this plugin, for this plugin. It
-# should be deleted and the failing lints addressed as soon as possible.
-
-include: ../../analysis_options.yaml
-
-analyzer:
- errors:
- public_member_api_docs: ignore
- unawaited_futures: ignore
diff --git a/packages/quick_actions/example/lib/main.dart b/packages/quick_actions/example/lib/main.dart
index dc4dc7a..fc28981 100644
--- a/packages/quick_actions/example/lib/main.dart
+++ b/packages/quick_actions/example/lib/main.dart
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// ignore_for_file: public_member_api_docs
+
import 'package:flutter/material.dart';
import 'package:quick_actions/quick_actions.dart';
diff --git a/packages/quick_actions/example/test_driver/quick_actions_e2e_test.dart b/packages/quick_actions/example/test_driver/quick_actions_e2e_test.dart
index ff6e9ce..f3aa9e2 100644
--- a/packages/quick_actions/example/test_driver/quick_actions_e2e_test.dart
+++ b/packages/quick_actions/example/test_driver/quick_actions_e2e_test.dart
@@ -10,6 +10,6 @@
final FlutterDriver driver = await FlutterDriver.connect();
final String result =
await driver.requestData(null, timeout: const Duration(minutes: 1));
- driver.close();
+ await driver.close();
exit(result == 'pass' ? 0 : 1);
}
diff --git a/packages/quick_actions/lib/quick_actions.dart b/packages/quick_actions/lib/quick_actions.dart
index f240968..933162a 100644
--- a/packages/quick_actions/lib/quick_actions.dart
+++ b/packages/quick_actions/lib/quick_actions.dart
@@ -17,6 +17,10 @@
/// Home screen quick-action shortcut item.
class ShortcutItem {
+ /// Constructs an instance with the given [type], [localizedTitle], and
+ /// [icon].
+ ///
+ /// Only [icon] should be nullable. It will remain `null` if unset.
const ShortcutItem({
@required this.type,
@required this.localizedTitle,
@@ -36,14 +40,21 @@
/// Quick actions plugin.
class QuickActions {
+ /// Gets an instance of the plugin with the default methodChannel.
+ ///
+ /// [initialize] should be called before using any other methods.
factory QuickActions() => _instance;
+ /// This is a test-only constructor. Do not call this, it can break at any
+ /// time.
@visibleForTesting
QuickActions.withMethodChannel(this.channel);
static final QuickActions _instance =
QuickActions.withMethodChannel(_kChannel);
+ /// This is a test-only accessor. Do not call this, it can break at any time.
+ @visibleForTesting
final MethodChannel channel;
/// Initializes this plugin.
@@ -54,10 +65,6 @@
assert(call.method == 'launch');
handler(call.arguments);
});
- runLaunchAction(handler);
- }
-
- void runLaunchAction(QuickActionHandler handler) async {
final String action = await channel.invokeMethod<String>('getLaunchAction');
if (action != null) {
handler(action);
diff --git a/packages/quick_actions/pubspec.yaml b/packages/quick_actions/pubspec.yaml
index 5bb3467..ab88328 100644
--- a/packages/quick_actions/pubspec.yaml
+++ b/packages/quick_actions/pubspec.yaml
@@ -3,7 +3,7 @@
Quick Actions on iOS and App Shortcuts on Android.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/quick_actions
-version: 0.3.3+1
+version: 0.4.0
flutter:
plugin:
diff --git a/packages/quick_actions/test/quick_actions_test.dart b/packages/quick_actions/test/quick_actions_test.dart
index 98a412e..ffb6de1 100644
--- a/packages/quick_actions/test/quick_actions_test.dart
+++ b/packages/quick_actions/test/quick_actions_test.dart
@@ -1,6 +1,8 @@
// Copyright 2017 The Chromium 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/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:quick_actions/quick_actions.dart';
@@ -16,7 +18,7 @@
quickActions.channel.setMockMethodCallHandler(
(MethodCall methodCall) async {
log.add(methodCall);
- return null;
+ return 'non empty response';
},
);
});
@@ -59,8 +61,9 @@
log.clear();
});
- test('runLaunchAction', () {
- quickActions.runLaunchAction(null);
+ test('initialize', () async {
+ final Completer<bool> quickActionsHandler = Completer<bool>();
+ quickActions.initialize((_) => quickActionsHandler.complete(true));
expect(
log,
<Matcher>[
@@ -68,5 +71,20 @@
],
);
log.clear();
+
+ expect(quickActionsHandler.future, completion(isTrue));
+ });
+
+ test('Shortcut item can be constructed', () {
+ const String type = 'type';
+ const String localizedTitle = 'title';
+ const String icon = 'foo';
+
+ const ShortcutItem item =
+ ShortcutItem(type: type, localizedTitle: localizedTitle, icon: icon);
+
+ expect(item.type, type);
+ expect(item.localizedTitle, localizedTitle);
+ expect(item.icon, icon);
});
}