blob: c2e281a1a14a7e90e7a5274dca3192be15745f05 [file] [log] [blame]
// 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 'package:flutter_test/flutter_test.dart';
import 'package:quick_actions_ios/messages.g.dart';
import 'package:quick_actions_ios/quick_actions_ios.dart';
import 'package:quick_actions_platform_interface/quick_actions_platform_interface.dart';
const String LAUNCH_ACTION_STRING = 'aString';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final _FakeQuickActionsApi api = _FakeQuickActionsApi();
final QuickActionsIos quickActions = QuickActionsIos(api: api);
test('registerWith() registers correct instance', () {
QuickActionsIos.registerWith();
expect(QuickActionsPlatform.instance, isA<QuickActionsIos>());
});
group('#initialize', () {
test('initialize', () {
expect(quickActions.initialize((_) {}), completes);
});
});
test('setShortcutItems', () async {
await quickActions.initialize((String type) {});
const ShortcutItem item =
ShortcutItem(type: 'test', localizedTitle: 'title', icon: 'icon.svg');
await quickActions.setShortcutItems(<ShortcutItem>[item]);
expect(api.items.first.type, item.type);
expect(api.items.first.localizedTitle, item.localizedTitle);
expect(api.items.first.icon, item.icon);
});
test('clearShortCutItems', () {
quickActions.initialize((String type) {});
const ShortcutItem item =
ShortcutItem(type: 'test', localizedTitle: 'title', icon: 'icon.svg');
quickActions.setShortcutItems(<ShortcutItem>[item]);
quickActions.clearShortcutItems();
expect(api.items.isEmpty, true);
});
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);
});
}
class _FakeQuickActionsApi implements IOSQuickActionsApi {
List<ShortcutItem> items = <ShortcutItem>[];
bool getLaunchActionCalled = false;
@override
Future<void> clearShortcutItems() async {
items = <ShortcutItem>[];
return;
}
@override
Future<void> setShortcutItems(List<ShortcutItemMessage?> itemsList) async {
await clearShortcutItems();
for (final ShortcutItemMessage? element in itemsList) {
items.add(shortcutItemMessageToShortcutItem(element!));
}
}
}
/// Conversion tool to change [ShortcutItemMessage] back to [ShortcutItem]
ShortcutItem shortcutItemMessageToShortcutItem(ShortcutItemMessage item) {
return ShortcutItem(
type: item.type,
localizedTitle: item.localizedTitle,
icon: item.icon,
);
}