-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Update call UI #6990
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
Merged
Merged
feat: Update call UI #6990
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4dd2aa0
refactor(CallView): Simplify call state management and UI components;…
diegolmello 19f7c03
feat(CallHeader): Introduce Content and Subtitle components; refactor…
diegolmello 0803455
rename CallHeader -> MediaCallHeader
diegolmello 2791f64
Fix subtitle logic
diegolmello 5efdc7b
Add nav to room mock to MediaCallHeader
diegolmello d3cd9ac
Align left
diegolmello a48bf11
Add unit tests
diegolmello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
104 changes: 104 additions & 0 deletions
104
app/containers/MediaCallHeader/MediaCallHeader.stories.tsx
This file contains hidden or 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,104 @@ | ||
| import React from 'react'; | ||
| import { View, StyleSheet } from 'react-native'; | ||
|
|
||
| import MediaCallHeader from './MediaCallHeader'; | ||
| import { useCallStore } from '../../lib/services/voip/useCallStore'; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container: { | ||
| flex: 1 | ||
| } | ||
| }); | ||
|
|
||
| const mockCallStartTime = 1713340800000; | ||
|
|
||
| // Helper to set store state for stories | ||
| const setStoreState = (overrides: Partial<ReturnType<typeof useCallStore.getState>> = {}) => { | ||
| const mockCall = { | ||
| state: 'active', | ||
| muted: false, | ||
| held: false, | ||
| contact: { | ||
| displayName: 'Bob Burnquist', | ||
| username: 'bob.burnquist', | ||
| sipExtension: '2244' | ||
| }, | ||
| setMuted: () => {}, | ||
| setHeld: () => {}, | ||
| hangup: () => {}, | ||
| reject: () => {}, | ||
| emitter: { | ||
| on: () => {}, | ||
| off: () => {} | ||
| } | ||
| } as any; | ||
|
|
||
| useCallStore.setState({ | ||
| call: mockCall, | ||
| callUUID: 'test-uuid', | ||
| callState: 'active', | ||
| isMuted: false, | ||
| isOnHold: false, | ||
| isSpeakerOn: false, | ||
| callStartTime: mockCallStartTime, | ||
| contact: { | ||
| id: 'user-1', | ||
| displayName: 'Bob Burnquist', | ||
| username: 'bob.burnquist', | ||
| sipExtension: '2244' | ||
| }, | ||
| focused: true, | ||
| remoteMute: false, | ||
| remoteHeld: false, | ||
| ...overrides | ||
| }); | ||
| }; | ||
|
|
||
| const Wrapper = ({ children }: { children: React.ReactNode }) => <View style={styles.container}>{children}</View>; | ||
|
|
||
| export default { | ||
| title: 'MediaCallHeader', | ||
| component: MediaCallHeader, | ||
| decorators: [ | ||
| (Story: React.ComponentType) => ( | ||
| <Wrapper> | ||
| <Story /> | ||
| </Wrapper> | ||
| ) | ||
| ] | ||
| }; | ||
|
|
||
| export const NoCall = () => { | ||
| useCallStore.setState({ call: null }); | ||
| return <MediaCallHeader />; | ||
| }; | ||
|
|
||
| export const ActiveCall = () => { | ||
| setStoreState({ callState: 'active', callStartTime: mockCallStartTime }); | ||
| return <MediaCallHeader />; | ||
| }; | ||
|
|
||
| export const ConnectingCall = () => { | ||
| setStoreState({ callState: 'accepted', callStartTime: null }); | ||
| return <MediaCallHeader />; | ||
| }; | ||
|
|
||
| export const Focused = () => { | ||
| setStoreState({ focused: true }); | ||
| return <MediaCallHeader />; | ||
| }; | ||
|
|
||
| export const Collapsed = () => { | ||
| setStoreState({ focused: false }); | ||
| return <MediaCallHeader />; | ||
| }; | ||
|
|
||
| export const WithRemoteHeld = () => { | ||
| setStoreState({ callState: 'active', remoteHeld: true }); | ||
| return <MediaCallHeader />; | ||
| }; | ||
|
|
||
| export const WithRemoteMuted = () => { | ||
| setStoreState({ callState: 'active', remoteMute: true }); | ||
| return <MediaCallHeader />; | ||
| }; |
172 changes: 172 additions & 0 deletions
172
app/containers/MediaCallHeader/MediaCallHeader.test.tsx
This file contains hidden or 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,172 @@ | ||
| import React from 'react'; | ||
| import { fireEvent, render } from '@testing-library/react-native'; | ||
| import { Provider } from 'react-redux'; | ||
|
|
||
| import MediaCallHeader from './MediaCallHeader'; | ||
| import { useCallStore } from '../../lib/services/voip/useCallStore'; | ||
| import { mockedStore } from '../../reducers/mockedStore'; | ||
| import * as stories from './MediaCallHeader.stories'; | ||
| import { generateSnapshots } from '../../../.rnstorybook/generateSnapshots'; | ||
|
|
||
| // Mock alert | ||
| global.alert = jest.fn(); | ||
|
|
||
| // Helper to create a mock call | ||
| const createMockCall = (overrides: Record<string, unknown> = {}) => ({ | ||
| state: 'active', | ||
| muted: false, | ||
| held: false, | ||
| contact: { | ||
| displayName: 'Bob Burnquist', | ||
| username: 'bob.burnquist', | ||
| sipExtension: '2244' | ||
| }, | ||
| setMuted: jest.fn(), | ||
| setHeld: jest.fn(), | ||
| hangup: jest.fn(), | ||
| reject: jest.fn(), | ||
| emitter: { | ||
| on: jest.fn(), | ||
| off: jest.fn() | ||
| }, | ||
| ...overrides | ||
| }); | ||
|
|
||
| // Helper to set store state for tests | ||
| const setStoreState = (overrides: Partial<ReturnType<typeof useCallStore.getState>> = {}) => { | ||
| const mockCall = createMockCall(); | ||
| useCallStore.setState({ | ||
| call: mockCall as any, | ||
| callUUID: 'test-uuid', | ||
| callState: 'active', | ||
| isMuted: false, | ||
| isOnHold: false, | ||
| isSpeakerOn: false, | ||
| callStartTime: Date.now(), | ||
| contact: { | ||
| id: 'user-1', | ||
| displayName: 'Bob Burnquist', | ||
| username: 'bob.burnquist', | ||
| sipExtension: '2244' | ||
| }, | ||
| focused: true, | ||
| remoteMute: false, | ||
| remoteHeld: false, | ||
| ...overrides | ||
| }); | ||
| }; | ||
|
|
||
| const Wrapper = ({ children }: { children: React.ReactNode }) => ( | ||
| <Provider store={mockedStore}>{children}</Provider> | ||
| ); | ||
|
|
||
| describe('MediaCallHeader', () => { | ||
| beforeEach(() => { | ||
| useCallStore.getState().reset(); | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('should render empty placeholder when there is no call', () => { | ||
| useCallStore.setState({ call: null }); | ||
| const { getByTestId, queryByTestId } = render( | ||
| <Wrapper> | ||
| <MediaCallHeader /> | ||
| </Wrapper> | ||
| ); | ||
|
|
||
| expect(getByTestId('media-call-header-empty')).toBeTruthy(); | ||
| expect(queryByTestId('media-call-header')).toBeNull(); | ||
| expect(queryByTestId('media-call-header-collapse')).toBeNull(); | ||
| expect(queryByTestId('media-call-header-content')).toBeNull(); | ||
| expect(queryByTestId('media-call-header-end')).toBeNull(); | ||
| }); | ||
|
|
||
| it('should render full header when call exists', () => { | ||
| setStoreState(); | ||
| const { getByTestId } = render( | ||
| <Wrapper> | ||
| <MediaCallHeader /> | ||
| </Wrapper> | ||
| ); | ||
|
|
||
| expect(getByTestId('media-call-header')).toBeTruthy(); | ||
| expect(getByTestId('media-call-header-collapse')).toBeTruthy(); | ||
| expect(getByTestId('media-call-header-content')).toBeTruthy(); | ||
| expect(getByTestId('media-call-header-end')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should show caller name in Title', () => { | ||
| setStoreState({ | ||
| contact: { | ||
| id: 'user-1', | ||
| displayName: 'Alice Smith', | ||
| username: 'alice.smith', | ||
| sipExtension: '1234' | ||
| } | ||
| }); | ||
| const { getByTestId, getByText } = render( | ||
| <Wrapper> | ||
| <MediaCallHeader /> | ||
| </Wrapper> | ||
| ); | ||
|
|
||
| expect(getByTestId('call-view-header-title')).toBeTruthy(); | ||
| // Title renders name plus optional Timer in nested Text; match by regex | ||
| expect(getByText(/Alice Smith/)).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should show subtitle when connecting', () => { | ||
| setStoreState({ callState: 'ringing' }); | ||
| const { getByTestId } = render( | ||
| <Wrapper> | ||
| <MediaCallHeader /> | ||
| </Wrapper> | ||
| ); | ||
|
|
||
| expect(getByTestId('call-view-header-subtitle')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should call toggleFocus when collapse button is pressed', () => { | ||
| setStoreState(); | ||
| const toggleFocus = jest.fn(); | ||
| useCallStore.setState({ toggleFocus }); | ||
|
|
||
| const { getByTestId } = render( | ||
| <Wrapper> | ||
| <MediaCallHeader /> | ||
| </Wrapper> | ||
| ); | ||
|
|
||
| fireEvent.press(getByTestId('media-call-header-collapse')); | ||
| expect(toggleFocus).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('should call endCall when end button is pressed', () => { | ||
| setStoreState(); | ||
| const endCall = jest.fn(); | ||
| useCallStore.setState({ endCall }); | ||
|
|
||
| const { getByTestId } = render( | ||
| <Wrapper> | ||
| <MediaCallHeader /> | ||
| </Wrapper> | ||
| ); | ||
|
|
||
| fireEvent.press(getByTestId('media-call-header-end')); | ||
| expect(endCall).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('should show alert when content is pressed', () => { | ||
| setStoreState(); | ||
| const { getByTestId } = render( | ||
| <Wrapper> | ||
| <MediaCallHeader /> | ||
| </Wrapper> | ||
| ); | ||
|
|
||
| fireEvent.press(getByTestId('media-call-header-content')); | ||
| expect(global.alert).toHaveBeenCalledWith('nav to call room'); | ||
| }); | ||
| }); | ||
|
|
||
| generateSnapshots(stories); | ||
19 changes: 10 additions & 9 deletions
19
app/containers/CallHeader/CallHeader.tsx → ...iners/MediaCallHeader/MediaCallHeader.tsx
This file contains hidden or 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,46 +1,47 @@ | ||
| import { StyleSheet, View } from 'react-native'; | ||
| import { useSafeAreaInsets } from 'react-native-safe-area-context'; | ||
| import { useShallow } from 'zustand/react/shallow'; | ||
|
|
||
| import { useTheme } from '../../theme'; | ||
| import Collapse from './components/Collapse'; | ||
| import Title from './components/Title'; | ||
| import EndCall from './components/EndCall'; | ||
| import { useCallStore } from '../../lib/services/voip/useCallStore'; | ||
| import { Content } from './components/Content'; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| header: { | ||
| flexDirection: 'row', | ||
| justifyContent: 'space-between', | ||
| alignItems: 'center', | ||
| paddingHorizontal: 12, | ||
| paddingBottom: 4, | ||
| borderBottomWidth: StyleSheet.hairlineWidth | ||
| } | ||
| }); | ||
|
|
||
| const CallHeader = () => { | ||
| const MediaCallHeader = () => { | ||
| 'use memo'; | ||
|
|
||
| const { colors } = useTheme(); | ||
| const insets = useSafeAreaInsets(); | ||
| const call = useCallStore(useShallow(state => state.call)); | ||
|
|
||
| const defaultHeaderStyle = { | ||
| backgroundColor: colors.surfaceNeutral, | ||
| paddingTop: insets.top | ||
| paddingTop: insets.top + 12, | ||
| paddingBottom: 12 | ||
| }; | ||
|
|
||
| const call = useCallStore(state => state.call); | ||
| if (!call) { | ||
| return <View style={defaultHeaderStyle} />; | ||
| return <View style={defaultHeaderStyle} testID='media-call-header-empty' />; | ||
| } | ||
|
|
||
| return ( | ||
| <View style={[styles.header, { ...defaultHeaderStyle, borderBottomColor: colors.strokeLight }]}> | ||
| <View style={[styles.header, { ...defaultHeaderStyle, borderBottomColor: colors.strokeLight }]} testID='media-call-header'> | ||
| <Collapse /> | ||
| <Title /> | ||
| <Content /> | ||
| <EndCall /> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| export default CallHeader; | ||
| export default MediaCallHeader; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.