Skip to content
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
2 changes: 1 addition & 1 deletion config/eslint/eslint.seatbelt.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,7 @@
"../../tests/ui/ContactMethodsPageTest.tsx" "@typescript-eslint/no-unsafe-type-assertion" 4
"../../tests/ui/CountrySelectionListTest.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3
"../../tests/ui/CountrySelectorModalTest.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3
"../../tests/ui/DynamicCountrySelectionPageTest.tsx" "@typescript-eslint/no-unsafe-type-assertion" 7
"../../tests/ui/DynamicCountrySelectionPageTest.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3
"../../tests/ui/DynamicPaymentCardCurrencySelectorPageTest.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1
"../../tests/ui/DynamicReportDetailsPageTest.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2
"../../tests/ui/FloatingActionButtonTest.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type DynamicCountrySelectionPageProps = PlatformStackScreenProps<SettingsNavigat
function DynamicCountrySelectionPage({route}: DynamicCountrySelectionPageProps) {
const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState('');
const {translate} = useLocalize();
const currentCountry = route.params.country;
const currentCountry = route.params?.country;
const backPath = useDynamicBackPath(DYNAMIC_ROUTES.ADDRESS_COUNTRY.path);
const initialSelectedValue = useInitialSelection(currentCountry ?? undefined, {resetOnFocus: true});
const initialSelectedValues = initialSelectedValue ? [initialSelectedValue] : [];
Expand Down
25 changes: 21 additions & 4 deletions tests/ui/DynamicCountrySelectionPageTest.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import type * as ReactNavigation from '@react-navigation/native';
import {act, render} from '@testing-library/react-native';
import React from 'react';
import type {ComponentProps} from 'react';
import SelectionList from '@components/SelectionList';
import searchOptions from '@libs/searchOptions';
import StringUtils from '@libs/StringUtils';
import DynamicCountrySelectionPage from '@pages/settings/Profile/PersonalDetails/DynamicCountrySelectionPage';
import CONST from '@src/CONST';
import createMock from '../utils/createMock';

type DynamicCountrySelectionPageProps = ComponentProps<typeof DynamicCountrySelectionPage>;

const mockUseState = React.useState;
const mockAllCountries = CONST.ALL_COUNTRIES;
Expand Down Expand Up @@ -56,8 +60,8 @@ describe('DynamicCountrySelectionPage', () => {
it('pins the saved country to the top on reopen and wires debounced focus sync', () => {
render(
<DynamicCountrySelectionPage
route={{params: {country: 'US'}} as never}
navigation={jest.fn() as never}
route={createMock<DynamicCountrySelectionPageProps['route']>({params: {country: 'US'}})}
navigation={createMock<DynamicCountrySelectionPageProps['navigation']>({})}
/>,
);

Expand All @@ -76,8 +80,8 @@ describe('DynamicCountrySelectionPage', () => {
it('keeps natural filtered ordering while search is active', () => {
render(
<DynamicCountrySelectionPage
route={{params: {country: 'US'}} as never}
navigation={jest.fn() as never}
route={createMock<DynamicCountrySelectionPageProps['route']>({params: {country: 'US'}})}
navigation={createMock<DynamicCountrySelectionPageProps['navigation']>({})}
/>,
);

Expand All @@ -102,4 +106,17 @@ describe('DynamicCountrySelectionPage', () => {
expect(searchedProps?.data.map((item) => item.keyForList)).toEqual(expectedSearchResults.map((item) => item.keyForList));
expect(searchedProps?.searchValueForFocusSync).toBe('Uni');
});

it('renders without crashing when the route has no params', () => {
render(
<DynamicCountrySelectionPage
route={createMock<DynamicCountrySelectionPageProps['route']>({})}
navigation={createMock<DynamicCountrySelectionPageProps['navigation']>({})}
/>,
);

const selectionListProps = mockedSelectionList.mock.lastCall?.[0];
expect(selectionListProps?.initiallyFocusedItemKey).toBeUndefined();
expect(selectionListProps?.data.every((item) => !item.isSelected)).toBe(true);
});
});
Loading