From 093563065822faca7a1ce39256babc58a7e63dd0 Mon Sep 17 00:00:00 2001 From: Michael Klimushyn Date: Fri, 22 Nov 2019 14:48:49 -0800 Subject: [PATCH 1/4] [quick_actions] Add DartDoc and test coverage 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. --- packages/quick_actions/CHANGELOG.md | 8 ++++++- packages/quick_actions/analysis_options.yaml | 11 --------- packages/quick_actions/example/lib/main.dart | 2 ++ .../test_driver/quick_actions_e2e_test.dart | 2 +- packages/quick_actions/lib/quick_actions.dart | 16 +++++++++++++ packages/quick_actions/pubspec.yaml | 2 +- .../test/quick_actions_test.dart | 24 ++++++++++++++++--- 7 files changed, 48 insertions(+), 17 deletions(-) delete mode 100644 packages/quick_actions/analysis_options.yaml diff --git a/packages/quick_actions/CHANGELOG.md b/packages/quick_actions/CHANGELOG.md index ca7b674e77b5..97915157204f 100644 --- a/packages/quick_actions/CHANGELOG.md +++ b/packages/quick_actions/CHANGELOG.md @@ -1,6 +1,12 @@ +## 0.3.4 + +* Add missing documentation. Some of the public methods should have been + annotated as `@visibleForTesting` previously and were not, so the annotations + have been added now. + ## 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 d4ccef63f1d1..000000000000 --- 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 dc4dc7a316fe..fc289810ea24 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 ff6e9ce74ad9..f3aa9e218d82 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 @@ Future main() async { 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 f240968eb8f5..b98f8b2fa143 100644 --- a/packages/quick_actions/lib/quick_actions.dart +++ b/packages/quick_actions/lib/quick_actions.dart @@ -17,6 +17,10 @@ typedef void QuickActionHandler(String type); /// 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 @@ class ShortcutItem { /// 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,9 +65,14 @@ class QuickActions { assert(call.method == 'launch'); handler(call.arguments); }); + // ignore: deprecated_member_use_from_same_package runLaunchAction(handler); } + /// This is only exposed for the unit tests. Do not rely on it, it may break + /// without warning in the future. + @visibleForTesting + @deprecated void runLaunchAction(QuickActionHandler handler) async { final String action = await channel.invokeMethod('getLaunchAction'); if (action != null) { diff --git a/packages/quick_actions/pubspec.yaml b/packages/quick_actions/pubspec.yaml index 5bb3467a63fc..24e5fc2b5fc2 100644 --- a/packages/quick_actions/pubspec.yaml +++ b/packages/quick_actions/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for creating shortcuts on home screen, also known as Quick Actions on iOS and App Shortcuts on Android. author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/quick_actions -version: 0.3.3+1 +version: 0.3.4 flutter: plugin: diff --git a/packages/quick_actions/test/quick_actions_test.dart b/packages/quick_actions/test/quick_actions_test.dart index 98a412e3e06d..4567d0fe7073 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 @@ void main() { quickActions.channel.setMockMethodCallHandler( (MethodCall methodCall) async { log.add(methodCall); - return null; + return 'non empty response'; }, ); }); @@ -59,8 +61,9 @@ void main() { log.clear(); }); - test('runLaunchAction', () { - quickActions.runLaunchAction(null); + test('initialize', () async { + final Completer quickActionsHandler = Completer(); + quickActions.initialize((String _) => quickActionsHandler.complete(true)); expect( log, [ @@ -68,5 +71,20 @@ void main() { ], ); log.clear(); + + await expectLater(await quickActionsHandler.future, 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); }); } From 04b7806ef6f3675eca2d385d14ba219d30b7ffcf Mon Sep 17 00:00:00 2001 From: Michael Klimushyn Date: Mon, 25 Nov 2019 15:58:29 -0800 Subject: [PATCH 2/4] Apply suggestions from code review Co-Authored-By: Collin Jackson --- packages/quick_actions/lib/quick_actions.dart | 2 +- packages/quick_actions/test/quick_actions_test.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/quick_actions/lib/quick_actions.dart b/packages/quick_actions/lib/quick_actions.dart index b98f8b2fa143..9cb1dd1e4d5e 100644 --- a/packages/quick_actions/lib/quick_actions.dart +++ b/packages/quick_actions/lib/quick_actions.dart @@ -20,7 +20,7 @@ class ShortcutItem { /// Constructs an instance with the given [type], [localizedTitle], and /// [icon]. /// - /// Only [icon] should be nullable. It will remain null if unset. + /// Only [icon] should be nullable. It will remain `null` if unset. const ShortcutItem({ @required this.type, @required this.localizedTitle, diff --git a/packages/quick_actions/test/quick_actions_test.dart b/packages/quick_actions/test/quick_actions_test.dart index 4567d0fe7073..dc7393e342e9 100644 --- a/packages/quick_actions/test/quick_actions_test.dart +++ b/packages/quick_actions/test/quick_actions_test.dart @@ -75,7 +75,7 @@ void main() { await expectLater(await quickActionsHandler.future, isTrue); }); - test('ShortCut item can be constructed', () { + test('Shortcut item can be constructed', () { const String type = 'type'; const String localizedTitle = 'title'; const String icon = 'foo'; From 975a80d48c4a0376f6e0009a6aa4e9f7cd382bf6 Mon Sep 17 00:00:00 2001 From: Michael Klimushyn Date: Mon, 25 Nov 2019 16:08:33 -0800 Subject: [PATCH 3/4] Review feedback --- packages/quick_actions/CHANGELOG.md | 7 +++++-- packages/quick_actions/lib/quick_actions.dart | 9 --------- packages/quick_actions/pubspec.yaml | 2 +- packages/quick_actions/test/quick_actions_test.dart | 4 ++-- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/packages/quick_actions/CHANGELOG.md b/packages/quick_actions/CHANGELOG.md index 97915157204f..f93655bed9e8 100644 --- a/packages/quick_actions/CHANGELOG.md +++ b/packages/quick_actions/CHANGELOG.md @@ -1,8 +1,11 @@ -## 0.3.4 +## 0.4.0 * Add missing documentation. Some of the public methods should have been annotated as `@visibleForTesting` previously and were not, so the annotations - have been added now. + have been added now. **Potentially breaking change** this also removes a + public method that originally should have been private. It's unlikely that + this API has ever been used by consumers of the plugin, but the semantic + version has been upgraded anyway out of an abundance of caution. ## 0.3.3+1 diff --git a/packages/quick_actions/lib/quick_actions.dart b/packages/quick_actions/lib/quick_actions.dart index 9cb1dd1e4d5e..933162a1a47c 100644 --- a/packages/quick_actions/lib/quick_actions.dart +++ b/packages/quick_actions/lib/quick_actions.dart @@ -65,15 +65,6 @@ class QuickActions { assert(call.method == 'launch'); handler(call.arguments); }); - // ignore: deprecated_member_use_from_same_package - runLaunchAction(handler); - } - - /// This is only exposed for the unit tests. Do not rely on it, it may break - /// without warning in the future. - @visibleForTesting - @deprecated - void runLaunchAction(QuickActionHandler handler) async { final String action = await channel.invokeMethod('getLaunchAction'); if (action != null) { handler(action); diff --git a/packages/quick_actions/pubspec.yaml b/packages/quick_actions/pubspec.yaml index 24e5fc2b5fc2..ab8832865e5d 100644 --- a/packages/quick_actions/pubspec.yaml +++ b/packages/quick_actions/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for creating shortcuts on home screen, also known as Quick Actions on iOS and App Shortcuts on Android. author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/quick_actions -version: 0.3.4 +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 dc7393e342e9..ffb6de1024fd 100644 --- a/packages/quick_actions/test/quick_actions_test.dart +++ b/packages/quick_actions/test/quick_actions_test.dart @@ -63,7 +63,7 @@ void main() { test('initialize', () async { final Completer quickActionsHandler = Completer(); - quickActions.initialize((String _) => quickActionsHandler.complete(true)); + quickActions.initialize((_) => quickActionsHandler.complete(true)); expect( log, [ @@ -72,7 +72,7 @@ void main() { ); log.clear(); - await expectLater(await quickActionsHandler.future, isTrue); + expect(quickActionsHandler.future, completion(isTrue)); }); test('Shortcut item can be constructed', () { From a2491aee350cdb2b2b1099bd046b53c6708a4011 Mon Sep 17 00:00:00 2001 From: Michael Klimushyn Date: Mon, 25 Nov 2019 16:40:44 -0800 Subject: [PATCH 4/4] Reword changelog --- packages/quick_actions/CHANGELOG.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/quick_actions/CHANGELOG.md b/packages/quick_actions/CHANGELOG.md index f93655bed9e8..2c9aea75ff0d 100644 --- a/packages/quick_actions/CHANGELOG.md +++ b/packages/quick_actions/CHANGELOG.md @@ -1,11 +1,11 @@ ## 0.4.0 -* Add missing documentation. Some of the public methods should have been - annotated as `@visibleForTesting` previously and were not, so the annotations - have been added now. **Potentially breaking change** this also removes a - public method that originally should have been private. It's unlikely that - this API has ever been used by consumers of the plugin, but the semantic - version has been upgraded anyway out of an abundance of caution. +- 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