-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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: mock animation completion callback to trigger setState #17956
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,14 @@ jest.setTimeout(30000); | |
|
||
jest.mock('../../src/libs/Notification/LocalNotification'); | ||
|
||
// we need to mock it for the ReportScreen to update its state immediately for tests to pass | ||
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. Please be sure to capitalize the first word in every comment. Also, this comment is only a partial explanation of why the mocking is necessary. Can you please improve it so that it also says why the state isn't updating immediately in the first place and why the tests fail when it doesn't update immediately? 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. I just saw that we have a special file for adding the mocks to 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. Ah, thanks for moving it to the |
||
jest.mock('react-native/libraries/Interaction/InteractionManager', () => { | ||
const IM = jest.requireActual('react-native/libraries/Interaction/InteractionManager'); | ||
IM.runAfterInteractions = jest.fn(fn => fn()); | ||
|
||
return IM; | ||
}); | ||
|
||
beforeAll(() => { | ||
// In this test, we are generically mocking the responses of all API requests by mocking fetch() and having it | ||
// return 200. In other tests, we might mock HttpUtils.xhr() with a more specific mock data response (which means | ||
|
@@ -39,7 +47,7 @@ beforeAll(() => { | |
// simulate data arriving we will just set it into Onyx directly with Onyx.merge() or Onyx.set() etc. | ||
global.fetch = TestHelper.getGlobalFetchMock(); | ||
|
||
Linking.setInitialURL('https://new.expensify.com/r'); | ||
Linking.setInitialURL('https://new.expensify.com/'); | ||
appSetup(); | ||
|
||
// Connect to Pusher | ||
|
@@ -105,10 +113,10 @@ function navigateToSidebarOption(index) { | |
/** | ||
* @return {Boolean} | ||
*/ | ||
function isDrawerOpen() { | ||
function areYouOnChatListScreen() { | ||
const hintText = Localize.translateLocal('sidebarScreen.listOfChats'); | ||
const sidebarLinks = screen.queryAllByLabelText(hintText); | ||
return !lodashGet(sidebarLinks, [0, 'props', 'accessibilityElementsHidden']); | ||
return lodashGet(sidebarLinks, [0, 'props', 'isFocused']); | ||
} | ||
|
||
const REPORT_ID = '1'; | ||
|
@@ -196,7 +204,7 @@ function signInAndGetAppWithUnreadChat() { | |
}); | ||
} | ||
|
||
xdescribe('Unread Indicators', () => { | ||
describe('Unread Indicators', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
Onyx.clear(); | ||
|
@@ -211,7 +219,7 @@ xdescribe('Unread Indicators', () => { | |
const sidebarLinksHintText = Localize.translateLocal('sidebarScreen.listOfChats'); | ||
const sidebarLinks = screen.queryAllByLabelText(sidebarLinksHintText); | ||
expect(sidebarLinks).toHaveLength(1); | ||
expect(isDrawerOpen()).toBe(true); | ||
expect(areYouOnChatListScreen()).toBe(true); | ||
|
||
// Verify there is only one option in the sidebar | ||
const optionRowsHintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); | ||
|
@@ -227,7 +235,7 @@ xdescribe('Unread Indicators', () => { | |
}) | ||
.then(() => { | ||
// Verify that the report screen is rendered and the drawer is closed | ||
expect(isDrawerOpen()).toBe(false); | ||
expect(areYouOnChatListScreen()).toBe(false); | ||
|
||
// That the report actions are visible along with the created action | ||
const welcomeMessageHintText = Localize.translateLocal('accessibilityHints.chatWelcomeMessage'); | ||
|
@@ -255,14 +263,14 @@ xdescribe('Unread Indicators', () => { | |
// Navigate to the unread chat from the sidebar | ||
.then(() => navigateToSidebarOption(0)) | ||
.then(() => { | ||
expect(isDrawerOpen()).toBe(false); | ||
expect(areYouOnChatListScreen()).toBe(false); | ||
|
||
// Then navigate back to the sidebar | ||
return navigateToSidebar(); | ||
}) | ||
.then(() => { | ||
// Verify the LHN is now open | ||
expect(isDrawerOpen()).toBe(true); | ||
expect(areYouOnChatListScreen()).toBe(true); | ||
|
||
// Verify that the option row in the LHN is no longer bold (since OpenReport marked it as read) | ||
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); | ||
|
@@ -277,7 +285,7 @@ xdescribe('Unread Indicators', () => { | |
const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator'); | ||
const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); | ||
expect(unreadIndicator).toHaveLength(0); | ||
expect(isDrawerOpen()).toBe(false); | ||
expect(areYouOnChatListScreen()).toBe(false); | ||
|
||
// Scroll and verify that the new messages badge is also hidden | ||
scrollUpToRevealNewMessagesBadge(); | ||
|
@@ -343,9 +351,6 @@ xdescribe('Unread Indicators', () => { | |
.then(() => { | ||
// Verify notification was created | ||
expect(LocalNotification.showCommentNotification).toBeCalled(); | ||
|
||
// // Navigate back to the sidebar | ||
return navigateToSidebar(); | ||
}) | ||
.then(() => { | ||
// // Verify the new report option appears in the LHN | ||
|
@@ -440,7 +445,7 @@ xdescribe('Unread Indicators', () => { | |
it('Removes the new line indicator when a new message is created by the current user', () => signInAndGetAppWithUnreadChat() | ||
.then(() => { | ||
// Verify we are on the LHN and that the chat shows as unread in the LHN | ||
expect(isDrawerOpen()).toBe(true); | ||
expect(areYouOnChatListScreen()).toBe(true); | ||
|
||
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); | ||
const displayNameTexts = screen.queryAllByLabelText(hintText); | ||
|
@@ -469,7 +474,7 @@ xdescribe('Unread Indicators', () => { | |
it('Keeps the new line indicator when the user moves the App to the background', () => signInAndGetAppWithUnreadChat() | ||
.then(() => { | ||
// Verify we are on the LHN and that the chat shows as unread in the LHN | ||
expect(isDrawerOpen()).toBe(true); | ||
expect(areYouOnChatListScreen()).toBe(true); | ||
|
||
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); | ||
const displayNameTexts = screen.queryAllByLabelText(hintText); | ||
|
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.
Is all this necessary for mocking jest? I can't imagine it is, so it's just strange to see these changes in this PR
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.
accessibilityElementsHidden
was used before both for checking the value in tests and probably to mock the navigation behavior of accessibility (see: https://github.com/react-navigation/react-navigation/blob/9fe34b445fcb86e5666f61e144007d7540f014fa/packages/stack/src/views/Stack/CardContainer.tsx#L242). If we still want to check if this route is focused or not, we need to keep a way of doing it. If you know a better way to do it, it would be great 😅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.
OK, that explains why
accessibilityElementsHidden
is there in the first place, but I guess I am still not quite understanding why it needs to change fromaccessibilityElementsHidden
toisFocused
. We can't keep the original way, or it's not desired for some reason?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.
Hmm
accessibilityElementsHidden
should not be needed anymore, but we can keep it. I just wanted a prop that does not do anything so I didn't destroy any of the behaviors, but since the screen is not focused when this prop is set, it should all work just fine.