FakeOsIntentsPlatform class

The platform, replaced by something a test can look inside.

Without one, everything OsIntents offers beyond running a handler is invisible in tests: the default implementation of the platform interface answers false and an empty list to keep a plugin-less desktop build working, so a test of code that donates, publishes static answers or pushes a launcher shortcut passes whether or not that code did anything at all.

late FakeOsIntentsPlatform platform;

setUp(() async {
  platform = FakeOsIntentsPlatform.install();
  await OsIntents.install($osIntentsRegistry);
});

test('completing a task donates it', () async {
  await completeTask('t-1');
  expect(platform.donations.single.id, 'completeTask');
});

It is also the only way to exercise the path the OS actually takes. IntentHarness calls a handler directly; invokeIntent goes through the dispatcher OsIntents.install registered, so what it returns is the wire map the system would have been handed — including how a thrown exception is turned into an error the user can be shown.

Inheritance
  • Object
  • PlatformInterface
  • OsIntentsPlatform
  • FakeOsIntentsPlatform

Constructors

FakeOsIntentsPlatform({bool donationsAccepted = true, int shortcutSlots = 15})

Properties

backgroundReadyCalled ↔ bool
getter/setter pair
donations → List<RecordedDonation>
Every donation, in order.
final
donationsAccepted → bool
Whether OsIntents.donate reports that the platform took the donation.
final
hashCode → int
The hash code for this object.
no setterinherited
phraseRefreshes ↔ int
How many times OsIntents.refreshShortcutPhrases was called.
getter/setter pair
readyCalled ↔ bool
Whether the app reported its handlers registered, per isolate.
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
shortcuts → List<Map<String, Object?>>
Dynamic shortcuts currently on the fake launcher, lowest rank first.
final
shortcutSlots → int
How many dynamic shortcuts this launcher holds. 0 stands in for iOS.
final
snippetReloads → List<String>
Ids passed to OsIntents.reloadSnippet, in order.
final
staticValues ↔ Map<String, Object?>
What was last published for Execution.static_ intents, keyed by id.
getter/setter pair

Methods

debugInvokeBackground(String id, Map<String, Object?> args) → Future<Map<String, Object?>?>
Forces an invocation through the headless engine, for development.
override
debugStaticValue(String id) → Future<String?>
What a static intent would answer with, read out of what was published.
override
Tells the system this intent just happened, so it can offer it later.
override
dynamicShortcuts() → Future<List<String>>
Ids of the dynamic shortcuts currently published, in rank order.
override
invokeIntent(String id, {Map<String, Object?> args = const {}, bool background = false}) → Future<Map<String, Object?>>
Invokes an intent the way the system does, through the installed dispatcher.
maxDynamicShortcuts() → Future<int>
How many dynamic shortcuts this launcher will hold, or 0 where there are none.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
publishStaticValues(Map<String, Object?> values) → Future<void>
Publishes values the Execution.static_ path reads without an engine.
override
pushDynamicShortcut(Map<String, Object?> shortcut) → Future<bool>
Publishes a launcher shortcut the app manages itself.
override
queryEntities(String method, Map<String, Object?> args, {bool background = false}) → Future<List<Map<String, Object?>>>
Answers an entity query the way the system does.
ready({bool background = false}) → Future<void>
Signals that Dart handlers are registered.
override
refreshShortcutPhrases() → Future<bool>
Re-reads the value lists behind parameterized phrases.
override
reloadSnippet(String id) → Future<bool>
Asks the system to redraw a liveSnippet intent's card.
override
removeDynamicShortcuts(List<String>? ids) → Future<void>
Removes dynamic shortcuts by id. Unknown ids are ignored.
override
setEntityHandler(EntityQueryHandler handler, {bool background = false}) → void
Installs the callback that answers entity queries.
override
setInvocationHandler(IntentInvocationHandler handler, {bool background = false}) → void
Installs the callback the native side routes invocations to.
override
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

install({bool donationsAccepted = true, int shortcutSlots = 15}) → FakeOsIntentsPlatform
Installs a fresh fake and forgets whatever a previous test installed.