Camera, photo and file fakes
Pick or take a photo, scan a code, save to Photos or pick a file in a unit test. import { setPickedImage, queueBarcodeScan, setPickedFiles } from '@blotch/angular-lynx-testing-library';
Image picker
Answers LynxImagePicker.pick(), since a spec has no library to pick from or camera to point. Each test starts with nothing to pick and no requests.
- Each answer lasts for the rest of the test.
- Until a spec gives it an image,
pick()rejects withunavailable. - The fake hands back the bytes as you gave them. It doesn't scale or re-encode them for
maxDimensionorquality.
setPickedImage()
Has the person pick image from the library: pick() resolves with it. null closes the picker, and pick() resolves with null.
setTakenPhoto()
Has the person take image with the camera (source: 'camera'): pick() resolves with it. null closes the camera, and pick() resolves with null.
failImagePicker()
Has pick() reject with code, such as denied for a person who won't let the app use the camera.
imagePickerRequests()
Lists the picks the app asked for, oldest first.
Barcode scanner
Answers LynxBarcodeScanner.scan(), since a spec has no camera to point. Each test starts with no scan open and nothing queued.
- A scan stays open until one of these functions answers it.
- Each call answers the open scan. When none is open, it answers the next one as soon as it's called, in order.
- The answer reaches the app through the background thread, as on a phone. Wait for it with
waitForUpdate().
queueBarcodeScan()
Reads scan, as if the person pointed the camera at it: scan() resolves with it.
cancelBarcodeScan()
Closes the scanner, as the Cancel button does: scan() rejects with canceled.
failBarcodeScan()
Rejects with code, such as denied for a person who won't let the app use the camera.
Photo library
Stands in for the phone's photo library behind LynxPhotoLibrary.
- Saves reach the app through the background thread, so wait with
waitForUpdate(). - Set the permission before rendering. The service reads it when it's created, after each save, and when the app comes back to the front (
setAppState()).
savedPhotos()
Lists what save() added in this test, oldest first, with the ID it resolved with.
setPhotoLibraryPermission()
Sets what the person has answered.
deniedmakessave()reject withpermission-denied.unsupportedmakes it reject withunavailable.- Each test starts
undetermined: the first save asks, and the person allows it.
File picker
Stands in for the person using LynxFilePicker's picker and save screen.
setPickedFiles()
Has the person pick files each time the app opens the picker in this test.
- Until a spec calls it, the person closes the picker, and
pick()resolves with[]. - Files over 20 MiB together reject with
too-large, as on a phone.
setFilePickerCanceled()
Has the person close the picker and the save screen for the rest of the test. pick() resolves with [], and save() with false. setPickedFiles() undoes it.
savedFiles()
The files the app saved with LynxFilePicker.save() in this test, oldest first. Each test starts with none.
