Skip to content
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

[NoQA] Upgrade RNTL to the newest version #53067

Merged
merged 5 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions jest/setupAfterEnv.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// This is required in order for jest to recognize custom matchers like toBeDisabled. This can be removed once testing-library/react-native version is bumped to v12.4 or later
import '@testing-library/jest-native/extend-expect';
import '@testing-library/react-native/extend-expect';

jest.useRealTimers();
92 changes: 7 additions & 85 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@
"@storybook/react-webpack5": "^8.4.0",
"@storybook/theming": "^8.1.10",
"@svgr/webpack": "^6.0.0",
"@testing-library/jest-native": "5.4.1",
"@testing-library/react-native": "11.5.1",
"@testing-library/react-native": "12.8.1",
"@trivago/prettier-plugin-sort-imports": "^4.2.0",
"@types/base-64": "^1.0.2",
"@types/canvas-size": "^1.2.2",
Expand Down
4 changes: 4 additions & 0 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ function Button(
if (shouldEnableHapticFeedback) {
HapticFeedback.press();
}

if (isDisabled || isLoading) {
return; // Prevent the onPress from being triggered when the button is disabled or in a loading state
}
return onPress(event);
}}
onLongPress={(event) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/DatePicker/CalendarPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function CalendarPicker({
const isDisabled = !day || isBeforeMinDate || isAfterMaxDate;
const isSelected = !!day && isSameDay(parseISO(value.toString()), new Date(currentYearView, currentMonthView, day));
const handleOnPress = () => {
if (!day) {
if (!day || isDisabled) {
return;
}

Expand Down
30 changes: 20 additions & 10 deletions tests/perf-test/ReportActionsList.perf-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import {ReportAttachmentsProvider} from '@src/pages/home/report/ReportAttachment
import {ActionListContext, ReactionListContext} from '@src/pages/home/ReportScreenContext';
import type {PersonalDetailsList} from '@src/types/onyx';
import createRandomReportAction from '../utils/collections/reportActions';
import * as LHNTestUtilsModule from '../utils/LHNTestUtils';
import createRandomReport from '../utils/collections/reports';
import * as ReportTestUtils from '../utils/ReportTestUtils';
import * as TestHelper from '../utils/TestHelper';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates';

Expand Down Expand Up @@ -71,11 +72,25 @@ const mockOnScroll = jest.fn();
const mockLoadChats = jest.fn();
const mockRef = {current: null, flatListRef: null, scrollPosition: null, setScrollPosition: () => {}};

const TEST_USER_ACCOUNT_ID = 1;
const TEST_USER_LOGIN = '[email protected]';

const signUpWithTestUser = () => {
TestHelper.signInWithTestUser(TEST_USER_ACCOUNT_ID, TEST_USER_LOGIN);
};

const report = createRandomReport(1);
const parentReportAction = createRandomReportAction(1);

beforeEach(() => {
// Initialize the network key for OfflineWithFeedback
Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false});
wrapOnyxWithWaitForBatchedUpdates(Onyx);
Onyx.clear().then(waitForBatchedUpdates);
signUpWithTestUser();
});

afterEach(() => {
Onyx.clear();
});

function ReportActionsListWrapper() {
Expand All @@ -85,18 +100,18 @@ function ReportActionsListWrapper() {
<ReactionListContext.Provider value={mockRef}>
<ActionListContext.Provider value={mockRef}>
<ReportActionsList
parentReportAction={createRandomReportAction(1)}
parentReportAction={parentReportAction}
parentReportActionForTransactionThread={undefined}
sortedReportActions={reportActions}
sortedVisibleReportActions={reportActions}
report={LHNTestUtilsModule.getFakeReport()}
report={report}
onLayout={mockOnLayout}
onScroll={mockOnScroll}
onContentSizeChange={() => {}}
listID={1}
loadOlderChats={mockLoadChats}
loadNewerChats={mockLoadChats}
transactionThreadReport={LHNTestUtilsModule.getFakeReport()}
transactionThreadReport={report}
reportActions={reportActions}
/>
</ActionListContext.Provider>
Expand All @@ -110,10 +125,5 @@ test('[ReportActionsList] should render ReportActionsList with 500 reportActions
await screen.findByTestId('report-actions-list');
};
await waitForBatchedUpdates();

Onyx.multiSet({
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtilsModule.fakePersonalDetails,
});

await measureRenders(<ReportActionsListWrapper />, {scenario});
});
10 changes: 5 additions & 5 deletions tests/ui/UnreadIndicatorsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function navigateToSidebar(): Promise<void> {

function areYouOnChatListScreen(): boolean {
const hintText = Localize.translateLocal('sidebarScreen.listOfChats');
const sidebarLinks = screen.queryAllByLabelText(hintText);
const sidebarLinks = screen.queryAllByLabelText(hintText, {includeHiddenElements: true});

return !sidebarLinks?.at(0)?.props?.accessibilityElementsHidden;
}
Expand Down Expand Up @@ -369,12 +369,12 @@ describe('Unread Indicators', () => {
await act(() => (NativeNavigation as NativeNavigationMock).triggerTransitionEnd());
// Verify that report we navigated to appears in a "read" state while the original unread report still shows as unread
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNameTexts = screen.queryAllByLabelText(hintText);
const displayNameTexts = screen.queryAllByLabelText(hintText, {includeHiddenElements: true});
expect(displayNameTexts).toHaveLength(2);
expect((displayNameTexts.at(0)?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.normal);
expect(screen.getAllByText('C User').at(0)).toBeOnTheScreen();
expect((displayNameTexts.at(1)?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold);
expect(screen.getByText('B User')).toBeOnTheScreen();
expect(screen.getByText('B User', {includeHiddenElements: true})).toBeOnTheScreen();
}));

xit('Manually marking a chat message as unread shows the new line indicator and updates the LHN', () =>
Expand Down Expand Up @@ -528,7 +528,7 @@ describe('Unread Indicators', () => {
.then(() => {
// Verify the chat preview text matches the last comment from the current user
const hintText = Localize.translateLocal('accessibilityHints.lastChatMessagePreview');
const alternateText = screen.queryAllByLabelText(hintText);
const alternateText = screen.queryAllByLabelText(hintText, {includeHiddenElements: true});
expect(alternateText).toHaveLength(1);

// This message is visible on the sidebar and the report screen, so there are two occurrences.
Expand All @@ -541,7 +541,7 @@ describe('Unread Indicators', () => {
})
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.lastChatMessagePreview');
const alternateText = screen.queryAllByLabelText(hintText);
const alternateText = screen.queryAllByLabelText(hintText, {includeHiddenElements: true});
expect(alternateText).toHaveLength(1);
expect(screen.getAllByText('Comment 9').at(0)).toBeOnTheScreen();
})
Expand Down
16 changes: 10 additions & 6 deletions tests/ui/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
import colors from '@styles/theme/colors';
import Button from '@src/components/Button';
import type {ButtonProps} from '@src/components/Button';
import CONST from '@src/CONST';

const buttonText = 'Click me';
const accessibilityLabel = 'button-label';
Expand All @@ -17,7 +18,7 @@ describe('Button Component', () => {
/>,
);
const onPress = jest.fn();
const getButton = () => screen.getByText(buttonText);
const getButton = () => screen.getByRole(CONST.ROLE.BUTTON, {name: buttonText});

afterEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -55,15 +56,18 @@ describe('Button Component', () => {
renderButton({isLoading: true});

// Then the loading state is displayed
expect(getButton()).toBeDisabled();
expect(screen.getByText(buttonText)).not.toBeVisible();
});

it('disables button when isDisabled is true', () => {
// Given the component is rendered with isDisabled true
renderButton({isDisabled: true});
// Given the component is rendered with isDisabled set to true
renderButton({isDisabled: true, onPress});

// Then the button is disabled
expect(getButton()).toBeDisabled();
// When the button is pressed
fireEvent.press(getButton());

// Then the onPress function should not be called
expect(onPress).not.toHaveBeenCalled();
});

it('sets accessibility label correctly', () => {
Expand Down
8 changes: 2 additions & 6 deletions tests/unit/BaseSelectionListTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@ describe('BaseSelectionList', () => {
isSelected: section.keyForList === '2',
}));
const {rerender} = render(<BaseListItemRenderer sections={mockSections} />);
expect(screen.getByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}1`)).toHaveAccessibilityState({
selected: true,
});
expect(screen.getByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}1`)).toBeSelected();
rerender(<BaseListItemRenderer sections={updatedMockSections} />);
expect(screen.getByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}2`)).toHaveAccessibilityState({
selected: true,
});
expect(screen.getByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}2`)).toBeSelected();
});
});
Loading
Loading