Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
159 lines
3.9 KiB
TypeScript
159 lines
3.9 KiB
TypeScript
import { Emitter } from '@rocket.chat/emitter';
|
|
import type { CallContact } from '@rocket.chat/media-signaling';
|
|
import { renderHook, act } from '@testing-library/react';
|
|
import type { ReactNode } from 'react';
|
|
|
|
import { MediaCallInstanceContext, defaultContextValue } from './MediaCallInstanceContext';
|
|
import { usePeekMediaSessionPeerInfo } from './usePeekMediaSessionPeerInfo';
|
|
|
|
type MockInstance = {
|
|
getState: () => { confirmed: true; remoteParticipant: { contact: CallContact } } | null;
|
|
on: (event: 'sessionStateChange', onStoreChange: () => void) => () => void;
|
|
};
|
|
|
|
const createWrapper = (instance: MockInstance | undefined) => {
|
|
const wrapper = ({ children }: { children?: ReactNode }) => (
|
|
<MediaCallInstanceContext.Provider
|
|
value={{
|
|
...defaultContextValue,
|
|
instance: instance as any,
|
|
}}
|
|
>
|
|
{children}
|
|
</MediaCallInstanceContext.Provider>
|
|
);
|
|
return wrapper;
|
|
};
|
|
|
|
describe('usePeekMediaSessionPeerInfo', () => {
|
|
it('returns undefined when instance is undefined', () => {
|
|
const { result } = renderHook(() => usePeekMediaSessionPeerInfo(), {
|
|
wrapper: createWrapper(undefined),
|
|
});
|
|
|
|
expect(result.current).toBeUndefined();
|
|
});
|
|
|
|
it('returns undefined when instance has no main call', () => {
|
|
const instance: MockInstance = {
|
|
getState: () => null,
|
|
on: () => () => undefined,
|
|
};
|
|
|
|
const { result } = renderHook(() => usePeekMediaSessionPeerInfo(), {
|
|
wrapper: createWrapper(instance),
|
|
});
|
|
|
|
expect(result.current).toBeUndefined();
|
|
});
|
|
|
|
describe('when main call has a contact', () => {
|
|
it('returns external peer info for SIP contact', () => {
|
|
const instance: MockInstance = {
|
|
getState: () => ({
|
|
confirmed: true,
|
|
remoteParticipant: {
|
|
contact: {
|
|
type: 'sip',
|
|
id: '+5511999999999',
|
|
},
|
|
},
|
|
}),
|
|
on: () => () => undefined,
|
|
};
|
|
|
|
const { result } = renderHook(() => usePeekMediaSessionPeerInfo(), {
|
|
wrapper: createWrapper(instance),
|
|
});
|
|
|
|
expect(result.current).toEqual({ number: '+5511999999999' });
|
|
});
|
|
|
|
it('returns internal peer info for user contact', () => {
|
|
const instance: MockInstance = {
|
|
getState: () => ({
|
|
confirmed: true,
|
|
remoteParticipant: {
|
|
contact: {
|
|
type: 'user',
|
|
id: 'userId123',
|
|
displayName: 'John Doe',
|
|
username: 'johndoe',
|
|
sipExtension: '1001',
|
|
},
|
|
},
|
|
}),
|
|
on: () => () => undefined,
|
|
};
|
|
|
|
const { result } = renderHook(() => usePeekMediaSessionPeerInfo(), {
|
|
wrapper: createWrapper(instance),
|
|
});
|
|
|
|
expect(result.current).toEqual({
|
|
displayName: 'John Doe',
|
|
userId: 'userId123',
|
|
username: 'johndoe',
|
|
callerId: '1001',
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('sessionStateChange subscription', () => {
|
|
it('updates peer info when sessionStateChange is emitted', () => {
|
|
const emitter = new Emitter<{ sessionStateChange: void }>();
|
|
|
|
const defaultInstanceState = {
|
|
confirmed: true as const,
|
|
remoteParticipant: {
|
|
contact: {
|
|
type: 'sip' as const,
|
|
id: '+5511999999999',
|
|
} as CallContact,
|
|
},
|
|
};
|
|
|
|
let instanceState: typeof defaultInstanceState | null = defaultInstanceState;
|
|
|
|
const instance: MockInstance = {
|
|
getState: () => instanceState,
|
|
on: (event, onStoreChange) => emitter.on(event, onStoreChange),
|
|
};
|
|
|
|
const { result } = renderHook(() => usePeekMediaSessionPeerInfo(), {
|
|
wrapper: createWrapper(instance),
|
|
});
|
|
|
|
expect(result.current).toEqual({ number: '+5511999999999' });
|
|
|
|
act(() => {
|
|
instanceState = null;
|
|
emitter.emit('sessionStateChange');
|
|
});
|
|
|
|
expect(result.current).toBeUndefined();
|
|
|
|
act(() => {
|
|
instanceState = {
|
|
confirmed: true,
|
|
remoteParticipant: {
|
|
contact: {
|
|
type: 'user',
|
|
id: 'userId456',
|
|
displayName: 'Jane Smith',
|
|
},
|
|
},
|
|
};
|
|
emitter.emit('sessionStateChange');
|
|
});
|
|
|
|
expect(result.current).toEqual({
|
|
displayName: 'Jane Smith',
|
|
userId: 'userId456',
|
|
username: undefined,
|
|
callerId: undefined,
|
|
});
|
|
});
|
|
});
|
|
});
|