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
2 changes: 2 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ const EMAIL = {
SVFG: 'svfg@expensify.com',
EXPENSIFY_EMAIL_DOMAIN: '@expensify.com',
EXPENSIFY_TEAM_EMAIL_DOMAIN: '@team.expensify.com',
TEAM: 'team@expensify.com',
MANAGER_MCTEST: 'manager_mctest@expensify.com',
};

Expand Down Expand Up @@ -3522,6 +3523,7 @@ const CONST = {
EMAIL.RECEIPTS,
EMAIL.STUDENT_AMBASSADOR,
EMAIL.SVFG,
EMAIL.TEAM,
EMAIL.MANAGER_MCTEST,
] as string[],
get EXPENSIFY_ACCOUNT_IDS() {
Expand Down
66 changes: 54 additions & 12 deletions tests/ui/NewChatPageTest.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as NativeNavigation from '@react-navigation/native';
import {act, fireEvent, render, screen} from '@testing-library/react-native';
import {act, fireEvent, render, screen, waitFor, within} from '@testing-library/react-native';
import React from 'react';
import {SectionList} from 'react-native';
import Onyx from 'react-native-onyx';
Expand All @@ -9,12 +9,25 @@ import OptionsListContextProvider from '@components/OptionListContextProvider';
import ScreenWrapper from '@components/ScreenWrapper';
import {translateLocal} from '@libs/Localize';
import NewChatPage from '@pages/NewChatPage';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {NativeNavigationMock} from '../../__mocks__/@react-navigation/native';
import {fakePersonalDetails} from '../utils/LHNTestUtils';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';

jest.mock('@react-navigation/native');
jest.mock('@src/libs/Navigation/navigationRef');

const wrapper = ({children}: {children: React.ReactNode}) => (
<OnyxProvider>
<LocaleContextProvider>
<OptionsListContextProvider>
<ScreenWrapper testID="test">{children}</ScreenWrapper>
</OptionsListContextProvider>
</LocaleContextProvider>
</OnyxProvider>
);

describe('NewChatPage', () => {
beforeAll(() => {
Expand All @@ -24,19 +37,15 @@ describe('NewChatPage', () => {
jest.spyOn(NativeNavigation, 'useRoute').mockReturnValue({key: '', name: ''});
});

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

it('should scroll to top when adding a user to the group selection', async () => {
await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails);
render(
<OnyxProvider>
<LocaleContextProvider>
<OptionsListContextProvider>
<ScreenWrapper testID="test">
<NewChatPage />
</ScreenWrapper>
</OptionsListContextProvider>
</LocaleContextProvider>
</OnyxProvider>,
);
render(<NewChatPage />, {wrapper});
await waitForBatchedUpdatesWithAct();
await act(() => {
(NativeNavigation as NativeNavigationMock).triggerTransitionEnd();
Expand All @@ -49,4 +58,37 @@ describe('NewChatPage', () => {
expect(spy).toHaveBeenCalledWith(expect.objectContaining({itemIndex: 0}));
}
});

describe('should not display "Add to group" button on expensify emails', () => {
const excludedGroupEmails = CONST.EXPENSIFY_EMAILS.filter((value) => value !== CONST.EMAIL.CONCIERGE && value !== CONST.EMAIL.NOTIFICATIONS).map((email) => [email]);

it.each(excludedGroupEmails)('%s', async (email) => {
// Given that a personal details list is initialized in Onyx
await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, {
// eslint-disable-next-line @typescript-eslint/naming-convention
'1': {accountID: 1, login: email},
});

// And NewChatPage is opened
render(<NewChatPage />, {wrapper});
await waitForBatchedUpdatesWithAct();
await act(() => {
(NativeNavigation as NativeNavigationMock).triggerTransitionEnd();
});

// And email is entered into the search input
const input = screen.getByTestId('selection-list-text-input');
fireEvent.changeText(input, email);

// And waited for the user option to appear
await waitFor(() => {
expect(screen.getByLabelText(email)).toBeOnTheScreen();
});

// Then "Add to group" button should not appear
const userOption = screen.getByLabelText(email);
const addButton = within(userOption).queryByText(translateLocal('newChatPage.addToGroup'));
expect(addButton).not.toBeOnTheScreen();
});
});
});