Repository navigation
[NoQA] Optimise PaginationTest #74234
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -49,6 +49,8 @@ const USER_A_ACCOUNT_ID = 1; | |
| const USER_A_EMAIL = 'user_a@test.com'; | ||
| const USER_B_ACCOUNT_ID = 2; | ||
| const USER_B_EMAIL = 'user_b@test.com'; | ||
| const TEST_AUTH_TOKEN = 'test-auth-token'; | ||
| const TEST_AUTO_GENERATED_LOGIN = 'expensify.cash-abc123'; | ||
|
|
||
| function getReportScreen(reportID = REPORT_ID) { | ||
| return screen.getByTestId(`report-screen-${reportID}`); | ||
|
|
@@ -189,74 +191,92 @@ function mockGetNewerActions(messageCount: number) { | |
| })); | ||
| } | ||
|
|
||
| async function fastSignInWithTestUser() { | ||
| await Onyx.multiSet({ | ||
| [ONYXKEYS.CREDENTIALS]: { | ||
| login: USER_A_EMAIL, | ||
| autoGeneratedLogin: TEST_AUTO_GENERATED_LOGIN, | ||
| autoGeneratedPassword: 'Password1', | ||
| }, | ||
| [ONYXKEYS.ACCOUNT]: { | ||
| validated: true, | ||
| isUsingExpensifyCard: false, | ||
| }, | ||
| [ONYXKEYS.SESSION]: { | ||
| authToken: TEST_AUTH_TOKEN, | ||
| accountID: USER_A_ACCOUNT_ID, | ||
| email: USER_A_EMAIL, | ||
| encryptedAuthToken: TEST_AUTH_TOKEN, | ||
| }, | ||
| [ONYXKEYS.BETAS]: ['all'], | ||
| [ONYXKEYS.NVP_PRIVATE_PUSH_NOTIFICATION_ID]: 'randomID', | ||
| [ONYXKEYS.PERSONAL_DETAILS_LIST]: { | ||
| [USER_A_ACCOUNT_ID]: TestHelper.buildPersonalDetails(USER_A_EMAIL, USER_A_ACCOUNT_ID, 'A'), | ||
| }, | ||
| }); | ||
| await waitForBatchedUpdates(); | ||
| } | ||
|
|
||
| /** | ||
| * Sets up a test with a logged in user. Returns the <App/> test instance. | ||
| */ | ||
| async function signInAndGetApp(): Promise<void> { | ||
| // Render the App and sign in as a test user. | ||
| render(<App />); | ||
| await waitForBatchedUpdatesWithAct(); | ||
| const hintText = TestHelper.translateLocal('loginForm.loginForm'); | ||
| const loginForm = await screen.findAllByLabelText(hintText); | ||
| expect(loginForm).toHaveLength(1); | ||
|
|
||
| await act(async () => { | ||
| await TestHelper.signInWithTestUser(USER_A_ACCOUNT_ID, USER_A_EMAIL, undefined, undefined, 'A'); | ||
| }); | ||
| await fastSignInWithTestUser(); | ||
|
|
||
| render(<App />); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| // Start listening for pusher events after navigation settles. | ||
| subscribeToUserEvents(); | ||
|
|
||
| await waitForBatchedUpdates(); | ||
|
|
||
| await act(async () => { | ||
| // Simulate setting an unread report and personal details | ||
| await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, { | ||
| reportID: REPORT_ID, | ||
| reportName: CONST.REPORT.DEFAULT_REPORT_NAME, | ||
| lastMessageText: 'Test', | ||
| participants: { | ||
| [USER_B_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, | ||
| [USER_A_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, | ||
| }, | ||
| lastActorAccountID: USER_B_ACCOUNT_ID, | ||
| type: CONST.REPORT.TYPE.CHAT, | ||
| }); | ||
|
|
||
| await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, { | ||
| [USER_B_ACCOUNT_ID]: TestHelper.buildPersonalDetails(USER_B_EMAIL, USER_B_ACCOUNT_ID, 'B'), | ||
| }); | ||
|
|
||
| // Setup a 2nd report to test comment linking. | ||
| await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${COMMENT_LINKING_REPORT_ID}`, { | ||
| reportID: COMMENT_LINKING_REPORT_ID, | ||
| reportName: CONST.REPORT.DEFAULT_REPORT_NAME, | ||
| lastMessageText: 'Test', | ||
| participants: {[USER_A_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}}, | ||
| lastActorAccountID: USER_A_ACCOUNT_ID, | ||
| type: CONST.REPORT.TYPE.CHAT, | ||
| }); | ||
|
|
||
| await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${COMMENT_LINKING_REPORT_ID}`, { | ||
| '100': buildCreatedAction('100', format(TEN_MINUTES_AGO, CONST.DATE.FNS_DB_FORMAT_STRING)), | ||
| '101': { | ||
| actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, | ||
| person: [{type: 'TEXT', style: 'strong', text: 'User B'}], | ||
| created: format(addSeconds(TEN_MINUTES_AGO, 10), CONST.DATE.FNS_DB_FORMAT_STRING), | ||
| message: [ | ||
| { | ||
| type: 'COMMENT', | ||
| html: '<a href="https://dev.new.expensify.com:8082/r/1/5">Link 1</a>', | ||
| text: 'Link 1', | ||
| }, | ||
| ], | ||
| reportActionID: '101', | ||
| actorAccountID: USER_A_ACCOUNT_ID, | ||
| }, | ||
| }); | ||
|
|
||
| // We manually setting the sidebar as loaded since the onLayout event does not fire in tests | ||
| await Promise.all([ | ||
| // Simulate setting an unread report and personal details | ||
| Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, { | ||
| reportID: REPORT_ID, | ||
| reportName: CONST.REPORT.DEFAULT_REPORT_NAME, | ||
| lastMessageText: 'Test', | ||
| participants: { | ||
| [USER_B_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, | ||
| [USER_A_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, | ||
| }, | ||
| lastActorAccountID: USER_B_ACCOUNT_ID, | ||
| type: CONST.REPORT.TYPE.CHAT, | ||
| }), | ||
| Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, { | ||
| [USER_B_ACCOUNT_ID]: TestHelper.buildPersonalDetails(USER_B_EMAIL, USER_B_ACCOUNT_ID, 'B'), | ||
| }), | ||
|
|
||
| // Setup a 2nd report to test comment linking. | ||
| Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${COMMENT_LINKING_REPORT_ID}`, { | ||
| reportID: COMMENT_LINKING_REPORT_ID, | ||
| reportName: CONST.REPORT.DEFAULT_REPORT_NAME, | ||
| lastMessageText: 'Test', | ||
| participants: {[USER_A_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}}, | ||
| lastActorAccountID: USER_A_ACCOUNT_ID, | ||
| type: CONST.REPORT.TYPE.CHAT, | ||
| }), | ||
| Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${COMMENT_LINKING_REPORT_ID}`, { | ||
| '100': buildCreatedAction('100', format(TEN_MINUTES_AGO, CONST.DATE.FNS_DB_FORMAT_STRING)), | ||
| '101': { | ||
| actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, | ||
| person: [{type: 'TEXT', style: 'strong', text: 'User B'}], | ||
| created: format(addSeconds(TEN_MINUTES_AGO, 10), CONST.DATE.FNS_DB_FORMAT_STRING), | ||
| message: [ | ||
| { | ||
| type: 'COMMENT', | ||
| html: '<a href="https://dev.new.expensify.com:8082/r/1/5">Link 1</a>', | ||
| text: 'Link 1', | ||
| }, | ||
| ], | ||
| reportActionID: '101', | ||
| actorAccountID: USER_A_ACCOUNT_ID, | ||
| }, | ||
| }), | ||
| ]); | ||
|
|
||
| // Manually mark the sidebar as loaded since onLayout does not fire in tests. | ||
| setSidebarLoaded(); | ||
| }); | ||
|
|
||
|
|
@@ -324,10 +344,13 @@ describe('Pagination', () => { | |
| TestHelper.expectAPICommandToHaveBeenCalled('GetNewerActions', 0); | ||
|
|
||
| await waitForNetworkPromises(); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| // We now have 18 messages. 15 (MIN_INITIAL_REPORT_ACTION_COUNT) from the initial OpenReport and 3 from GetOlderActions. | ||
| // GetOlderActions only returns 3 actions since it reaches id '1', which is the created action. | ||
| expect(getReportActions()).toHaveLength(18); | ||
| await waitFor(() => { | ||
|
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. @ShridharGoel Should we add the
Contributor
Author
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. We needed it because If we use it for other assertions also, it would add unnecessary polling since those actions don't involve
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. Good point i agree. |
||
| expect(getReportActions()).toHaveLength(18); | ||
| }); | ||
| }); | ||
|
|
||
| it('opens a chat and load newer messages', async () => { | ||
|
|
||
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.
Should this be wrapped with
act?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.
In this we’re just preloading Onyx data before
<App />renders, so there’s no mounted UI to update yet. Soactshouldn't be needed.