Bluetooth, NFC and Wi-Fi fakes
Put a Bluetooth device in range, tap an NFC tag, or put the phone on a Wi-Fi network in a unit test. import { addBluetoothDevice, tapNfcTag, setWifiNetwork } from '@blotch/angular-lynx-testing-library';
Bluetooth
Fakes the radio behind LynxBluetooth. Each test starts with no devices and the radio on.
addBluetoothDevice()
Puts a Bluetooth LE device in range of the app. LynxBluetooth finds it, connects to it and talks to it as it would a real one.
- Scans see it. A running scan sees it at once, and one that starts later sees it as it starts.
- It advertises every service it has, unless
advertisedServicessays otherwise. - A characteristic can be read, written and notified, unless its
propertiessay otherwise. onWriteis called with each value the app writes, and the device. The spec can then answer as the real device does.- A write longer than the device takes is refused, as on a phone.
maxWriteLengthsets the limit for a write without response. - UUIDs are spelled either way, as
canonicalBluetoothUUID()reads them. - Adding an
ida second time throws.
The device it returns:
setBluetoothState()
Sets the state of the phone's Bluetooth, as the person turning it off or refusing permission does. A spec can then check what the app shows.
- Anything but
'poweredOn'ends a running scan and every connection, as it does on a phone. 'unknown'stands for not asked yet. The person allows it whenLynxBluetoothasks, asrequestPermission(),scan()andconnect()do.
NFC
Fakes LynxNfc's native module. Each test starts with a phone that reads tags, no session open and no writes.
Each answer reaches the app through the background thread, as on a phone. Wait for it with waitForUpdate().
tapNfcTag()
Brings a tag near the phone.
- The open
read()resolves with itsrecords. - The open
write()writes to it. - An open
scan()calls back with it. - With no session open yet, the next one takes it.
failNfcSession()
Ends the open session, or the next one, as iOS does: canceled when the person closes the sheet, timeout after a minute.
setNfcState()
Turns NFC off (disabled), or takes the reader away (unsupported).
state() reads it at startup, and each time the app comes back. Send the app away and back with setAppState().
nfcSession()
Says what's open: its alertMessage, whether it's a scan() (multiple), and whether it's writing.
nfcWrites()
Lists the records each write() wrote, as a read gives them back.
Wi-Fi
Fakes the network behind LynxWifi. Each test starts off Wi-Fi, with no joins.
setWifiNetwork()
Puts the spec's phone on network, which LynxWifi.currentNetwork() resolves from then on. null takes it off Wi-Fi.
- A successful
join()puts the phone on the network it joined. leave()puts it back where it was.
denyWifiNetworkRead()
Makes currentNetwork() reject with a WifiError of code from then on.
codeisdeniedby default.- The default message for
deniedis the one an Android app gets when the person refuses the location prompt.
allowWifiNetworkRead()
Lets currentNetwork() read the network again, after denyWifiNetworkRead().
queueWifiJoinResult()
Answers the next LynxWifi.join() with result: joined, which puts the phone on the network, or a WifiError of that code.
- Each call answers one join, in order.
- Without one, a join succeeds.
wifiJoins()
The networks the app joined through LynxWifi.join() in this test, oldest first, answered or not. Each test starts with none.
wifiLeaves()
The names of the networks the app left in this test. Each test starts with none.
