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

[No QA][TS migration] Migrate multiple unit and Performance test to Typescript #37685

Merged
merged 14 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion src/components/DragAndDrop/Provider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type DragAndDropProviderProps = {
isDisabled?: boolean;

/** Indicate that users are dragging file or not */
setIsDraggingOver: (value: boolean) => void;
setIsDraggingOver?: (value: boolean) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this should be optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, @VickyStash explained the reason here: #37820 (comment)

};

type SetOnDropHandlerCallback = (event: DragEvent) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/EmojiPickerAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ function resetEmojiPopoverAnchor() {
}

export {emojiPickerRef, showEmojiPicker, hideEmojiPicker, isActive, clearActive, isEmojiPickerVisible, resetEmojiPopoverAnchor};
export type {AnchorOrigin};
export type {AnchorOrigin, EmojiPickerRef};
6 changes: 5 additions & 1 deletion src/types/onyx/ReportAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type {ValueOf} from 'type-fest';
import type {FileObject} from '@components/AttachmentModal';
import type {AvatarSource} from '@libs/UserUtils';
import type CONST from '@src/CONST';
import type ONYXKEYS from '@src/ONYXKEYS';
import type CollectionDataSet from '@src/types/utils/CollectionDataSet';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import type * as OnyxCommon from './OnyxCommon';
import type {Decision, Reaction} from './OriginalMessage';
Expand Down Expand Up @@ -224,5 +226,7 @@ type ReportAction = ReportActionBase & OriginalMessage;

type ReportActions = Record<string, ReportAction>;

type ReportActionsCollectionDataSet = CollectionDataSet<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS>;

export default ReportAction;
export type {ReportActions, ReportActionBase, Message, LinkMetadata, OriginalMessage};
export type {ReportActions, ReportActionBase, Message, LinkMetadata, OriginalMessage, ReportActionsCollectionDataSet};
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
import {fireEvent, screen} from '@testing-library/react-native';
import type {ComponentType} from 'react';
import React from 'react';
import Onyx from 'react-native-onyx';
import type Animated from 'react-native-reanimated';
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 type {WithNavigationFocusProps} from '@components/withNavigationFocus';
import type {EmojiPickerRef} from '@libs/actions/EmojiPickerAction';
import type Navigation from '@libs/Navigation/Navigation';
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(
'react-native-reanimated',
() =>
({
...jest.requireActual('react-native-reanimated/mock'),
useAnimatedRef: jest.fn(),
} as typeof Animated),
);

jest.mock('@react-navigation/native', () => {
const actualNav = jest.requireActual('@react-navigation/native');
Expand All @@ -32,11 +41,11 @@ jest.mock('@react-navigation/native', () => {
useIsFocused: () => ({
navigate: jest.fn(),
}),
};
} as typeof Navigation;
});

