Skip to content

Commit 1a4f560

Browse files
committed
test(mfa): hydrate the session account in the ui walk harness
The session-hydration guard drops INIT while the account is still the context default placeholder, and the walk harness never mounted CurrentUserPersonalDetailsProvider, so every walked path failed to open the modal. Mount the provider and seed SESSION.accountID before each path.
1 parent 2688e92 commit 1a4f560

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

tests/unit/components/MultifactorAuthentication/machine/graphTraversal/viewMatchesMachine.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import {mfaNavigationRef} from '@components/MultifactorAuthentication/mfaNavigat
77
import type {MFAResult} from '@libs/MultifactorAuthentication/shared/MFAResult';
88

99
import CONST from '@src/CONST';
10+
import ONYXKEYS from '@src/ONYXKEYS';
1011
import SCREENS from '@src/SCREENS';
1112

1213
import type * as MfaRealUiMocks from 'tests/utils/mfa/realUi/mocks';
1314
import type {SnapshotFrom} from 'xstate';
1415

1516
import Onyx from 'react-native-onyx';
17+
import {MFA_TEST_ACCOUNT_ID} from 'tests/utils/mfa/flowFixtures';
1618
import getWalkedPaths, {
1719
isAutoDrivenEvent,
1820
READ_HAS_ACCEPTED_SOFT_PROMPT_DONE_EVENT_TYPE,
@@ -215,11 +217,14 @@ describe('the real MFA modal matches the machine at every step of every generate
215217
// The navigation buffer is deliberately not reset here. The machine resets it when it enters
216218
// `closed`, which also runs when each test's fresh actor starts, so a reset here would hide a
217219
// machine that stopped doing that cleanup. Onyx is cleared because approving the soft prompt
218-
// persists the acceptance, and no path may depend on what an earlier path stored.
220+
// persists the acceptance, and no path may depend on what an earlier path stored. The session
221+
// account is then seeded because the MFA context rejects a flow start while the account is
222+
// still the hydration placeholder.
219223
beforeEach(async () => {
220224
resetMfaUiMocks();
221225
await act(async () => {
222226
await Onyx.clear();
227+
await Onyx.merge(ONYXKEYS.SESSION, {accountID: MFA_TEST_ACCOUNT_ID});
223228
});
224229
await waitForBatchedUpdatesWithAct();
225230
});

tests/utils/mfa/realUi/harness.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {render} from '@testing-library/react-native';
22

33
import ComposeProviders from '@components/ComposeProviders';
4+
import {CurrentUserPersonalDetailsProvider} from '@components/CurrentUserPersonalDetailsProvider';
45
import {LocaleContextProvider} from '@components/LocaleContextProvider';
56
import {MultifactorAuthenticationContextProviders, useMultifactorAuthentication} from '@components/MultifactorAuthentication/Context';
67
import OnyxListItemProvider from '@components/OnyxListItemProvider';
@@ -30,14 +31,17 @@ function MfaControlsCapture({controlsRef}: {controlsRef: MfaControlsRef}) {
3031

3132
/**
3233
* Mounts the production MFA providers and modal navigator. The global safe-area mock provides fixed
33-
* values without a `SafeAreaProvider`. The returned `executeScenario` reads the captured controls at
34-
* call time because the provider recreates the context API on every render.
34+
* values without a `SafeAreaProvider`. `CurrentUserPersonalDetailsProvider` is required because the
35+
* MFA context rejects a flow start while the account is still the context default placeholder, so
36+
* each test must also seed `ONYXKEYS.SESSION` with an account ID before starting a flow. The
37+
* returned `executeScenario` reads the captured controls at call time because the provider recreates
38+
* the context API on every render.
3539
*/
3640
function renderMfaUi() {
3741
const controlsRef: MfaControlsRef = {current: undefined};
3842

3943
const renderResult = render(
40-
<ComposeProviders components={[OnyxListItemProvider, LocaleContextProvider]}>
44+
<ComposeProviders components={[OnyxListItemProvider, CurrentUserPersonalDetailsProvider, LocaleContextProvider]}>
4145
<MultifactorAuthenticationContextProviders>
4246
<MfaControlsCapture controlsRef={controlsRef} />
4347
<MultifactorAuthenticationModalNavigator />

0 commit comments

Comments
 (0)