signal-desktop/ts/test-electron/state/selectors/calling_test.ts

147 lines
4.3 KiB
TypeScript
Raw Normal View History

2021-01-08 22:57:54 +00:00
// Copyright 2019-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import { reducer as rootReducer } from '../../../state/reducer';
import { noopAction } from '../../../state/ducks/noop';
2020-11-13 19:57:55 +00:00
import { CallMode, CallState } from '../../../types/Calling';
import {
getCallsByConversation,
getCallSelector,
getIncomingCall,
2021-01-29 22:58:28 +00:00
isInCall,
} from '../../../state/selectors/calling';
2020-11-13 19:57:55 +00:00
import { getEmptyState, CallingStateType } from '../../../state/ducks/calling';
describe('state/selectors/calling', () => {
const getEmptyRootState = () => rootReducer(undefined, noopAction());
const getCallingState = (calling: CallingStateType) => ({
...getEmptyRootState(),
calling,
});
2020-11-13 19:57:55 +00:00
const stateWithDirectCall: CallingStateType = {
...getEmptyState(),
callsByConversation: {
'fake-direct-call-conversation-id': {
2020-11-13 19:57:55 +00:00
callMode: CallMode.Direct,
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 = {
...stateWithDirectCall,
activeCallState: {
conversationId: 'fake-direct-call-conversation-id',
hasLocalAudio: true,
hasLocalVideo: false,
2021-01-08 22:57:54 +00:00
isInSpeakerView: false,
2020-11-17 15:07:53 +00:00
showParticipantsList: false,
safetyNumberChangedUuids: [],
pip: false,
settingsDialogOpen: false,
},
};
2020-11-13 19:57:55 +00:00
const stateWithIncomingDirectCall: CallingStateType = {
...getEmptyState(),
callsByConversation: {
'fake-direct-call-conversation-id': {
2020-11-13 19:57:55 +00:00
callMode: CallMode.Direct,
conversationId: 'fake-direct-call-conversation-id',
callState: CallState.Ringing,
isIncoming: true,
isVideoCall: false,
hasRemoteVideo: false,
},
},
};
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,
}
);
});
});
describe('getIncomingCall', () => {
it('returns undefined if there are no calls', () => {
assert.isUndefined(getIncomingCall(getEmptyRootState()));
});
it('returns undefined if there is no incoming call', () => {
assert.isUndefined(getIncomingCall(getCallingState(stateWithDirectCall)));
assert.isUndefined(
getIncomingCall(getCallingState(stateWithActiveDirectCall))
);
});
it('returns the incoming call', () => {
assert.deepEqual(
getIncomingCall(getCallingState(stateWithIncomingDirectCall)),
{
callMode: CallMode.Direct,
conversationId: 'fake-direct-call-conversation-id',
callState: CallState.Ringing,
isIncoming: true,
isVideoCall: false,
hasRemoteVideo: false,
}
);
});
});
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)));
});
});
});