jest.mock('../../src/libs/actions/EmojiPickerAction', () => {
const actualEmojiPickerAction = jest.requireActual('../../src/libs/actions/EmojiPickerAction');
jest.mock('@src/libs/actions/EmojiPickerAction', () => {
const actualEmojiPickerAction = jest.requireActual('@src/libs/actions/EmojiPickerAction');
return {
...actualEmojiPickerAction,
emojiPickerRef: {
Expand All @@ -47,15 +56,15 @@ jest.mock('../../src/libs/actions/EmojiPickerAction', () => {
showEmojiPicker: jest.fn(),
hideEmojiPicker: jest.fn(),
isActive: () => true,
};
} as EmojiPickerRef;
});

jest.mock('../../src/components/withNavigationFocus', () => (Component) => {
function WithNavigationFocus(props) {
jest.mock('@src/components/withNavigationFocus', <TProps extends WithNavigationFocusProps>() => (Component: ComponentType<TProps>) => {
function WithNavigationFocus(props: Omit<TProps, keyof WithNavigationFocusProps>) {
return (
<Component
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
{...(props as TProps)}
isFocused={false}
/>
);
Expand All @@ -70,7 +79,6 @@ beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
registerStorageEventListener: () => {},
}),
);

Expand All @@ -87,6 +95,8 @@ function ReportActionComposeWrapper() {
reportID="1"
disabled={false}
report={LHNTestUtils.getFakeReport()}
isComposerFullSize
listHeight={200}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why 200?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a random value as it is not important for the test.

/>
</ComposeProviders>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import {fireEvent, screen} from '@testing-library/react-native';
import type {ComponentType} 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 {WindowDimensionsProvider} from '../../src/components/withWindowDimensions';
import * as Localize from '../../src/libs/Localize';
import ONYXKEYS from '../../src/ONYXKEYS';
import ReportActionsList from '../../src/pages/home/report/ReportActionsList';
import {ReportAttachmentsProvider} from '../../src/pages/home/report/ReportAttachmentsContext';
import {ActionListContext, ReactionListContext} from '../../src/pages/home/ReportScreenContext';
import variables from '../../src/styles/variables';
import type {WithNavigationFocusProps} from '@components/withNavigationFocus';
import type Navigation from '@libs/Navigation/Navigation';
import ComposeProviders from '@src/components/ComposeProviders';
import {LocaleContextProvider} from '@src/components/LocaleContextProvider';
import OnyxProvider from '@src/components/OnyxProvider';
import {WindowDimensionsProvider} from '@src/components/withWindowDimensions';
import * as Localize from '@src/libs/Localize';
import ONYXKEYS from '@src/ONYXKEYS';
import ReportActionsList from '@src/pages/home/report/ReportActionsList';
import {ReportAttachmentsProvider} from '@src/pages/home/report/ReportAttachmentsContext';
import {ActionListContext, ReactionListContext} from '@src/pages/home/ReportScreenContext';
import variables from '@src/styles/variables';
import * as LHNTestUtils from '../utils/LHNTestUtils';
import PusherHelper from '../utils/PusherHelper';
import * as ReportTestUtils from '../utils/ReportTestUtils';
Expand All @@ -19,12 +22,12 @@

const mockedNavigate = jest.fn();

jest.mock('../../src/components/withNavigationFocus', () => (Component) => {
function WithNavigationFocus(props) {
jest.mock('@src/components/withNavigationFocus', <TProps extends WithNavigationFocusProps>() => (Component: ComponentType<TProps>) => {
function WithNavigationFocus(props: Omit<TProps, keyof WithNavigationFocusProps>) {
return (
<Component
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
{...(props as TProps)}
isFocused={false}
/>
);
Expand All @@ -41,16 +44,15 @@
...actualNav,
useRoute: () => mockedNavigate,
useIsFocused: () => true,
};
} as typeof Navigation;
});

jest.mock('../../src/components/ConfirmedRoute.tsx');
jest.mock('@src/components/ConfirmedRoute.tsx');

beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
registerStorageEventListener: () => {},
}),
);

Expand All @@ -61,7 +63,7 @@
const mockOnLayout = jest.fn();
const mockOnScroll = jest.fn();
const mockLoadChats = jest.fn();
const mockRef = {current: null};
const mockRef = {current: null, flatListRef: null, scrollPosition: null, setScrollPosition: () => {}};

// Initialize the network key for OfflineWithFeedback
beforeEach(() => {
Expand Down Expand Up @@ -90,7 +92,7 @@
onScroll={mockOnScroll}
loadMoreChats={mockLoadChats}
loadOlderChats={mockLoadChats}
loadNewerChats={mockLoadChats}

Check failure on line 95 in tests/perf-test/ReportActionsList.perf-test.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Type 'Mock<any, any, any>' is missing the following properties from type 'DebouncedFunc<(params: { distanceFromStart: number; }) => void>': cancel, flush
currentUserPersonalDetails={LHNTestUtils.fakePersonalDetails[currentUserAccountID]}
/>
</ActionListContext.Provider>
Expand Down
Loading
Loading