Sharing and link fakes
Check the links the app opens, open the app with a link, run a shortcut or share to the app in a unit test. import { openedURLs, openedAppSettings, openLink, runShortcut, receiveShare } from '@blotch/angular-lynx-testing-library';
Linking
Fakes LynxLinking both ways: links the app opens, and links that open the app. The link that started the app is render()'s initialURL option.
openedURLs()
The links the app opened with LynxLinking in this test, oldest first, so a spec can check where a tap leads. Each test starts with none.
inAppistrueforopenInApp(), andfalseforopenURL().- Nothing opens. Under the testing library, both resolve without opening anything.
canOpenURL()resolvestrue.
openedAppSettings()
How many times the app opened its own page in the phone's Settings with LynxLinking.openAppSettings() in this test, so a spec can check that a refused permission's button leads there. Each test starts at 0.
- Nothing opens. Under the testing library,
openAppSettings()resolves without opening anything. openedURLs()doesn't list it: Settings isn't a link.
openLink()
Opens the app with a link, so a spec can check where it leads. It's as if the person tapped a link with one of angular.json's deepLinkSchemes while the app was open.
- With
provideRouter(), the router navigates to the link's route. - Each
LynxLinking.onURL()handler is called with the URL. - It arrives through the background thread, as on a phone. Wait for it with
waitForUpdate(). - Sent before the app listens, it waits for the first handler, as a link that arrives while an app starts does.
- It's never the link that started the app.
getInitialURL()staysnull. Give that one torender()asinitialURL. - Each test starts with none waiting.
Shortcuts
Runs the app's shortcuts for LynxShortcuts.
runShortcut()
Runs one of the app's shortcuts, as the person does by asking Siri or from the app icon's menu. A spec can then check what the app does with it.
- A spec doesn't read angular.json. So
idonly has to be one the code under test handles withLynxShortcuts.on(). options.route: give a shortcut therouteit has in angular.json here. The router then navigates to it.- It arrives through the background thread, as on a phone. Wait for it with
waitForUpdate(). - Run before the app has injected
LynxShortcuts, it waits, as the shortcut that starts an app does. - Each test starts with none waiting.
Share target
Shares to the app for LynxShareTarget.
receiveShare()
Shares to the app, as the person does by picking it in another app's share sheet. A spec can then check what the app does with what LynxShareTarget.onShare() hands it.
- A spec doesn't read angular.json, so any text, link or file arrives, whatever
shareTarget.mimeTypeslists. - Each file's type is its Blob's.
- It arrives through the background thread. Await
receiveShare(), thenwaitForUpdate(). - Sent before the app registers a handler, it waits, as the share that starts an app does.
- Each test starts with none waiting.
