Device and host fakes
Send the app to the background, take the phone offline, or press Android's back button in a unit test. import { setAppState, setOnline, pressBackButton } from '@blotch/angular-lynx-testing-library';
App state
Fakes what LynxAppState reports. Each test starts 'active'.
setAppState()
Sends the app to the background, or brings it back, as the person does by leaving the app and returning. A spec can then check what the app does on its return.
LynxAppState.state()becomesstate, andactive()istrueonly for'active'.'inactive'is an app on screen that isn't taking touches, such as with Control Center pulled over it, or a call coming in.- It arrives as a change to the host's global props, as on a phone. Wait for it with
waitForUpdate(). - Wait between two states too. Otherwise an
effect()runs once for both, and never sees the app leave.
Network
Fakes what LynxNetwork reports. Each test starts online.
setOnline()
Takes the phone offline, or brings it back online. A spec can then check what the app shows without a connection, and what it does once it's back.
LynxNetwork.online()becomesonline.- It arrives as a change to the host's global props, as on a phone. Wait for it with
waitForUpdate(). - Wait between two changes too. Otherwise an
effect()runs once for both, and never sees the phone go offline. - It changes only what
LynxNetworkreports. Requests go on as the spec's fakes answer them.
Back button
Presses Android's back button for LynxBackButton and the router. Each test starts with back left to Android.
pressBackButton()
Presses Android's back button, so a spec can check what the app does with it. The app may close what's open on top, with a handler registered with LynxBackButton.on(). Or it may go back a screen through the router.
- It returns
falsewhen the app doesn't take back. As on Android, the press reaches the app only while the app takes back. Otherwise Android would leave the app. - It arrives through the background thread, as on a phone. Wait for it with
waitForUpdate(). - An
<overlay>takes back before the app on a phone. Fire itsrequestcloseevent for that instead.
