Skip to content

Commit 81a4b8f

Browse files
committed
fix(MUSD-744): update Money tab test for new Tab.Screen registration
After moving MoneyScreenStack from a top-level Stack.Screen into a Tab.Screen inside HomeTabs, the conditional-rendering test could no longer find Routes.MONEY.ROOT among the outer Stack navigator's direct children. Render HomeTabs separately (mirroring the existing getHomeTabsComponent helper) and inspect the TabNavigator's children to assert the Money route is registered when the feature flag is on and absent when it is off.
1 parent c1cda22 commit 81a4b8f

1 file changed

Lines changed: 29 additions & 24 deletions

File tree

app/components/Nav/Main/MainNavigator.test.tsx

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,45 +1433,50 @@ describe('MainNavigator', () => {
14331433
});
14341434

14351435
describe('Money home screen conditional rendering', () => {
1436-
it('includes Money route when feature flag is enabled', () => {
1437-
mockSelectMoneyHomeScreenEnabledFlag.mockReturnValue(true);
1438-
1439-
const container = renderWithProvider(<MainNavigator />, {
1436+
const getHomeTabsScreenNames = (): string[] => {
1437+
const { root: mainRoot } = renderWithProvider(<MainNavigator />, {
14401438
state: initialRootState,
14411439
});
1442-
1443-
const screenProps = container.root.children
1440+
const homeScreen = mainRoot.findAll(
1441+
(node: ReactTestInstance) =>
1442+
node.type?.toString?.() === 'Screen' && node.props?.name === 'Home',
1443+
)[0];
1444+
const HomeTabs = homeScreen?.props?.component as React.ComponentType<
1445+
Record<string, unknown>
1446+
>;
1447+
const { root: homeRoot } = renderWithProvider(
1448+
<HomeTabs route={{ params: {} }} />,
1449+
{ state: initialRootState },
1450+
);
1451+
const tabNavigatorNode = homeRoot.findAll(
1452+
(node: ReactTestInstance) =>
1453+
node.type?.toString?.() === 'TabNavigator',
1454+
)[0];
1455+
return (tabNavigatorNode?.children ?? [])
14441456
.filter(
14451457
(child): child is ReactTestInstance =>
14461458
typeof child === 'object' &&
1447-
'type' in child &&
14481459
'props' in child &&
1449-
child.type?.toString() === 'Screen',
1460+
typeof child.props?.name === 'string',
14501461
)
1451-
.map((child) => child.props.name);
1462+
.map((child) => child.props.name as string);
1463+
};
1464+
1465+
it('includes Money route when feature flag is enabled', () => {
1466+
mockSelectMoneyHomeScreenEnabledFlag.mockReturnValue(true);
14521467

1453-
expect(screenProps).toContain(Routes.MONEY.ROOT);
1468+
const tabScreenNames = getHomeTabsScreenNames();
1469+
1470+
expect(tabScreenNames).toContain(Routes.MONEY.ROOT);
14541471
mockSelectMoneyHomeScreenEnabledFlag.mockReturnValue(false);
14551472
});
14561473

14571474
it('excludes Money route when feature flag is disabled', () => {
14581475
mockSelectMoneyHomeScreenEnabledFlag.mockReturnValue(false);
14591476

1460-
const container = renderWithProvider(<MainNavigator />, {
1461-
state: initialRootState,
1462-
});
1463-
1464-
const screenProps = container.root.children
1465-
.filter(
1466-
(child): child is ReactTestInstance =>
1467-
typeof child === 'object' &&
1468-
'type' in child &&
1469-
'props' in child &&
1470-
child.type?.toString() === 'Screen',
1471-
)
1472-
.map((child) => child.props.name);
1477+
const tabScreenNames = getHomeTabsScreenNames();
14731478

1474-
expect(screenProps).not.toContain(Routes.MONEY.ROOT);
1479+
expect(tabScreenNames).not.toContain(Routes.MONEY.ROOT);
14751480
});
14761481
});
14771482
});

0 commit comments

Comments
 (0)