-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[No QA] GBR/RBR on ContactMethodsPage and ProfilePage UI tests #72966
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
Merged
mountiny
merged 7 commits into
Expensify:main
from
software-mansion-labs:jnowakow/contact-page-ui-tests
Oct 20, 2025
+280
−0
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
63b725b
UI tests for ContactMethodsPage
jnowakow 6f8d2fc
UI tests for ProfilePage
jnowakow 2139da4
Fix prettier
jnowakow 588ee7b
Fix spelling
jnowakow ac715b1
Add empty lines before comments
jnowakow 09c9182
More new lines
jnowakow e22f352
Fix prettier
jnowakow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,140 @@ | ||||||||
| import {render, screen, waitFor} from '@testing-library/react-native'; | ||||||||
| import React from 'react'; | ||||||||
| import Onyx from 'react-native-onyx'; | ||||||||
| import type {ValueOf} from 'type-fest'; | ||||||||
| import ComposeProviders from '@components/ComposeProviders'; | ||||||||
| import ContactMethodsPage from '@pages/settings/Profile/Contacts/ContactMethodsPage'; | ||||||||
| import DelegateNoAccessModalProvider from '@src/components/DelegateNoAccessModalProvider'; | ||||||||
| import LockedAccountModalProvider from '@src/components/LockedAccountModalProvider'; | ||||||||
| import type CONST from '@src/CONST'; | ||||||||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||||||||
| import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||||||||
|
|
||||||||
| // Mock navigation used by the page | ||||||||
| jest.mock('@libs/Navigation/Navigation', () => ({ | ||||||||
| navigate: jest.fn(), | ||||||||
| goBack: jest.fn(), | ||||||||
| getActiveRoute: jest.fn(() => ''), | ||||||||
| })); | ||||||||
|
|
||||||||
| // Replace MenuItem with a simple test double that exposes props in the tree | ||||||||
| jest.mock('@components/MenuItem', () => { | ||||||||
| const ReactMock = require('react') as typeof React; | ||||||||
| const {Text} = require('react-native') as {Text: React.ComponentType<{testID: string; children?: React.ReactNode}>}; | ||||||||
| return ({title, brickRoadIndicator}: {title: string; brickRoadIndicator?: ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS>}) => | ||||||||
| ReactMock.createElement(Text, {testID: `menu-${String(title)}`}, `${brickRoadIndicator ?? 'none'}-brickRoadIndicator`); | ||||||||
| }); | ||||||||
|
|
||||||||
| describe('ContactMethodsPage', () => { | ||||||||
| beforeAll(() => { | ||||||||
| Onyx.init({ | ||||||||
| keys: ONYXKEYS, | ||||||||
| }); | ||||||||
| }); | ||||||||
|
|
||||||||
| beforeEach(() => { | ||||||||
| return Onyx.clear(); | ||||||||
| }); | ||||||||
|
|
||||||||
| function renderPage() { | ||||||||
| return render( | ||||||||
| <ComposeProviders components={[LockedAccountModalProvider, DelegateNoAccessModalProvider]}> | ||||||||
| {/* @ts-expect-error - route typing is not necessary for this test */} | ||||||||
| <ContactMethodsPage route={{params: {}}} /> | ||||||||
| </ComposeProviders>, | ||||||||
| ); | ||||||||
| } | ||||||||
|
|
||||||||
| it('sets error indicator when login has error fields', async () => { | ||||||||
| // Given a login list entry with errorFields set | ||||||||
| const defaultEmail = 'default@example.com'; | ||||||||
| const otherEmail = 'other@example.com'; | ||||||||
| Onyx.merge(ONYXKEYS.SESSION, {email: defaultEmail}); | ||||||||
| Onyx.merge(ONYXKEYS.LOGIN_LIST, { | ||||||||
| [defaultEmail]: { | ||||||||
| partnerUserID: defaultEmail, | ||||||||
| validatedDate: '2024-01-01', | ||||||||
| }, | ||||||||
| [otherEmail]: { | ||||||||
| partnerUserID: otherEmail, | ||||||||
| validatedDate: '', | ||||||||
| errorFields: { | ||||||||
| error: {field: 'dummy'}, | ||||||||
| }, | ||||||||
| }, | ||||||||
| }); | ||||||||
| await waitForBatchedUpdates(); | ||||||||
|
|
||||||||
| renderPage(); | ||||||||
|
|
||||||||
| let node = screen.getByTestId(`menu-${defaultEmail}`); | ||||||||
|
|
||||||||
| // ContactMethodsPage doesn't set any BR for validated logins | ||||||||
| expect(node).toHaveTextContent('none-brickRoadIndicator'); | ||||||||
|
|
||||||||
| node = screen.getByTestId(`menu-${otherEmail}`); | ||||||||
|
|
||||||||
| // ContactMethodsPage sets brickRoadIndicator to 'error' when any errorFields are present | ||||||||
| expect(node).toHaveTextContent('error-brickRoadIndicator'); | ||||||||
|
|
||||||||
| // Verify that RBR disappears | ||||||||
| Onyx.merge(ONYXKEYS.LOGIN_LIST, { | ||||||||
| [otherEmail]: { | ||||||||
| partnerUserID: otherEmail, | ||||||||
| validatedDate: '2024-02-02', | ||||||||
| errorFields: null, | ||||||||
| }, | ||||||||
| }); | ||||||||
|
|
||||||||
| await waitFor(() => { | ||||||||
| node = screen.getByTestId(`menu-${otherEmail}`); | ||||||||
|
|
||||||||
| // ContactMethodsPage sets brickRoadIndicator to 'info' for non-default unvalidated logins | ||||||||
| expect(node).toHaveTextContent('none-brickRoadIndicator'); | ||||||||
| }); | ||||||||
| }); | ||||||||
|
|
||||||||
| it('sets info indicator when login is unvalidated and not default', async () => { | ||||||||
| // Given two logins: default (session email) validated, and another unvalidated | ||||||||
| const defaultEmail = 'default@example.com'; | ||||||||
| const otherEmail = 'other@example.com'; | ||||||||
| Onyx.merge(ONYXKEYS.SESSION, {email: defaultEmail}); | ||||||||
| Onyx.merge(ONYXKEYS.LOGIN_LIST, { | ||||||||
| [defaultEmail]: { | ||||||||
| partnerUserID: defaultEmail, | ||||||||
| validatedDate: '2024-01-01', | ||||||||
| }, | ||||||||
| [otherEmail]: { | ||||||||
| partnerUserID: otherEmail, | ||||||||
| validatedDate: '', | ||||||||
| }, | ||||||||
| }); | ||||||||
| await waitForBatchedUpdates(); | ||||||||
|
|
||||||||
| renderPage(); | ||||||||
| let node = screen.getByTestId(`menu-${defaultEmail}`); | ||||||||
|
|
||||||||
| // ContactMethodsPage doesn't set any BR for validated logins | ||||||||
| expect(node).toHaveTextContent('none-brickRoadIndicator'); | ||||||||
|
|
||||||||
| node = screen.getByTestId(`menu-${otherEmail}`); | ||||||||
|
|
||||||||
| // ContactMethodsPage sets brickRoadIndicator to 'info' for non-default unvalidated logins | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| expect(node).toHaveTextContent('info-brickRoadIndicator'); | ||||||||
|
|
||||||||
| // Verify that GBR disappears | ||||||||
| Onyx.merge(ONYXKEYS.LOGIN_LIST, { | ||||||||
| [otherEmail]: { | ||||||||
| partnerUserID: otherEmail, | ||||||||
| validatedDate: '2024-02-02', | ||||||||
| }, | ||||||||
| }); | ||||||||
|
|
||||||||
| await waitFor(() => { | ||||||||
| node = screen.getByTestId(`menu-${otherEmail}`); | ||||||||
|
|
||||||||
| // ContactMethodsPage sets brickRoadIndicator to 'info' for non-default unvalidated logins | ||||||||
| expect(node).toHaveTextContent('none-brickRoadIndicator'); | ||||||||
| }); | ||||||||
| }); | ||||||||
| }); | ||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,138 @@ | ||||||||
| import {NavigationContainer} from '@react-navigation/native'; | ||||||||
| import type * as ReactNavigation from '@react-navigation/native'; | ||||||||
| import {render, screen, waitFor} from '@testing-library/react-native'; | ||||||||
| import React from 'react'; | ||||||||
| import Onyx from 'react-native-onyx'; | ||||||||
| import type {ValueOf} from 'type-fest'; | ||||||||
| import ComposeProviders from '@components/ComposeProviders'; | ||||||||
| import DelegateNoAccessModalProvider from '@components/DelegateNoAccessModalProvider'; | ||||||||
| import ProfilePage from '@pages/settings/Profile/ProfilePage'; | ||||||||
| import type CONST from '@src/CONST'; | ||||||||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||||||||
| import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||||||||
|
|
||||||||
| jest.mock('@libs/Navigation/Navigation', () => ({ | ||||||||
| navigate: jest.fn(), | ||||||||
| goBack: jest.fn(), | ||||||||
| getActiveRoute: jest.fn(() => ''), | ||||||||
| getShouldPopToSidebar: jest.fn(() => false), | ||||||||
| popToSidebar: jest.fn(), | ||||||||
| })); | ||||||||
|
|
||||||||
| jest.mock('@react-navigation/native', () => { | ||||||||
| const actualNav = jest.requireActual<typeof ReactNavigation>('@react-navigation/native'); | ||||||||
| return { | ||||||||
| ...actualNav, | ||||||||
| useRoute: jest.fn(), | ||||||||
| createNavigationContainerRef: () => ({ | ||||||||
| getState: () => jest.fn(), | ||||||||
| }), | ||||||||
| usePreventRemove: jest.fn(), | ||||||||
| }; | ||||||||
| }); | ||||||||
|
|
||||||||
| // Replace MenuItemWithTopDescription with a simple test double that exposes props in the tree | ||||||||
| jest.mock('@components/MenuItemWithTopDescription', () => { | ||||||||
| const ReactMock = require('react') as typeof React; | ||||||||
| const {Text} = require('react-native') as {Text: React.ComponentType<{testID: string; children?: React.ReactNode}>}; | ||||||||
| return ({pressableTestID, brickRoadIndicator}: {pressableTestID: string; brickRoadIndicator?: ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS>}) => | ||||||||
| ReactMock.createElement(Text, {testID: pressableTestID}, `${brickRoadIndicator ?? 'none'}-brickRoadIndicator`); | ||||||||
| }); | ||||||||
|
|
||||||||
| describe('ProfilePage contact method indicator', () => { | ||||||||
| beforeAll(() => { | ||||||||
| Onyx.init({ | ||||||||
| keys: ONYXKEYS, | ||||||||
| }); | ||||||||
| }); | ||||||||
|
|
||||||||
| beforeEach(() => { | ||||||||
| return Onyx.clear(); | ||||||||
| }); | ||||||||
|
|
||||||||
| function renderPage() { | ||||||||
| return render( | ||||||||
| <NavigationContainer> | ||||||||
| <ComposeProviders components={[DelegateNoAccessModalProvider]}> | ||||||||
| <ProfilePage | ||||||||
| // @ts-expect-error - route typing is not necessary for this test | ||||||||
| route={{}} | ||||||||
| navigation={{}} | ||||||||
| /> | ||||||||
| </ComposeProviders> | ||||||||
| </NavigationContainer>, | ||||||||
| ); | ||||||||
| } | ||||||||
|
|
||||||||
| it('shows error when login list has errors', async () => { | ||||||||
| const email = 'user@example.com'; | ||||||||
|
|
||||||||
| // Current user provided by mocked hook uses the same email | ||||||||
| Onyx.merge(ONYXKEYS.LOGIN_LIST, { | ||||||||
| [email]: { | ||||||||
| partnerUserID: email, | ||||||||
| validatedDate: '', | ||||||||
| errorFields: {anyError: {message: 'oops'}}, | ||||||||
| }, | ||||||||
| }); | ||||||||
| await waitForBatchedUpdates(); | ||||||||
|
|
||||||||
| renderPage(); | ||||||||
|
|
||||||||
| // Description for contact method is 'contacts.contactMethod' via mocked translate | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you leave an empty line before each comment like this for better readability
Suggested change
|
||||||||
| let node = screen.getByText('error-brickRoadIndicator'); | ||||||||
| expect(node).toBeDefined(); | ||||||||
|
|
||||||||
| // Verify that RBR disappears | ||||||||
| Onyx.merge(ONYXKEYS.LOGIN_LIST, { | ||||||||
| [email]: { | ||||||||
| partnerUserID: email, | ||||||||
| validatedDate: '2024-02-02', | ||||||||
| errorFields: null, | ||||||||
| }, | ||||||||
| }); | ||||||||
|
|
||||||||
| await waitFor(() => { | ||||||||
| node = screen.getByTestId('contact-method-menu-item'); | ||||||||
|
|
||||||||
| // ContactMethodsPage sets brickRoadIndicator to 'info' for non-default unvalidated logins | ||||||||
| expect(node).toHaveTextContent('none-brickRoadIndicator'); | ||||||||
| }); | ||||||||
| }); | ||||||||
|
|
||||||||
| it('shows info when there is an unvalidated secondary login', async () => { | ||||||||
| const defaultEmail = 'user@example.com'; | ||||||||
| const otherEmail = 'other@example.com'; | ||||||||
| Onyx.merge(ONYXKEYS.LOGIN_LIST, { | ||||||||
| [defaultEmail]: { | ||||||||
| partnerUserID: defaultEmail, | ||||||||
| validatedDate: '2024-01-01', | ||||||||
| }, | ||||||||
| [otherEmail]: { | ||||||||
| partnerUserID: otherEmail, | ||||||||
| validatedDate: '', | ||||||||
| }, | ||||||||
| }); | ||||||||
| await waitForBatchedUpdates(); | ||||||||
|
|
||||||||
| renderPage(); | ||||||||
|
|
||||||||
| let node = screen.getByText('info-brickRoadIndicator'); | ||||||||
| expect(node).toBeDefined(); | ||||||||
|
|
||||||||
| // Verify that GBR disappears | ||||||||
| Onyx.merge(ONYXKEYS.LOGIN_LIST, { | ||||||||
| [otherEmail]: { | ||||||||
| partnerUserID: otherEmail, | ||||||||
| validatedDate: '2024-02-02', | ||||||||
| }, | ||||||||
| }); | ||||||||
|
|
||||||||
| await waitFor(() => { | ||||||||
| node = screen.getByTestId('contact-method-menu-item'); | ||||||||
|
|
||||||||
| // ContactMethodsPage sets brickRoadIndicator to 'info' for non-default unvalidated logins | ||||||||
| expect(node).toHaveTextContent('none-brickRoadIndicator'); | ||||||||
| }); | ||||||||
| }); | ||||||||
| }); | ||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.