Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 3 additions & 1 deletion app/containers/NewMediaCall/NewMediaCall.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect } from 'react';
import { StyleSheet, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

import { PeerList } from './PeerList';
import { SelectedPeer } from './SelectedPeer';
Expand All @@ -11,10 +12,11 @@ import { useTheme } from '../../theme';
export const NewMediaCall = (): React.ReactElement => {
const { colors } = useTheme();
const reset = usePeerAutocompleteStore(state => state.reset);
const { bottom } = useSafeAreaInsets();
useEffect(() => () => reset(), [reset]);

return (
<View style={[styles.screen, { backgroundColor: colors.surfaceLight }]}>
<View style={[styles.screen, { backgroundColor: colors.surfaceLight, paddingBottom: bottom + 16 }]}>
<FilterHeader />
<SelectedPeer />
<PeerList />
Expand Down
6 changes: 6 additions & 0 deletions app/containers/NewMediaCall/PeerList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ describe('PeerList', () => {
expect(queryByTestId('new-media-call-option-user-1')).toBeNull();
});

it('should return null when there are no options', () => {
usePeerAutocompleteStore.setState({ options: [], selectedPeer: null });
const { toJSON } = render(<PeerList />);
expect(toJSON()).toBeNull();
});

it('should set selected peer, clear filter and fetch options when option is pressed', () => {
usePeerAutocompleteStore.setState({
options: mockOptions,
Expand Down
4 changes: 3 additions & 1 deletion app/containers/NewMediaCall/PeerList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export const PeerList = () => {
const selectedPeer = usePeerAutocompleteStore(state => state.selectedPeer);
const options = usePeerAutocompleteStore(state => state.options);

if (selectedPeer) return null;
if (selectedPeer || options.length === 0) {
return null;
}

const handleSelectOption = (option: TPeerItem) => {
setSelectedPeer(option);
Expand Down
32 changes: 31 additions & 1 deletion app/lib/hooks/useNewMediaCall/useNewMediaCall.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,21 @@ jest.mock('../../../containers/NewMediaCall', () => ({
NewMediaCall: jest.fn(() => null)
}));

jest.mock('../../methods/helpers/deviceInfo', () => ({
isAndroid: false
}));

describe('useNewMediaCall', () => {
beforeEach(() => {
jest.clearAllMocks();
});

const expectNewMediaCallActionSheet = () => {
const expectNewMediaCallActionSheet = (expectedFullContainer = false) => {
expect(mockShowActionSheetRef).toHaveBeenCalledTimes(1);
const [actionSheetArgs] = mockShowActionSheetRef.mock.calls[0];
expect(React.isValidElement(actionSheetArgs.children)).toBe(true);
expect(actionSheetArgs.children.type).toBe(NewMediaCall);
expect(actionSheetArgs.fullContainer).toBe(expectedFullContainer);
};

it('should set selected peer and open action sheet when room has a direct message peer', () => {
Expand Down Expand Up @@ -103,4 +108,29 @@ describe('useNewMediaCall', () => {
expect(mockSetSelectedPeer).not.toHaveBeenCalled();
expectNewMediaCallActionSheet();
});

it('should pass fullContainer to the action sheet when isAndroid is true', () => {
jest.resetModules();
jest.doMock('../../methods/helpers/deviceInfo', () => ({
isAndroid: true
}));
// Must load hook after doMock so `fullContainer: isAndroid` uses Android.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { useNewMediaCall: useNewMediaCallAndroid } = require('./useNewMediaCall');

mockUseSubscription.mockReturnValue(undefined);
mockUseMediaCallPermission.mockReturnValue(false);

const { result } = renderHook(() => useNewMediaCallAndroid('room-id'));

act(() => {
result.current.openNewMediaCall();
});

// Re-required hook uses a fresh NewMediaCall mock ref; only assert fullContainer and element shape.
expect(mockShowActionSheetRef).toHaveBeenCalledTimes(1);
const [actionSheetArgs] = mockShowActionSheetRef.mock.calls[0];
expect(React.isValidElement(actionSheetArgs.children)).toBe(true);
expect(actionSheetArgs.fullContainer).toBe(true);
});
});
6 changes: 2 additions & 4 deletions app/lib/hooks/useNewMediaCall/useNewMediaCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getUidDirectMessage } from '../../methods/helpers/helpers';
import { usePeerAutocompleteStore } from '../../services/voip/usePeerAutocompleteStore';
import { useSubscription } from '../useSubscription';
import { useMediaCallPermission } from '../useMediaCallPermission';
import { isAndroid } from '../../methods/helpers/deviceInfo';

export const useNewMediaCall = (rid?: string) => {
const room = useSubscription(rid);
Expand All @@ -20,10 +21,7 @@ export const useNewMediaCall = (rid?: string) => {
}
showActionSheetRef({
children: <NewMediaCall />,
portraitSnaps: ['60%'],
landscapeSnaps: ['90%'],
enableContentPanningGesture: false,
fullContainer: true
fullContainer: isAndroid
});
Comment thread
diegolmello marked this conversation as resolved.
};

Expand Down
Loading