-
Notifications
You must be signed in to change notification settings - Fork 3k
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: mWeb - Selector - User lands on the same WS when double tapping on different one on selector. #52438
Merged
Merged
fix: mWeb - Selector - User lands on the same WS when double tapping on different one on selector. #52438
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b9fc338
fix: mWeb - Selector - User lands on the same WS when double tapping …
Krishna2323 d3aeb62
Merge branch 'Expensify:main' into krishna2323/issue/51402
Krishna2323 7934656
add WorkspaceSwitcherPage UI tests.
Krishna2323 5a860cb
update test cases.
Krishna2323 497a698
Merge branch 'Expensify:main' into krishna2323/issue/51402
Krishna2323 435a77e
update tests for WorkspaceSwitcher page.
Krishna2323 e101c3e
update tests.
Krishna2323 d4ab3f9
minor updates.
Krishna2323 b1af7d3
remove tests/ui/WorkspaceSwitcherPageTest.tsx.
Krishna2323 a33e89d
update test.
Krishna2323 846b921
Merge branch 'main' into krishna2323/issue/51402
Krishna2323 b1b2ef7
update tests.
Krishna2323 de1b10a
add navigation mock.
Krishna2323 043cf5b
update tests.
Krishna2323 2a34693
remove redundant code.
Krishna2323 61753cf
update tests.
Krishna2323 b1227c4
remove commented code.
Krishna2323 a192d8e
remove redundant code.
Krishna2323 793b688
minor update.
Krishna2323 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 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 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 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,104 @@ | ||
import * as NativeNavigation from '@react-navigation/native'; | ||
import {act, fireEvent, render, screen} from '@testing-library/react-native'; | ||
import React from 'react'; | ||
import Onyx from 'react-native-onyx'; | ||
import * as Localize from '@libs/Localize'; | ||
import type Navigation from '@libs/Navigation/Navigation'; | ||
import * as AppActions from '@userActions/App'; | ||
import * as User from '@userActions/User'; | ||
import App from '@src/App'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {NativeNavigationMock} from '../../__mocks__/@react-navigation/native'; | ||
import * as LHNTestUtils from '../utils/LHNTestUtils'; | ||
import PusherHelper from '../utils/PusherHelper'; | ||
import * as TestHelper from '../utils/TestHelper'; | ||
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct'; | ||
|
||
// We need a large timeout here as we are lazy loading React Navigation screens and this test is running against the entire mounted App | ||
jest.setTimeout(60000); | ||
|
||
jest.mock('@react-navigation/native', () => { | ||
const actualNav = jest.requireActual<typeof Navigation>('@react-navigation/native'); | ||
return { | ||
...actualNav, | ||
useIsFocused: jest.fn(), | ||
triggerTransitionEnd: jest.fn(), | ||
}; | ||
}); | ||
TestHelper.setupApp(); | ||
|
||
async function signInAndGetApp(): Promise<void> { | ||
// Render the App and sign in as a test user. | ||
render(<App />); | ||
await waitForBatchedUpdatesWithAct(); | ||
|
||
const hintText = Localize.translateLocal('loginForm.loginForm'); | ||
const loginForm = await screen.findAllByLabelText(hintText); | ||
expect(loginForm).toHaveLength(1); | ||
|
||
await act(async () => { | ||
await TestHelper.signInWithTestUser(); | ||
}); | ||
await waitForBatchedUpdatesWithAct(); | ||
|
||
User.subscribeToUserEvents(); | ||
await waitForBatchedUpdates(); | ||
|
||
AppActions.setSidebarLoaded(); | ||
|
||
await waitForBatchedUpdatesWithAct(); | ||
} | ||
|
||
async function navigateToWorkspaceSwitcher(): Promise<void> { | ||
const workspaceSwitcherButton = await screen.findByTestId('WorkspaceSwitcherButton'); | ||
fireEvent(workspaceSwitcherButton, 'press'); | ||
await act(() => { | ||
(NativeNavigation as NativeNavigationMock).triggerTransitionEnd(); | ||
}); | ||
await waitForBatchedUpdatesWithAct(); | ||
} | ||
|
||
describe('WorkspaceSwitcherPage', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
Onyx.clear(); | ||
|
||
// Unsubscribe to pusher channels | ||
PusherHelper.teardown(); | ||
}); | ||
|
||
it('navigates away when a workspace is selected and `isFocused` is true', async () => { | ||
await signInAndGetApp(); | ||
(NativeNavigation.useIsFocused as jest.Mock).mockReturnValue(true); | ||
|
||
await Onyx.mergeCollection(ONYXKEYS.COLLECTION.POLICY, { | ||
[`${ONYXKEYS.COLLECTION.POLICY}1` as const]: LHNTestUtils.getFakePolicy('1', 'Workspace A'), | ||
[`${ONYXKEYS.COLLECTION.POLICY}2` as const]: LHNTestUtils.getFakePolicy('2', 'Workspace B'), | ||
[`${ONYXKEYS.COLLECTION.POLICY}3` as const]: LHNTestUtils.getFakePolicy('3', 'Workspace C'), | ||
}); | ||
|
||
await navigateToWorkspaceSwitcher(); | ||
|
||
const workspaceRowB = screen.getByLabelText('Workspace B'); | ||
fireEvent.press(workspaceRowB); | ||
expect(screen.queryByTestId('WorkspaceSwitcherPage')).toBeNull(); | ||
}); | ||
|
||
it('does not navigate away when a workspace is selected and `isFocused` is false', async () => { | ||
await signInAndGetApp(); | ||
(NativeNavigation.useIsFocused as jest.Mock).mockReturnValue(false); | ||
|
||
await Onyx.mergeCollection(ONYXKEYS.COLLECTION.POLICY, { | ||
[`${ONYXKEYS.COLLECTION.POLICY}1` as const]: LHNTestUtils.getFakePolicy('1', 'Workspace A'), | ||
[`${ONYXKEYS.COLLECTION.POLICY}2` as const]: LHNTestUtils.getFakePolicy('2', 'Workspace B'), | ||
[`${ONYXKEYS.COLLECTION.POLICY}3` as const]: LHNTestUtils.getFakePolicy('3', 'Workspace C'), | ||
}); | ||
|
||
await navigateToWorkspaceSwitcher(); | ||
|
||
const workspaceRowB = screen.getByLabelText('Workspace B'); | ||
fireEvent.press(workspaceRowB); | ||
expect(screen.getByTestId('WorkspaceSwitcherPage')).toBeOnTheScreen(); | ||
}); | ||
}); |
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.
Can we not use the
actualNav
and just returnuseIsFocused
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.
I tried removing the
actualNav
and we can't remove it as causes issues for other missing methods in nav.