Repository navigation
[NoQA] feat: add perf tests for composer #30633
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 2 commits into
Expensify:main
from
OlimpiaZurek:feat/27641/reassure-composer
Nov 2, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,162 @@ | ||
| import {fireEvent, screen} from '@testing-library/react-native'; | ||
| import React from 'react'; | ||
| import Onyx from 'react-native-onyx'; | ||
| import {measurePerformance} from 'reassure'; | ||
| import ComposeProviders from '../../src/components/ComposeProviders'; | ||
| import {LocaleContextProvider} from '../../src/components/LocaleContextProvider'; | ||
| import OnyxProvider from '../../src/components/OnyxProvider'; | ||
| import {KeyboardStateProvider} from '../../src/components/withKeyboardState'; | ||
| import {WindowDimensionsProvider} from '../../src/components/withWindowDimensions'; | ||
| import * as Localize from '../../src/libs/Localize'; | ||
| import ONYXKEYS from '../../src/ONYXKEYS'; | ||
| import ReportActionCompose from '../../src/pages/home/report/ReportActionCompose/ReportActionCompose'; | ||
| import * as LHNTestUtils from '../utils/LHNTestUtils'; | ||
| import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
|
|
||
| // mock PortalStateContext | ||
| jest.mock('@gorhom/portal'); | ||
|
|
||
| jest.mock('react-native-reanimated', () => ({ | ||
| ...jest.requireActual('react-native-reanimated/mock'), | ||
| useAnimatedRef: jest.fn, | ||
| })); | ||
|
|
||
| jest.mock('../../src/libs/Permissions', () => ({ | ||
| canUseTasks: jest.fn(() => true), | ||
| })); | ||
|
|
||
| jest.mock('@react-navigation/native', () => { | ||
| const actualNav = jest.requireActual('@react-navigation/native'); | ||
| return { | ||
| ...actualNav, | ||
| useNavigation: () => ({ | ||
| navigate: jest.fn(), | ||
| addListener: () => jest.fn(), | ||
| }), | ||
| useIsFocused: () => ({ | ||
| navigate: jest.fn(), | ||
| }), | ||
| }; | ||
| }); | ||
|
|
||
| jest.mock('../../src/libs/actions/EmojiPickerAction', () => { | ||
| const actualEmojiPickerAction = jest.requireActual('../../src/libs/actions/EmojiPickerAction'); | ||
| return { | ||
| ...actualEmojiPickerAction, | ||
| emojiPickerRef: { | ||
| current: { | ||
| isEmojiPickerVisible: false, | ||
| }, | ||
| }, | ||
| showEmojiPicker: jest.fn(), | ||
| hideEmojiPicker: jest.fn(), | ||
| isActive: () => true, | ||
| }; | ||
| }); | ||
|
|
||
| beforeAll(() => | ||
| Onyx.init({ | ||
| keys: ONYXKEYS, | ||
| safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], | ||
| registerStorageEventListener: () => {}, | ||
| }), | ||
| ); | ||
|
|
||
| // Initialize the network key for OfflineWithFeedback | ||
| beforeEach(() => { | ||
| Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false}); | ||
| }); | ||
|
|
||
| function ReportActionComposeWrapper() { | ||
| return ( | ||
| <ComposeProviders components={[OnyxProvider, LocaleContextProvider, KeyboardStateProvider, WindowDimensionsProvider]}> | ||
| <ReportActionCompose | ||
| onSubmit={() => jest.fn()} | ||
| reportID="1" | ||
| disabled={false} | ||
| report={LHNTestUtils.getFakeReport()} | ||
| /> | ||
| </ComposeProviders> | ||
| ); | ||
| } | ||
| const mockEvent = {preventDefault: jest.fn()}; | ||
|
|
||
| test('should render Composer with text input interactions', async () => { | ||
| const scenario = async () => { | ||
| // Query for the composer | ||
| const composer = await screen.findByTestId('composer'); | ||
|
|
||
| expect(composer).toBeDefined(); | ||
| fireEvent.changeText(composer, '@test'); | ||
|
|
||
| // Query for the suggestions | ||
| await screen.findByTestId('suggestions'); | ||
|
|
||
| // scroll to hide suggestions | ||
| fireEvent.scroll(composer); | ||
|
|
||
| // press to block suggestions | ||
| fireEvent.press(composer); | ||
| }; | ||
|
|
||
| return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario})); | ||
| }); | ||
|
|
||
| test('should press add attachemnt button', async () => { | ||
| const scenario = async () => { | ||
| // Query for the attachment button | ||
| const hintAttachmentButtonText = Localize.translateLocal('reportActionCompose.addAction'); | ||
| const attachmentButton = await screen.findByLabelText(hintAttachmentButtonText); | ||
|
|
||
| expect(attachmentButton).toBeDefined(); | ||
| fireEvent.press(attachmentButton, mockEvent); | ||
| }; | ||
|
|
||
| return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario})); | ||
| }); | ||
|
|
||
| test('should press add emoji button', async () => { | ||
| const scenario = async () => { | ||
| // Query for the emoji button | ||
| const hintEmojiButtonText = Localize.translateLocal('reportActionCompose.emoji'); | ||
| const emojiButton = await screen.findByLabelText(hintEmojiButtonText); | ||
|
|
||
| expect(emojiButton).toBeDefined(); | ||
| fireEvent.press(emojiButton); | ||
| }; | ||
|
|
||
| return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario})); | ||
| }); | ||
|
|
||
| test('should press send message button', async () => { | ||
| const scenario = async () => { | ||
| // Query for the send button | ||
| const hintSendButtonText = Localize.translateLocal('common.send'); | ||
| const sendButton = await screen.findByLabelText(hintSendButtonText); | ||
|
|
||
| expect(sendButton).toBeDefined(); | ||
| fireEvent.press(sendButton); | ||
| }; | ||
|
|
||
| return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario})); | ||
| }); | ||
|
|
||
| test('render composer with attachement modal interactions', async () => { | ||
| const scenario = async () => { | ||
| const hintAddAttachmentButtonText = Localize.translateLocal('reportActionCompose.addAttachment'); | ||
| const hintAssignTaskButtonText = Localize.translateLocal('newTaskPage.assignTask'); | ||
| const hintSplitBillButtonText = Localize.translateLocal('iou.splitBill'); | ||
|
|
||
| // Query for the attachment modal items | ||
| const addAttachmentButton = await screen.findByLabelText(hintAddAttachmentButtonText); | ||
| fireEvent.press(addAttachmentButton, mockEvent); | ||
|
|
||
| const splitBillButton = await screen.findByLabelText(hintSplitBillButtonText); | ||
| fireEvent.press(splitBillButton, mockEvent); | ||
|
|
||
| const assignTaskButton = await screen.findByLabelText(hintAssignTaskButtonText); | ||
| fireEvent.press(assignTaskButton, mockEvent); | ||
| }; | ||
|
|
||
| return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario})); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.