Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing debug tab view UI above bottom tab bar #57772

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/components/Navigation/DebugTabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, {useCallback, useMemo} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import Button from '@components/Button';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
Expand All @@ -22,11 +23,11 @@ import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type {ReimbursementAccount} from '@src/types/onyx';
import BOTTOM_TABS from './BottomTabBar/BOTTOM_TABS';

type DebugTabViewProps = {
selectedTab?: string;
selectedTab?: ValueOf<typeof BOTTOM_TABS>;
chatTabBrickRoad: BrickRoad;
activeWorkspaceID?: string;
};
Expand Down Expand Up @@ -96,7 +97,7 @@ function getSettingsRoute(status: IndicatorStatus | undefined, reimbursementAcco
}
}

function DebugTabView({selectedTab = '', chatTabBrickRoad, activeWorkspaceID}: DebugTabViewProps) {
function DebugTabView({selectedTab, chatTabBrickRoad, activeWorkspaceID}: DebugTabViewProps) {
const StyleUtils = useStyleUtils();
const theme = useTheme();
const styles = useThemeStyles();
Expand All @@ -106,44 +107,44 @@ function DebugTabView({selectedTab = '', chatTabBrickRoad, activeWorkspaceID}: D
const {orderedReportIDs} = useReportIDs();

const message = useMemo((): TranslationPaths | undefined => {
if (selectedTab === SCREENS.HOME) {
if (selectedTab === BOTTOM_TABS.HOME) {
if (chatTabBrickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.INFO) {
return 'debug.indicatorStatus.theresAReportAwaitingAction';
}
if (chatTabBrickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR) {
return 'debug.indicatorStatus.theresAReportWithErrors';
}
}
if (selectedTab === SCREENS.SETTINGS.ROOT) {
if (selectedTab === BOTTOM_TABS.SETTINGS) {
return getSettingsMessage(status);
}
}, [selectedTab, chatTabBrickRoad, status]);

const indicator = useMemo(() => {
if (selectedTab === SCREENS.HOME) {
if (selectedTab === BOTTOM_TABS.HOME) {
if (chatTabBrickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.INFO) {
return theme.success;
}
if (chatTabBrickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR) {
return theme.danger;
}
}
if (selectedTab === SCREENS.SETTINGS.ROOT) {
if (selectedTab === BOTTOM_TABS.SETTINGS) {
if (status) {
return indicatorColor;
}
}
}, [selectedTab, chatTabBrickRoad, theme.success, theme.danger, status, indicatorColor]);

const navigateTo = useCallback(() => {
if (selectedTab === SCREENS.HOME && !!chatTabBrickRoad) {
if (selectedTab === BOTTOM_TABS.HOME && !!chatTabBrickRoad) {
const report = getChatTabBrickRoadReport(activeWorkspaceID, orderedReportIDs);

if (report) {
Navigation.navigate(ROUTES.DEBUG_REPORT.getRoute(report.reportID));
}
}
if (selectedTab === SCREENS.SETTINGS.ROOT) {
if (selectedTab === BOTTOM_TABS.SETTINGS) {
const route = getSettingsRoute(status, reimbursementAccount, policyIDWithErrors);

if (route) {
Expand All @@ -152,12 +153,15 @@ function DebugTabView({selectedTab = '', chatTabBrickRoad, activeWorkspaceID}: D
}
}, [selectedTab, chatTabBrickRoad, activeWorkspaceID, orderedReportIDs, status, reimbursementAccount, policyIDWithErrors]);

if (!([SCREENS.HOME, SCREENS.SETTINGS.ROOT] as string[]).includes(selectedTab) || !indicator) {
if (!([BOTTOM_TABS.HOME, BOTTOM_TABS.SETTINGS] as string[]).includes(selectedTab ?? '') || !indicator) {
return null;
}

return (
<View style={[StyleUtils.getBackgroundColorStyle(theme.cardBG), styles.p3, styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter]}>
<View
testID={DebugTabView.displayName}
style={[StyleUtils.getBackgroundColorStyle(theme.cardBG), styles.p3, styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter]}
>
<View style={[styles.flexRow, styles.gap2, styles.flex1, styles.alignItemsCenter]}>
<Icon
src={Expensicons.DotIndicator}
Expand Down
136 changes: 136 additions & 0 deletions tests/ui/BottomTabBarTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import {NavigationContainer} from '@react-navigation/native';
import {render, screen} from '@testing-library/react-native';
import Onyx from 'react-native-onyx';
import ComposeProviders from '@components/ComposeProviders';
import {LocaleContextProvider} from '@components/LocaleContextProvider';
import BottomTabBar from '@components/Navigation/BottomTabBar';
import BOTTOM_TABS from '@components/Navigation/BottomTabBar/BOTTOM_TABS';
import DebugTabView from '@components/Navigation/DebugTabView';
import OnyxProvider from '@components/OnyxProvider';
import {ReportIDsContextProvider} from '@hooks/useReportIDs';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

jest.mock('@src/hooks/useRootNavigationState');

describe('BottomTabBar', () => {
beforeAll(() => {
Onyx.init({keys: ONYXKEYS});
});
beforeEach(() => {
Onyx.clear();
});
describe('Home tab', () => {
describe('Debug mode enabled', () => {
beforeEach(() => {
Onyx.set(ONYXKEYS.USER, {isDebugModeEnabled: true});
});
describe('Has GBR', () => {
it('renders DebugTabView', async () => {
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}1`, {
reportID: '1',
reportName: 'My first report',
chatType: CONST.REPORT.CHAT_TYPE.SELF_DM,
type: CONST.REPORT.TYPE.CHAT,
hasOutstandingChildTask: true,
lastMessageText: 'Hello world!',
});

render(
<ComposeProviders components={[OnyxProvider, LocaleContextProvider, ReportIDsContextProvider]}>
<NavigationContainer>
<BottomTabBar selectedTab={BOTTOM_TABS.HOME} />
</NavigationContainer>
</ComposeProviders>,
);

expect(await screen.findByTestId(DebugTabView.displayName)).toBeOnTheScreen();
});
});
describe('Has RBR', () => {
it('renders DebugTabView', async () => {
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}1`, {
reportID: '1',
reportName: 'My first report',
chatType: CONST.REPORT.CHAT_TYPE.SELF_DM,
type: CONST.REPORT.TYPE.CHAT,
errorFields: {
error: {
message: 'Some error occurred!',
},
},
lastMessageText: 'Hello world!',
});

render(
<ComposeProviders components={[OnyxProvider, LocaleContextProvider, ReportIDsContextProvider]}>
<NavigationContainer>
<BottomTabBar selectedTab={BOTTOM_TABS.HOME} />
</NavigationContainer>
</ComposeProviders>,
);

expect(await screen.findByTestId(DebugTabView.displayName)).toBeOnTheScreen();
});
});
});
});
describe('Settings tab', () => {
describe('Debug mode enabled', () => {
beforeEach(() => {
Onyx.set(ONYXKEYS.USER, {isDebugModeEnabled: true});
});
describe('Has GBR', () => {
it('renders DebugTabView', async () => {
await Onyx.multiSet({
[ONYXKEYS.SESSION]: {
email: 'foo@bar.com',
},
[ONYXKEYS.LOGIN_LIST]: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'foo@bar.com': {
partnerUserID: 'john.doe@mail.com',
validatedDate: undefined,
},
},
});

render(
<ComposeProviders components={[OnyxProvider, LocaleContextProvider, ReportIDsContextProvider]}>
<NavigationContainer>
<BottomTabBar selectedTab={BOTTOM_TABS.SETTINGS} />
</NavigationContainer>{' '}
</ComposeProviders>,
);

expect(await screen.findByTestId(DebugTabView.displayName)).toBeOnTheScreen();
});
});
describe('Has RBR', () => {
it('renders DebugTabView', async () => {
await Onyx.set(ONYXKEYS.LOGIN_LIST, {
// eslint-disable-next-line @typescript-eslint/naming-convention
'foo@bar.com': {
partnerUserID: 'john.doe@mail.com',
errorFields: {
partnerName: {
message: 'Partner name is missing!',
},
},
},
});

render(
<ComposeProviders components={[OnyxProvider, LocaleContextProvider, ReportIDsContextProvider]}>
<NavigationContainer>
<BottomTabBar selectedTab={BOTTOM_TABS.SETTINGS} />
</NavigationContainer>{' '}
</ComposeProviders>,
);

expect(await screen.findByTestId(DebugTabView.displayName)).toBeOnTheScreen();
});
});
});
});
});