Sensor and audio fakes
Put the phone somewhere, tilt it, ask for Face ID, record audio or play it in a unit test. import { setLocation, emitMotion } from '@blotch/angular-lynx-testing-library';
Location
Fakes the phone behind LynxGeolocation. Each test starts with permission unknown, not allowed all the time, and no location. It acts as an app with backgroundLocation and permissions.locationAlways, so a background watch runs as any other, and areas work.
setLocation()
Puts the phone at location. It's what getCurrentPosition() resolves with, and the next position each running watch gets.
- A watch skips it when it's nearer the last one than the watch's
distanceFilter. - An area
watchRegion()watches hearsenterwhen it takes the phone into it, andexitwhen it takes it out. An area started with the phone inside hearsenterat once. - Only
latitudeandlongitudeare needed.accuracyis 5 meters andtimestampnow, unless you give them. - Until a spec sets one, or after
null, the phone can't find itself.getCurrentPosition()rejects withtimeout.
setLocationPermission()
Sets what the app is allowed, as if the person had answered the prompt or changed it in Settings. It's what state() reports.
- At
unknown, the first call that needs the location shows the prompt. deniedends every running watch withdenied, as it does on a phone.- Anything but
preciseends every area withdenied, since areas need the precise location.
setLocationAlways()
Sets whether the app may find the phone all the time, as if the person had chosen in Settings. It's what always() reports while the location is allowed. false ends every area with denied.
setLocationAnswer()
What the person answers when the prompt shows: precise by default. The prompt shows only while the permission is unknown.
setLocationAlwaysAnswer()
What the person answers when requestPermission({ always: true }) or watchRegion() asks for the location all the time: true (allow it) by default. It asks once, after the location prompt if that shows too, as iOS does, and not after setLocationAlways().
setLocationEnabled()
Turns Location on or off for the whole phone. Off, state() is off whatever the app is allowed. Calls reject with off, and every running watch and area ends with off.
locationPrompts()
How many times a location prompt showed in this test, the one for the location all the time included. A spec can check the app asks at the right moment, and only once. Each test starts at 0.
Motion
Stands in for a phone with every sensor, for LynxMotion. Each function sends what the iOS and Android apps send, through the background thread. Wait for it with waitForUpdate().
A sensor nothing watches isn't running, so nothing reaches the app, as on a phone.
emitMotion()
Sends a sample to the app's watchAcceleration(), watchRotation() and watchOrientation() watches.
setHeading()
Sends a compass heading to the app's watchHeading() watches: degrees from magnetic north, or an object with the true heading and accuracy too.
shakeDevice()
Runs the app's onShake() handlers, the ones listening when it's called.
Sample timestamps
- A sample without a
timestampcounts as a second after the latest one sent, of any sensor, or now, if that's later. So a watch whoseintervalis a second or less gets it at once. - A sample with one is stamped as given. Each watch is spaced by its own
interval, as on a phone: a sample stamped closer to the last one the watch got than itsintervalis held back. - A held sample arrives an
intervallater, by the timers, unless a newer sample comes first. With1000and then1050, a 100 ms watch gets the first at once and the second 100 ms later. Advance fake timers to see it, or stamp samples at least a watch'sintervalapart.
Biometrics
Fakes the phone behind LynxBiometrics and LynxSecureStorage's requireBiometrics. They see it as they see the native module on a phone.
Each test starts with a phone that has Face ID set up behind a passcode, where every prompt succeeds.
setBiometrics()
Changes the phone. What you leave out keeps its value. { type: 'none' } is a phone without a sensor, or an app without permissions.biometrics.
queueBiometricResult()
Has the next prompt end that way, such as 'canceled'. Results queue one per prompt. Once they run out, prompts succeed.
biometricPrompts()
Lists the prompts the app showed, oldest first: each authenticate(), and each read of a value kept behind biometrics.
Audio recorder
Fakes LynxAudioRecorder's native module. Each test starts with a person who hasn't been asked for the microphone: the first start() asks, and they allow it.
setMicrophonePermission()
Sets what the person answered. denied has start() reject with denied, and unsupported with unavailable.
Set it before rendering: permission() reads it at startup, and each time the app comes back.
setRecordedAudio()
Sets what the clips hold:
bytes: whatblob()resolves with.mimeType:audio/mp4by default.durationMs: without it, a clip is as long as it recorded by the clock, pauses left out.vi.useFakeTimers()moves that clock.
clip.delete() deletes the fake phone's file, as a phone does, and blob() rejects after it.
emitAudioLevel()
Sends the open recording's level, from 0 to 1, as a phone does about ten times a second. Once the recording is as long as its maxDuration, it ends instead, and stop() resolves with the clip.
interruptAudioRecording()
Pauses the recording, as a phone call or going to the background does.
failAudioRecording()
Ends the recording with a failed error, which stop() rejects with.
audioRecording()
Says what's open: its state (recording or paused) and maxDuration.
Audio player
Fakes LynxAudioPlayer's native module. A track loads at once, a minute long unless the track or setAudioFile() says, and plays by the clock: its position moves with fake timers, and the module sends it four times a second, as a phone does, until it ends.
Fake Date and the intervals, and leave the frames change detection waits for on the real clock:
setAudioFile()
Sets what the phone finds at url:
duration: how long it plays, in seconds.error: why it won't load:network,unsupported-formatorfailed.load()rejects with it.
audioPlayback()
Says what's loaded, or undefined before load() and after stop(): its state (playing, paused or ended), position and duration in seconds, the track the lock screen shows, and the remoteCommands the app takes with onRemoteCommand().
pressRemoteCommand()
Presses a lock-screen button, as a phone hears it: a command the app takes goes to its handler, and play, pause and seek act on the player otherwise. position is where the slider was moved to, for seek. It throws for next or previous while the app doesn't take them, since the lock screen doesn't show them then, and with nothing loaded.
interruptAudioPlayback()
Pauses the track, as a phone call does.
failAudioPlayback()
Stops the track with an error, as a dropped connection does: state turns error, and error() holds the AudioPlayerError. network by default.
