2022-02-25 15:24:05 +00:00
|
|
|
// Copyright 2019-2022 Signal Messenger, LLC
|
2020-11-06 17:36:37 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
2020-12-02 18:11:54 +00:00
|
|
|
import { reducer as rootReducer } from '../../../state/reducer';
|
|
|
|
import { noopAction } from '../../../state/ducks/noop';
|
2022-07-08 20:46:25 +00:00
|
|
|
import { actions as userActions } from '../../../state/ducks/user';
|
2021-08-20 16:06:15 +00:00
|
|
|
import {
|
|
|
|
CallMode,
|
|
|
|
CallState,
|
2022-05-25 18:03:27 +00:00
|
|
|
CallViewMode,
|
2021-08-20 16:06:15 +00:00
|
|
|
GroupCallConnectionState,
|
|
|
|
GroupCallJoinState,
|
|
|
|
} from '../../../types/Calling';
|
2020-12-07 20:43:19 +00:00
|
|
|
import {
|
|
|
|
getCallsByConversation,
|
|
|
|
getCallSelector,
|
|
|
|
getIncomingCall,
|
2021-01-29 22:58:28 +00:00
|
|
|
isInCall,
|
2020-12-07 20:43:19 +00:00
|
|
|
} from '../../../state/selectors/calling';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type {
|
2021-08-20 16:06:15 +00:00
|
|
|
CallingStateType,
|
|
|
|
DirectCallStateType,
|
|
|
|
GroupCallStateType,
|
|
|
|
} from '../../../state/ducks/calling';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { getEmptyState } from '../../../state/ducks/calling';
|
2020-11-06 17:36:37 +00:00
|
|
|
|
|
|
|
describe('state/selectors/calling', () => {
|
2022-07-08 20:46:25 +00:00
|
|
|
const getEmptyRootState = () => {
|
|
|
|
const initial = rootReducer(undefined, noopAction());
|
|
|
|
return rootReducer(
|
|
|
|
initial,
|
|
|
|
userActions.userChanged({
|
|
|
|
ourACI: '00000000-0000-4000-8000-000000000000',
|
|
|
|
})
|
|
|
|
);
|
|
|
|
};
|
2020-12-02 18:11:54 +00:00
|
|
|
|
|
|
|
const getCallingState = (calling: CallingStateType) => ({
|
|
|
|
...getEmptyRootState(),
|
|
|
|
calling,
|
|
|
|
});
|
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
const stateWithDirectCall: CallingStateType = {
|
2020-11-06 17:36:37 +00:00
|
|
|
...getEmptyState(),
|
|
|
|
callsByConversation: {
|
|
|
|
'fake-direct-call-conversation-id': {
|
2020-11-13 19:57:55 +00:00
|
|
|
callMode: CallMode.Direct,
|
2020-11-06 17:36:37 +00:00
|
|
|
conversationId: 'fake-direct-call-conversation-id',
|
|
|
|
callState: CallState.Accepted,
|
|
|
|
isIncoming: false,
|
|
|
|
isVideoCall: false,
|
|
|
|
hasRemoteVideo: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
const stateWithActiveDirectCall: CallingStateType = {
|
2020-11-06 17:36:37 +00:00
|
|
|
...stateWithDirectCall,
|
|
|
|
activeCallState: {
|
|
|
|
conversationId: 'fake-direct-call-conversation-id',
|
|
|
|
hasLocalAudio: true,
|
|
|
|
hasLocalVideo: false,
|
2022-05-19 03:28:51 +00:00
|
|
|
localAudioLevel: 0,
|
2022-05-25 18:03:27 +00:00
|
|
|
viewMode: CallViewMode.Grid,
|
2020-11-17 15:07:53 +00:00
|
|
|
showParticipantsList: false,
|
2020-12-08 19:37:04 +00:00
|
|
|
safetyNumberChangedUuids: [],
|
2021-08-25 21:42:51 +00:00
|
|
|
outgoingRing: true,
|
2020-11-06 17:36:37 +00:00
|
|
|
pip: false,
|
|
|
|
settingsDialogOpen: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
const incomingDirectCall: DirectCallStateType = {
|
|
|
|
callMode: CallMode.Direct,
|
|
|
|
conversationId: 'fake-direct-call-conversation-id',
|
|
|
|
callState: CallState.Ringing,
|
|
|
|
isIncoming: true,
|
|
|
|
isVideoCall: false,
|
|
|
|
hasRemoteVideo: false,
|
|
|
|
};
|
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
const stateWithIncomingDirectCall: CallingStateType = {
|
2020-11-06 17:36:37 +00:00
|
|
|
...getEmptyState(),
|
|
|
|
callsByConversation: {
|
2021-08-20 16:06:15 +00:00
|
|
|
'fake-direct-call-conversation-id': incomingDirectCall,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const incomingGroupCall: GroupCallStateType = {
|
|
|
|
callMode: CallMode.Group,
|
|
|
|
conversationId: 'fake-group-call-conversation-id',
|
|
|
|
connectionState: GroupCallConnectionState.NotConnected,
|
|
|
|
joinState: GroupCallJoinState.NotJoined,
|
|
|
|
peekInfo: {
|
|
|
|
uuids: ['c75b51da-d484-4674-9b2c-cc11de00e227'],
|
|
|
|
creatorUuid: 'c75b51da-d484-4674-9b2c-cc11de00e227',
|
|
|
|
maxDevices: Infinity,
|
|
|
|
deviceCount: 1,
|
|
|
|
},
|
|
|
|
remoteParticipants: [],
|
|
|
|
ringId: BigInt(123),
|
|
|
|
ringerUuid: 'c75b51da-d484-4674-9b2c-cc11de00e227',
|
|
|
|
};
|
|
|
|
|
|
|
|
const stateWithIncomingGroupCall: CallingStateType = {
|
|
|
|
...getEmptyState(),
|
|
|
|
callsByConversation: {
|
|
|
|
'fake-group-call-conversation-id': incomingGroupCall,
|
2020-11-06 17:36:37 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-12-07 20:43:19 +00:00
|
|
|
describe('getCallsByConversation', () => {
|
|
|
|
it('returns state.calling.callsByConversation', () => {
|
|
|
|
assert.deepEqual(getCallsByConversation(getEmptyRootState()), {});
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
getCallsByConversation(getCallingState(stateWithDirectCall)),
|
|
|
|
{
|
|
|
|
'fake-direct-call-conversation-id': {
|
|
|
|
callMode: CallMode.Direct,
|
|
|
|
conversationId: 'fake-direct-call-conversation-id',
|
|
|
|
callState: CallState.Accepted,
|
|
|
|
isIncoming: false,
|
|
|
|
isVideoCall: false,
|
|
|
|
hasRemoteVideo: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getCallSelector', () => {
|
|
|
|
it('returns a selector that returns undefined if selecting a conversation with no call', () => {
|
|
|
|
assert.isUndefined(
|
|
|
|
getCallSelector(getEmptyRootState())('conversation-id')
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns a selector that returns a conversation's call", () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
getCallSelector(getCallingState(stateWithDirectCall))(
|
|
|
|
'fake-direct-call-conversation-id'
|
|
|
|
),
|
|
|
|
{
|
|
|
|
callMode: CallMode.Direct,
|
|
|
|
conversationId: 'fake-direct-call-conversation-id',
|
|
|
|
callState: CallState.Accepted,
|
|
|
|
isIncoming: false,
|
|
|
|
isVideoCall: false,
|
|
|
|
hasRemoteVideo: false,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-06 17:36:37 +00:00
|
|
|
describe('getIncomingCall', () => {
|
|
|
|
it('returns undefined if there are no calls', () => {
|
2020-12-02 18:11:54 +00:00
|
|
|
assert.isUndefined(getIncomingCall(getEmptyRootState()));
|
2020-11-06 17:36:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns undefined if there is no incoming call', () => {
|
2020-12-02 18:11:54 +00:00
|
|
|
assert.isUndefined(getIncomingCall(getCallingState(stateWithDirectCall)));
|
|
|
|
assert.isUndefined(
|
|
|
|
getIncomingCall(getCallingState(stateWithActiveDirectCall))
|
|
|
|
);
|
2020-11-06 17:36:37 +00:00
|
|
|
});
|
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
it('returns undefined if there is a group call with no peeked participants', () => {
|
|
|
|
const state = {
|
|
|
|
...stateWithIncomingGroupCall,
|
|
|
|
callsByConversation: {
|
|
|
|
'fake-group-call-conversation-id': {
|
|
|
|
...incomingGroupCall,
|
|
|
|
peekInfo: {
|
|
|
|
uuids: [],
|
|
|
|
maxDevices: Infinity,
|
|
|
|
deviceCount: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.isUndefined(getIncomingCall(getCallingState(state)));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns an incoming direct call', () => {
|
2020-12-02 18:11:54 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
getIncomingCall(getCallingState(stateWithIncomingDirectCall)),
|
2021-08-20 16:06:15 +00:00
|
|
|
incomingDirectCall
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns an incoming group call', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
getIncomingCall(getCallingState(stateWithIncomingGroupCall)),
|
|
|
|
incomingGroupCall
|
2020-12-02 18:11:54 +00:00
|
|
|
);
|
2020-11-06 17:36:37 +00:00
|
|
|
});
|
|
|
|
});
|
2021-01-29 22:58:28 +00:00
|
|
|
|
|
|
|
describe('isInCall', () => {
|
|
|
|
it('returns should be false if we are not in a call', () => {
|
|
|
|
assert.isFalse(isInCall(getEmptyRootState()));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be true if we are in a call', () => {
|
|
|
|
assert.isTrue(isInCall(getCallingState(stateWithActiveDirectCall)));
|
|
|
|
});
|
|
|
|
});
|
2020-11-06 17:36:37 +00:00
|
|
|
});
|