Skip to content
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
3 changes: 2 additions & 1 deletion src/pages/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
isHiddenForCurrentUser as isReportHiddenForCurrentUser,
navigateToPrivateNotes,
} from '@libs/ReportUtils';
import {isAgentEmail} from '@libs/SessionUtils';
import {generateAccountID} from '@libs/UserUtils';
import {isValidAccountRoute} from '@libs/ValidationUtils';
import type {ProfileNavigatorParamList} from '@navigation/types';
Expand Down Expand Up @@ -124,7 +125,7 @@ function ProfilePage({route}: ProfilePageProps) {

// If we have a reportID param this means that we
// arrived here via the ParticipantsPage and should be allowed to navigate back to it
const shouldShowLocalTime = !hasAutomatedExpensifyAccountIDs([accountID]) && !isEmptyObject(timezone) && isParticipantValidated;
const shouldShowLocalTime = !hasAutomatedExpensifyAccountIDs([accountID]) && !isAgentEmail(login) && !isEmptyObject(timezone) && isParticipantValidated;
Comment thread
NicolasBonet marked this conversation as resolved.
Resolved
let pronouns = details?.pronouns ?? '';
if (pronouns?.startsWith(CONST.PRONOUNS.PREFIX)) {
const localeKey = pronouns.replace(CONST.PRONOUNS.PREFIX, '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {usePersonalDetails} from '@components/OnyxListItemProvider';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useOnyx from '@hooks/useOnyx';
import {canShowReportRecipientLocalTime, getReportOfflinePendingActionAndErrors, getReportRecipientAccountIDs} from '@libs/ReportUtils';
import {isAgentEmail} from '@libs/SessionUtils';
import ParticipantLocalTime from '@pages/inbox/report/ParticipantLocalTime';
import ONYXKEYS from '@src/ONYXKEYS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
Expand All @@ -23,7 +24,7 @@ function ComposerLocalTime({reportID}: ComposerLocalTimeProps) {
const reportRecipientAccountIDs = getReportRecipientAccountIDs(report, currentUserPersonalDetails.accountID);
const reportRecipient = personalDetails?.[reportRecipientAccountIDs[0]];

if (!shouldShow || isEmptyObject(reportRecipient)) {
if (!shouldShow || isEmptyObject(reportRecipient) || isAgentEmail(reportRecipient?.login)) {
Comment thread
NicolasBonet marked this conversation as resolved.
Resolved
return null;
}

Expand Down
102 changes: 102 additions & 0 deletions tests/unit/ComposerLocalTimeTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import {render, screen} from '@testing-library/react-native';
import React from 'react';
import Onyx from 'react-native-onyx';
import ComposeProviders from '@components/ComposeProviders';
import {LocaleContextProvider} from '@components/LocaleContextProvider';
import OnyxListItemProvider from '@components/OnyxListItemProvider';
import ComposerLocalTime from '@pages/inbox/report/ReportActionCompose/ComposerLocalTime';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetailsList, Report} from '@src/types/onyx';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

const CURRENT_USER_ACCOUNT_ID = 1;
const RECIPIENT_ACCOUNT_ID = 2;
const REPORT_ID = '1';

jest.mock('@hooks/useCurrentUserPersonalDetails', () => ({
__esModule: true,
default: () => ({accountID: CURRENT_USER_ACCOUNT_ID}),
}));

jest.mock('@libs/Navigation/Navigation', () => ({
navigate: jest.fn(),
getActiveRouteWithoutParams: jest.fn(() => ''),
isNavigationReady: jest.fn(() => Promise.resolve()),
}));

function buildReport(participantAccountIDs: number[]): Report {
const participants: Report['participants'] = {};
for (const id of participantAccountIDs) {
participants[id] = {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS};
}
return {
reportID: REPORT_ID,
type: CONST.REPORT.TYPE.CHAT,
participants,
} as Report;
}

function renderWithProviders(component: React.ReactElement) {
return render(<ComposeProviders components={[OnyxListItemProvider, LocaleContextProvider]}>{component}</ComposeProviders>);
}

describe('ComposerLocalTime', () => {
beforeAll(() => {
Onyx.init({keys: ONYXKEYS});
});

afterEach(async () => {
await Onyx.clear();
});

it('renders local time for a non-agent participant', async () => {
const report = buildReport([CURRENT_USER_ACCOUNT_ID, RECIPIENT_ACCOUNT_ID]);
const personalDetails: PersonalDetailsList = {
[RECIPIENT_ACCOUNT_ID]: {
accountID: RECIPIENT_ACCOUNT_ID,
login: 'normaluser@expensify.com',
displayName: 'Normal User',
firstName: 'Normal',
validated: true,
timezone: {automatic: true, selected: 'America/New_York'},
},
};

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails);
await waitForBatchedUpdates();

renderWithProviders(<ComposerLocalTime reportID={REPORT_ID} />);

await waitForBatchedUpdates();

// ParticipantLocalTime renders a text with the participant's name and local time
expect(screen.getByText(/Normal/)).toBeTruthy();
});

it('returns null for an agent participant', async () => {
const report = buildReport([CURRENT_USER_ACCOUNT_ID, RECIPIENT_ACCOUNT_ID]);
const personalDetails: PersonalDetailsList = {
[RECIPIENT_ACCOUNT_ID]: {
accountID: RECIPIENT_ACCOUNT_ID,
login: 'agent_999@expensify.ai',
displayName: 'Agent 999',
firstName: 'Agent',
validated: true,
timezone: {automatic: true, selected: 'America/New_York'},
},
};

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails);
await waitForBatchedUpdates();

const {toJSON} = renderWithProviders(<ComposerLocalTime reportID={REPORT_ID} />);

await waitForBatchedUpdates();

// Component should render nothing for agent emails
expect(toJSON()).toBeNull();
});
});
Loading