Skip to content

Commit 43f14ab

Browse files
author
Michael Klimushyn
authored
[quick_actions] Add DartDoc and test coverage (flutter#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.
1 parent 2ea4bc8 commit 43f14ab

7 files changed

Lines changed: 46 additions & 21 deletions

File tree

packages/quick_actions/CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
## 0.4.0
2+
3+
- Added missing documentation.
4+
- **Breaking change**. `channel` and `withMethodChannel` are now
5+
`@visibleForTesting`. These methods are for plugin unit tests only and may be
6+
removed in the future.
7+
- **Breaking change**. Removed `runLaunchAction` from public API. This method
8+
was not meant to be used by consumers of the plugin.
9+
110
## 0.3.3+1
211

3-
* Update and migrate iOS example project by removing flutter_assets, change
12+
* Update and migrate iOS example project by removing flutter_assets, change
413
"English" to "en", remove extraneous xcconfigs, update to Xcode 11 build
514
settings, and remove ARCHS and DEVELOPMENT_TEAM.
615

packages/quick_actions/analysis_options.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/quick_actions/example/lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// ignore_for_file: public_member_api_docs
6+
57
import 'package:flutter/material.dart';
68
import 'package:quick_actions/quick_actions.dart';
79

packages/quick_actions/example/test_driver/quick_actions_e2e_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ Future<void> main() async {
1010
final FlutterDriver driver = await FlutterDriver.connect();
1111
final String result =
1212
await driver.requestData(null, timeout: const Duration(minutes: 1));
13-
driver.close();
13+
await driver.close();
1414
exit(result == 'pass' ? 0 : 1);
1515
}

packages/quick_actions/lib/quick_actions.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ typedef void QuickActionHandler(String type);
1717

1818
/// Home screen quick-action shortcut item.
1919
class ShortcutItem {
20+
/// Constructs an instance with the given [type], [localizedTitle], and
21+
/// [icon].
22+
///
23+
/// Only [icon] should be nullable. It will remain `null` if unset.
2024
const ShortcutItem({
2125
@required this.type,
2226
@required this.localizedTitle,
@@ -36,14 +40,21 @@ class ShortcutItem {
3640

3741
/// Quick actions plugin.
3842
class QuickActions {
43+
/// Gets an instance of the plugin with the default methodChannel.
44+
///
45+
/// [initialize] should be called before using any other methods.
3946
factory QuickActions() => _instance;
4047

48+
/// This is a test-only constructor. Do not call this, it can break at any
49+
/// time.
4150
@visibleForTesting
4251
QuickActions.withMethodChannel(this.channel);
4352

4453
static final QuickActions _instance =
4554
QuickActions.withMethodChannel(_kChannel);
4655

56+
/// This is a test-only accessor. Do not call this, it can break at any time.
57+
@visibleForTesting
4758
final MethodChannel channel;
4859

4960
/// Initializes this plugin.
@@ -54,10 +65,6 @@ class QuickActions {
5465
assert(call.method == 'launch');
5566
handler(call.arguments);
5667
});
57-
runLaunchAction(handler);
58-
}
59-
60-
void runLaunchAction(QuickActionHandler handler) async {
6168
final String action = await channel.invokeMethod<String>('getLaunchAction');
6269
if (action != null) {
6370
handler(action);

packages/quick_actions/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for creating shortcuts on home screen, also known as
33
Quick Actions on iOS and App Shortcuts on Android.
44
author: Flutter Team <[email protected]>
55
homepage: https://github.com/flutter/plugins/tree/master/packages/quick_actions
6-
version: 0.3.3+1
6+
version: 0.4.0
77

88
flutter:
99
plugin:

packages/quick_actions/test/quick_actions_test.dart

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright 2017 The Chromium Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4+
import 'dart:async';
5+
46
import 'package:flutter/services.dart';
57
import 'package:flutter_test/flutter_test.dart';
68
import 'package:quick_actions/quick_actions.dart';
@@ -16,7 +18,7 @@ void main() {
1618
quickActions.channel.setMockMethodCallHandler(
1719
(MethodCall methodCall) async {
1820
log.add(methodCall);
19-
return null;
21+
return 'non empty response';
2022
},
2123
);
2224
});
@@ -59,14 +61,30 @@ void main() {
5961
log.clear();
6062
});
6163

62-
test('runLaunchAction', () {
63-
quickActions.runLaunchAction(null);
64+
test('initialize', () async {
65+
final Completer<bool> quickActionsHandler = Completer<bool>();
66+
quickActions.initialize((_) => quickActionsHandler.complete(true));
6467
expect(
6568
log,
6669
<Matcher>[
6770
isMethodCall('getLaunchAction', arguments: null),
6871
],
6972
);
7073
log.clear();
74+
75+
expect(quickActionsHandler.future, completion(isTrue));
76+
});
77+
78+
test('Shortcut item can be constructed', () {
79+
const String type = 'type';
80+
const String localizedTitle = 'title';
81+
const String icon = 'foo';
82+
83+
const ShortcutItem item =
84+
ShortcutItem(type: type, localizedTitle: localizedTitle, icon: icon);
85+
86+
expect(item.type, type);
87+
expect(item.localizedTitle, localizedTitle);
88+
expect(item.icon, icon);
7189
});
7290
}

0 commit comments

Comments
 (0)