Sign-in, review and tracking fakes
Sign in with Apple, count rating requests, or answer the tracking prompt in a unit test. import { setAppleSignInResult, reviewRequests, setTrackingStatus } from '@blotch/angular-lynx-testing-library';
Sign in with Apple
Fakes LynxAppleSignIn's native module.
- Each test starts with the sheet there, no sign-ins and no users.
- Until a spec answers, the person closes the sheet, and
signIn()rejects withcanceled. - The answer reaches the app through the background thread, as on a phone. Wait for it with
waitForUpdate().
setAppleSignInResult()
Has the person sign in from now on in this test: signIn() resolves with result.
emailandfullNameare shared only when the sign-in asks for their scopes, as Apple does.- What's left out takes a test value.
useristest-apple-user, and the tokens aretest-identity-tokenandtest-authorization-code. - Each user it signs in is
authorizedafterwards.
setAppleSignInError()
Has the next sign-ins reject with code.
setAppleSignInAvailable()
false takes the native sheet away, as on Android and the web.
isAvailable()resolvesfalse, andsignIn()rejects withunsupported.- An
<apple-sign-in-button>made after it is the one the runtime draws, rather than iOS's element.getByText()finds its title.
setAppleCredentialState()
Sets what getCredentialState(user) resolves with. A user nobody signed in is notFound.
appleSignInRequests()
Lists the sign-ins the app opened, with the scopes, nonce and state each asked for.
Store review
Counts the rating requests LynxStoreReview makes.
reviewRequests()
How many times the app asked for a rating with LynxStoreReview.request() in this test. A spec can check it asks at the right moment, and only then.
request()resolves without showing anything.- Each test starts at 0.
Tracking
Fakes whether the app may track the person, for LynxTracking. Each test starts at notDetermined.
setTrackingStatus()
Sets whether the app may track the person, as if they'd answered the prompt or changed it in Settings. It's what status() reads, and what requestPermission() resolves with.
FakeTrackingStatus takes the same values as TrackingStatus.
LynxTracking reads the status when it's created, and again when the app comes back to the foreground. So set it before render():
Or, after render(), follow it with setAppState('background') and setAppState('active'), as a person coming back from Settings would. Await waitForUpdate() after each. Without the wait between them, the app never seems to leave, and the status isn't read again:
setTrackingAnswer()
What the person answers when requestPermission() shows the prompt: authorized by default. The prompt shows only while the status is notDetermined.
trackingPrompts()
How many times requestPermission() showed the prompt in this test. A spec can check the app asks at the right moment, and only once. Each test starts at 0.
