-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/ses-experimental-setting
- Loading branch information
Showing
224 changed files
with
2,768 additions
and
2,183 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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
25 changes: 5 additions & 20 deletions
25
app/component-library/components/BottomSheets/BottomSheet/BottomSheet.types.ts
This file contains 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 |
---|---|---|
@@ -1,35 +1,20 @@ | ||
import { ViewProps } from 'react-native'; | ||
// Internal dependencies. | ||
import { BottomSheetDialogProps } from './foundation/BottomSheetDialog/BottomSheetDialog.types'; | ||
|
||
/** | ||
* BottomSheet component props. | ||
*/ | ||
export interface BottomSheetProps extends ViewProps { | ||
/** | ||
* Content to wrap for multiselect. | ||
*/ | ||
children: React.ReactNode; | ||
/** | ||
* Optional callback that gets triggered when sheet is dismissed. | ||
*/ | ||
onClose?: (hasPendingAction: boolean) => void; | ||
/** | ||
* Optional boolean that indicates if sheet is swippable. This affects whether or not tapping on the overlay will dismiss the sheet as well. | ||
* @default true | ||
*/ | ||
isInteractable?: boolean; | ||
export interface BottomSheetProps extends BottomSheetDialogProps { | ||
/** | ||
* Optional boolean that indicates if sheet isUnmounted from the stack or not when closed. | ||
* @default true | ||
*/ | ||
shouldNavigateBack?: boolean; | ||
/** | ||
* Optional boolean that allow the bottomsheet to grow until the top. | ||
*/ | ||
isFlexible?: boolean; | ||
} | ||
|
||
export type BottomSheetPostCallback = () => void; | ||
|
||
export interface BottomSheetRef { | ||
hide: (callback?: BottomSheetPostCallback) => void; | ||
onOpenBottomSheet: (callback?: BottomSheetPostCallback) => void; | ||
onCloseBottomSheet: (callback?: BottomSheetPostCallback) => void; | ||
} |
98 changes: 98 additions & 0 deletions
98
...mponents/BottomSheets/BottomSheet/foundation/BottomSheetDialog/BottomSheetDialog.test.tsx
This file contains 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,98 @@ | ||
// Third party dependencies | ||
import React, { useRef, useEffect } from 'react'; | ||
import { render, act } from '@testing-library/react-native'; | ||
|
||
// External dependencies. | ||
import Text from '../../../../Texts/Text'; | ||
|
||
// Internal dependencies | ||
import BottomSheetDialog from './BottomSheetDialog'; | ||
import { BottomSheetDialogRef } from './BottomSheetDialog.types'; | ||
|
||
jest.mock('react-native-safe-area-context', () => { | ||
// using disting digits for mock rects to make sure they are not mixed up | ||
const inset = { top: 1, right: 2, bottom: 3, left: 4 }; | ||
const frame = { width: 5, height: 6, x: 7, y: 8 }; | ||
return { | ||
SafeAreaProvider: jest.fn().mockImplementation(({ children }) => children), | ||
SafeAreaConsumer: jest | ||
.fn() | ||
.mockImplementation(({ children }) => children(inset)), | ||
useSafeAreaInsets: jest.fn().mockImplementation(() => inset), | ||
useSafeAreaFrame: jest.fn().mockImplementation(() => frame), | ||
}; | ||
}); | ||
|
||
jest.mock('@react-navigation/native', () => { | ||
const actualNav = jest.requireActual('@react-navigation/native'); | ||
return { | ||
...actualNav, | ||
useNavigation: () => ({ | ||
navigate: jest.fn(), | ||
}), | ||
}; | ||
}); | ||
|
||
describe('BottomSheetDialog', () => { | ||
it('should render correctly', () => { | ||
const wrapper = render(<BottomSheetDialog />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
it('should render the component with children', () => { | ||
const { getByText } = render( | ||
<BottomSheetDialog> | ||
<Text>Test Child</Text> | ||
</BottomSheetDialog>, | ||
); | ||
expect(getByText('Test Child')).toBeTruthy(); | ||
}); | ||
it('should call onOpen when onOpenDialog ref is called', () => { | ||
const onOpenMock = jest.fn(); | ||
const TestComponent = () => { | ||
const ref = useRef<BottomSheetDialogRef>(null); | ||
|
||
useEffect(() => { | ||
if (ref.current) { | ||
act(() => { | ||
ref.current?.onOpenDialog(); | ||
}); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<BottomSheetDialog ref={ref} onOpen={onOpenMock}> | ||
<Text>Test Child</Text> | ||
</BottomSheetDialog> | ||
); | ||
}; | ||
|
||
render(<TestComponent />); | ||
|
||
expect(onOpenMock).toHaveBeenCalled(); | ||
}); | ||
it('should call onClose when onCloseDialog ref is called', () => { | ||
const onCloseMock = jest.fn(); | ||
const TestComponent = () => { | ||
const ref = useRef<BottomSheetDialogRef>(null); | ||
|
||
useEffect(() => { | ||
if (ref.current) { | ||
act(() => { | ||
ref.current?.onCloseDialog(); | ||
}); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<BottomSheetDialog ref={ref} onClose={onCloseMock}> | ||
<Text>Test Child</Text> | ||
</BottomSheetDialog> | ||
); | ||
}; | ||
|
||
render(<TestComponent />); | ||
|
||
expect(onCloseMock).toHaveBeenCalled(); | ||
}); | ||
// Note: Add Gesture tests when react-native-gesture-handler gets updated | ||
}); |
Oops, something went wrong.