2021-02-23 20:34:28 +00:00
|
|
|
// Copyright 2019-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
import { assert } from 'chai';
|
|
|
|
|
2021-01-06 15:41:43 +00:00
|
|
|
import {
|
2021-03-03 20:09:58 +00:00
|
|
|
OneTimeModalState,
|
|
|
|
ComposerStep,
|
2021-01-06 15:41:43 +00:00
|
|
|
ConversationLookupType,
|
|
|
|
ConversationType,
|
|
|
|
getEmptyState,
|
|
|
|
} from '../../../state/ducks/conversations';
|
2019-01-14 21:49:58 +00:00
|
|
|
import {
|
|
|
|
_getConversationComparator,
|
2019-03-12 00:20:16 +00:00
|
|
|
_getLeftPaneLists,
|
2021-03-11 21:29:31 +00:00
|
|
|
getCandidateContactsForNewGroup,
|
2021-03-03 20:09:58 +00:00
|
|
|
getCantAddContactForModal,
|
2021-02-23 20:34:28 +00:00
|
|
|
getComposeContacts,
|
2021-04-20 23:16:49 +00:00
|
|
|
getComposeGroups,
|
2021-03-03 20:09:58 +00:00
|
|
|
getComposeGroupAvatar,
|
|
|
|
getComposeGroupName,
|
|
|
|
getComposeSelectedContacts,
|
2021-04-20 23:16:49 +00:00
|
|
|
getComposerConversationSearchTerm,
|
2021-03-03 20:09:58 +00:00
|
|
|
getComposerStep,
|
2021-01-06 15:41:43 +00:00
|
|
|
getConversationSelector,
|
2021-03-03 20:09:58 +00:00
|
|
|
getInvitedContactsForNewlyCreatedGroup,
|
|
|
|
getMaximumGroupSizeModalState,
|
2021-01-06 15:41:43 +00:00
|
|
|
getPlaceholderContact,
|
2021-03-03 20:09:58 +00:00
|
|
|
getRecommendedGroupSizeModalState,
|
2021-02-12 21:58:14 +00:00
|
|
|
getSelectedConversation,
|
|
|
|
getSelectedConversationId,
|
2021-03-03 20:09:58 +00:00
|
|
|
hasGroupCreationError,
|
|
|
|
isCreatingGroup,
|
2019-01-14 21:49:58 +00:00
|
|
|
} from '../../../state/selectors/conversations';
|
2021-01-06 15:41:43 +00:00
|
|
|
import { noopAction } from '../../../state/ducks/noop';
|
|
|
|
import { StateType, reducer as rootReducer } from '../../../state/reducer';
|
2021-02-23 20:34:28 +00:00
|
|
|
import { setup as setupI18n } from '../../../../js/modules/i18n';
|
|
|
|
import enMessages from '../../../../_locales/en/messages.json';
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2020-12-04 20:41:40 +00:00
|
|
|
describe('both/state/selectors/conversations', () => {
|
2021-01-06 15:41:43 +00:00
|
|
|
const getEmptyRootState = (): StateType => {
|
|
|
|
return rootReducer(undefined, noopAction());
|
|
|
|
};
|
|
|
|
|
|
|
|
function getDefaultConversation(id: string): ConversationType {
|
|
|
|
return {
|
|
|
|
id,
|
|
|
|
type: 'direct',
|
2021-04-27 22:35:35 +00:00
|
|
|
searchableTitle: `${id} title`,
|
2021-01-06 15:41:43 +00:00
|
|
|
title: `${id} title`,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
2021-01-06 15:41:43 +00:00
|
|
|
describe('#getConversationSelector', () => {
|
|
|
|
it('returns empty placeholder if falsey id provided', () => {
|
|
|
|
const state = getEmptyRootState();
|
|
|
|
const selector = getConversationSelector(state);
|
|
|
|
|
|
|
|
const actual = selector(undefined);
|
|
|
|
|
|
|
|
assert.deepEqual(actual, getPlaceholderContact());
|
|
|
|
});
|
|
|
|
it('returns empty placeholder if no match', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
};
|
|
|
|
const selector = getConversationSelector(state);
|
|
|
|
|
|
|
|
const actual = selector('random-id');
|
|
|
|
|
|
|
|
assert.deepEqual(actual, getPlaceholderContact());
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns conversation by e164 first', () => {
|
|
|
|
const id = 'id';
|
|
|
|
|
|
|
|
const conversation = getDefaultConversation(id);
|
|
|
|
const wrongConversation = getDefaultConversation('wrong');
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
[id]: wrongConversation,
|
|
|
|
},
|
|
|
|
conversationsByE164: {
|
|
|
|
[id]: conversation,
|
|
|
|
},
|
|
|
|
conversationsByUuid: {
|
|
|
|
[id]: wrongConversation,
|
|
|
|
},
|
|
|
|
conversationsByGroupId: {
|
|
|
|
[id]: wrongConversation,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const selector = getConversationSelector(state);
|
|
|
|
|
|
|
|
const actual = selector(id);
|
|
|
|
|
|
|
|
assert.strictEqual(actual, conversation);
|
|
|
|
});
|
|
|
|
it('returns conversation by uuid', () => {
|
|
|
|
const id = 'id';
|
|
|
|
|
|
|
|
const conversation = getDefaultConversation(id);
|
|
|
|
const wrongConversation = getDefaultConversation('wrong');
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
[id]: wrongConversation,
|
|
|
|
},
|
|
|
|
conversationsByUuid: {
|
|
|
|
[id]: conversation,
|
|
|
|
},
|
|
|
|
conversationsByGroupId: {
|
|
|
|
[id]: wrongConversation,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const selector = getConversationSelector(state);
|
|
|
|
|
|
|
|
const actual = selector(id);
|
|
|
|
|
|
|
|
assert.strictEqual(actual, conversation);
|
|
|
|
});
|
|
|
|
it('returns conversation by groupId', () => {
|
|
|
|
const id = 'id';
|
|
|
|
|
|
|
|
const conversation = getDefaultConversation(id);
|
|
|
|
const wrongConversation = getDefaultConversation('wrong');
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
[id]: wrongConversation,
|
|
|
|
},
|
|
|
|
conversationsByGroupId: {
|
|
|
|
[id]: conversation,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const selector = getConversationSelector(state);
|
|
|
|
|
|
|
|
const actual = selector(id);
|
|
|
|
|
|
|
|
assert.strictEqual(actual, conversation);
|
|
|
|
});
|
|
|
|
it('returns conversation by conversationId', () => {
|
|
|
|
const id = 'id';
|
|
|
|
|
|
|
|
const conversation = getDefaultConversation(id);
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
[id]: conversation,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const selector = getConversationSelector(state);
|
|
|
|
|
|
|
|
const actual = selector(id);
|
|
|
|
|
|
|
|
assert.strictEqual(actual, conversation);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Less important now, given that all prop-generation for conversations is in
|
|
|
|
// models/conversation.getProps() and not here.
|
|
|
|
it('does proper caching of result', () => {
|
|
|
|
const id = 'id';
|
|
|
|
|
|
|
|
const conversation = getDefaultConversation(id);
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
[id]: conversation,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const selector = getConversationSelector(state);
|
|
|
|
|
|
|
|
const actual = selector(id);
|
|
|
|
|
|
|
|
const secondState = {
|
|
|
|
...state,
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
[id]: conversation,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const secondSelector = getConversationSelector(secondState);
|
|
|
|
const secondActual = secondSelector(id);
|
|
|
|
|
|
|
|
assert.strictEqual(actual, secondActual);
|
|
|
|
|
|
|
|
const thirdState = {
|
|
|
|
...state,
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
[id]: getDefaultConversation('third'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const thirdSelector = getConversationSelector(thirdState);
|
|
|
|
const thirdActual = thirdSelector(id);
|
|
|
|
|
|
|
|
assert.notStrictEqual(actual, thirdActual);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
describe('#getInvitedContactsForNewlyCreatedGroup', () => {
|
|
|
|
it('returns an empty array if there are no invited contacts', () => {
|
|
|
|
const state = getEmptyRootState();
|
|
|
|
|
|
|
|
assert.deepEqual(getInvitedContactsForNewlyCreatedGroup(state), []);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns "hydrated" invited contacts', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
abc: getDefaultConversation('abc'),
|
|
|
|
def: getDefaultConversation('def'),
|
|
|
|
},
|
|
|
|
invitedConversationIdsForNewlyCreatedGroup: ['def', 'abc'],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const result = getInvitedContactsForNewlyCreatedGroup(state);
|
|
|
|
const titles = result.map(conversation => conversation.title);
|
|
|
|
|
|
|
|
assert.deepEqual(titles, ['def title', 'abc title']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getComposerStep', () => {
|
|
|
|
it("returns undefined if the composer isn't open", () => {
|
|
|
|
const state = getEmptyRootState();
|
|
|
|
const result = getComposerStep(state);
|
|
|
|
|
|
|
|
assert.isUndefined(result);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the first step of the composer', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.StartDirectConversation as const,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: 'foo',
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const result = getComposerStep(state);
|
|
|
|
|
|
|
|
assert.strictEqual(result, ComposerStep.StartDirectConversation);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the second step of the composer', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.ChooseGroupMembers as const,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: 'foo',
|
2021-03-03 20:09:58 +00:00
|
|
|
selectedConversationIds: ['abc'],
|
|
|
|
cantAddContactIdForModal: undefined,
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
maximumGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
groupName: '',
|
|
|
|
groupAvatar: undefined,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const result = getComposerStep(state);
|
|
|
|
|
|
|
|
assert.strictEqual(result, ComposerStep.ChooseGroupMembers);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the third step of the composer', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.SetGroupMetadata as const,
|
|
|
|
selectedConversationIds: ['abc'],
|
|
|
|
cantAddContactIdForModal: undefined,
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
maximumGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
groupName: '',
|
|
|
|
groupAvatar: undefined,
|
|
|
|
isCreating: false,
|
|
|
|
hasError: false as const,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const result = getComposerStep(state);
|
|
|
|
|
|
|
|
assert.strictEqual(result, ComposerStep.SetGroupMetadata);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#hasGroupCreationError', () => {
|
|
|
|
it('returns false if not in the "set group metadata" composer step', () => {
|
|
|
|
assert.isFalse(hasGroupCreationError(getEmptyRootState()));
|
|
|
|
|
|
|
|
assert.isFalse(
|
|
|
|
hasGroupCreationError({
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.StartDirectConversation,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: '',
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
it('returns false if there is no group creation error', () => {
|
|
|
|
assert.isFalse(
|
|
|
|
hasGroupCreationError({
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.SetGroupMetadata as const,
|
|
|
|
selectedConversationIds: [],
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
maximumGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
groupName: '',
|
|
|
|
groupAvatar: undefined,
|
|
|
|
isCreating: false as const,
|
|
|
|
hasError: false as const,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true if there is a group creation error', () => {
|
2021-02-23 20:34:28 +00:00
|
|
|
assert.isTrue(
|
2021-03-03 20:09:58 +00:00
|
|
|
hasGroupCreationError({
|
2021-02-23 20:34:28 +00:00
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
2021-03-03 20:09:58 +00:00
|
|
|
step: ComposerStep.SetGroupMetadata as const,
|
|
|
|
selectedConversationIds: [],
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
maximumGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
groupName: '',
|
|
|
|
groupAvatar: undefined,
|
|
|
|
isCreating: false as const,
|
|
|
|
hasError: true as const,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#isCreatingGroup', () => {
|
|
|
|
it('returns false if not in the "set group metadata" composer step', () => {
|
|
|
|
assert.isFalse(hasGroupCreationError(getEmptyRootState()));
|
|
|
|
|
|
|
|
assert.isFalse(
|
|
|
|
isCreatingGroup({
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.StartDirectConversation,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: '',
|
2021-02-23 20:34:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2021-03-03 20:09:58 +00:00
|
|
|
|
|
|
|
it('returns false if the group is not being created', () => {
|
|
|
|
assert.isFalse(
|
|
|
|
isCreatingGroup({
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.SetGroupMetadata as const,
|
|
|
|
selectedConversationIds: [],
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
maximumGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
groupName: '',
|
|
|
|
groupAvatar: undefined,
|
|
|
|
isCreating: false as const,
|
|
|
|
hasError: true as const,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true if the group is being created', () => {
|
|
|
|
assert.isTrue(
|
|
|
|
isCreatingGroup({
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.SetGroupMetadata as const,
|
|
|
|
selectedConversationIds: [],
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
maximumGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
groupName: '',
|
|
|
|
groupAvatar: undefined,
|
|
|
|
isCreating: true as const,
|
|
|
|
hasError: false as const,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getComposeContacts', () => {
|
2021-04-20 23:16:49 +00:00
|
|
|
const getRootState = (searchTerm = ''): StateType => {
|
2021-02-23 20:34:28 +00:00
|
|
|
const rootState = getEmptyRootState();
|
|
|
|
return {
|
|
|
|
...rootState,
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'our-conversation-id': {
|
|
|
|
...getDefaultConversation('our-conversation-id'),
|
|
|
|
isMe: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
composer: {
|
2021-03-03 20:09:58 +00:00
|
|
|
step: ComposerStep.StartDirectConversation,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm,
|
2021-02-23 20:34:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
...rootState.user,
|
|
|
|
ourConversationId: 'our-conversation-id',
|
|
|
|
i18n,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-04-20 23:16:49 +00:00
|
|
|
const getRootStateWithConversations = (searchTerm = ''): StateType => {
|
|
|
|
const result = getRootState(searchTerm);
|
2021-02-23 20:34:28 +00:00
|
|
|
Object.assign(result.conversations.conversationLookup, {
|
2021-04-27 22:35:35 +00:00
|
|
|
'convo-0': {
|
|
|
|
...getDefaultConversation('convo-0'),
|
|
|
|
name: 'Me, Myself, and I',
|
|
|
|
title: 'Me, Myself, and I',
|
|
|
|
searchableTitle: 'Note to Self',
|
|
|
|
isMe: true,
|
|
|
|
},
|
2021-02-23 20:34:28 +00:00
|
|
|
'convo-1': {
|
|
|
|
...getDefaultConversation('convo-1'),
|
|
|
|
name: 'In System Contacts',
|
|
|
|
title: 'A. Sorted First',
|
|
|
|
},
|
|
|
|
'convo-2': {
|
|
|
|
...getDefaultConversation('convo-2'),
|
|
|
|
title: 'Should Be Dropped (no name, no profile sharing)',
|
|
|
|
},
|
|
|
|
'convo-3': {
|
|
|
|
...getDefaultConversation('convo-3'),
|
|
|
|
type: 'group',
|
|
|
|
title: 'Should Be Dropped (group)',
|
|
|
|
},
|
|
|
|
'convo-4': {
|
|
|
|
...getDefaultConversation('convo-4'),
|
|
|
|
isBlocked: true,
|
|
|
|
title: 'Should Be Dropped (blocked)',
|
|
|
|
},
|
|
|
|
'convo-5': {
|
|
|
|
...getDefaultConversation('convo-5'),
|
|
|
|
discoveredUnregisteredAt: new Date(1999, 3, 20).getTime(),
|
2021-03-15 23:44:43 +00:00
|
|
|
name: 'In System Contacts (and unregistered too long ago)',
|
|
|
|
title: 'B. Sorted Second',
|
2021-02-23 20:34:28 +00:00
|
|
|
},
|
|
|
|
'convo-6': {
|
|
|
|
...getDefaultConversation('convo-6'),
|
|
|
|
profileSharing: true,
|
|
|
|
title: 'C. Has Profile Sharing',
|
|
|
|
},
|
|
|
|
'convo-7': {
|
|
|
|
...getDefaultConversation('convo-7'),
|
|
|
|
discoveredUnregisteredAt: Date.now(),
|
2021-03-15 23:44:43 +00:00
|
|
|
title: 'Should Be Dropped (unregistered)',
|
2021-02-23 20:34:28 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
2021-04-27 22:35:35 +00:00
|
|
|
it('returns no results when there are no contacts', () => {
|
2021-02-23 20:34:28 +00:00
|
|
|
const state = getRootState('foo bar baz');
|
|
|
|
const result = getComposeContacts(state);
|
|
|
|
|
|
|
|
assert.isEmpty(result);
|
|
|
|
});
|
|
|
|
|
2021-04-27 22:35:35 +00:00
|
|
|
it('includes Note to Self', () => {
|
2021-04-20 23:16:49 +00:00
|
|
|
const state = getRootStateWithConversations();
|
2021-02-23 20:34:28 +00:00
|
|
|
const result = getComposeContacts(state);
|
|
|
|
|
|
|
|
const ids = result.map(contact => contact.id);
|
2021-04-27 22:35:35 +00:00
|
|
|
// convo-6 is sorted last because it doesn't have a name
|
|
|
|
assert.deepEqual(ids, ['convo-1', 'convo-5', 'convo-0', 'convo-6']);
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can search for contacts', () => {
|
2021-04-20 23:16:49 +00:00
|
|
|
const state = getRootStateWithConversations('in system');
|
2021-02-23 20:34:28 +00:00
|
|
|
const result = getComposeContacts(state);
|
|
|
|
|
|
|
|
const ids = result.map(contact => contact.id);
|
2021-03-29 22:19:59 +00:00
|
|
|
// NOTE: convo-6 matches because you can't write "Sharing" without "in"
|
|
|
|
assert.deepEqual(ids, ['convo-1', 'convo-5', 'convo-6']);
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
2021-04-27 22:35:35 +00:00
|
|
|
|
|
|
|
it('can search for note to self', () => {
|
|
|
|
const state = getRootStateWithConversations('note');
|
|
|
|
const result = getComposeContacts(state);
|
|
|
|
|
|
|
|
const ids = result.map(contact => contact.id);
|
|
|
|
assert.deepEqual(ids, ['convo-0']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns not to self when searching for your own name', () => {
|
|
|
|
const state = getRootStateWithConversations('Myself');
|
|
|
|
const result = getComposeContacts(state);
|
|
|
|
|
|
|
|
const ids = result.map(contact => contact.id);
|
|
|
|
assert.deepEqual(ids, ['convo-0']);
|
|
|
|
});
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
|
|
|
|
2021-04-20 23:16:49 +00:00
|
|
|
describe('#getComposeGroups', () => {
|
|
|
|
const getState = (searchTerm = ''): StateType => {
|
|
|
|
const rootState = getEmptyRootState();
|
|
|
|
return {
|
|
|
|
...rootState,
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'our-conversation-id': {
|
|
|
|
...getDefaultConversation('our-conversation-id'),
|
|
|
|
isMe: true,
|
|
|
|
},
|
|
|
|
'convo-1': {
|
|
|
|
...getDefaultConversation('convo-1'),
|
|
|
|
name: 'In System Contacts',
|
|
|
|
title: 'Should be dropped (contact)',
|
|
|
|
},
|
|
|
|
'convo-2': {
|
|
|
|
...getDefaultConversation('convo-2'),
|
|
|
|
title: 'Should be dropped (contact)',
|
|
|
|
},
|
|
|
|
'convo-3': {
|
|
|
|
...getDefaultConversation('convo-3'),
|
|
|
|
type: 'group',
|
|
|
|
name: 'Hello World',
|
|
|
|
title: 'Hello World',
|
|
|
|
},
|
|
|
|
'convo-4': {
|
|
|
|
...getDefaultConversation('convo-4'),
|
|
|
|
type: 'group',
|
|
|
|
isBlocked: true,
|
|
|
|
title: 'Should be dropped (blocked)',
|
|
|
|
},
|
|
|
|
'convo-5': {
|
|
|
|
...getDefaultConversation('convo-5'),
|
|
|
|
type: 'group',
|
|
|
|
title: 'Unknown Group',
|
|
|
|
},
|
|
|
|
'convo-6': {
|
|
|
|
...getDefaultConversation('convo-6'),
|
|
|
|
type: 'group',
|
|
|
|
name: 'Signal',
|
|
|
|
title: 'Signal',
|
|
|
|
},
|
|
|
|
'convo-7': {
|
|
|
|
...getDefaultConversation('convo-7'),
|
|
|
|
profileSharing: false,
|
|
|
|
type: 'group',
|
|
|
|
name: 'Signal Fake',
|
|
|
|
title: 'Signal Fake',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.StartDirectConversation,
|
|
|
|
searchTerm,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
...rootState.user,
|
|
|
|
ourConversationId: 'our-conversation-id',
|
|
|
|
i18n,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
it('can search for groups', () => {
|
|
|
|
const state = getState('hello');
|
|
|
|
const result = getComposeGroups(state);
|
|
|
|
|
|
|
|
const ids = result.map(group => group.id);
|
|
|
|
assert.deepEqual(ids, ['convo-3']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not return unknown groups when getting all groups (no search term)', () => {
|
|
|
|
const state = getState();
|
|
|
|
const result = getComposeGroups(state);
|
|
|
|
|
|
|
|
const ids = result.map(group => group.id);
|
|
|
|
assert.deepEqual(ids, ['convo-3', 'convo-6', 'convo-7']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-11 21:29:31 +00:00
|
|
|
describe('#getCandidateContactsForNewGroup', () => {
|
2021-04-20 23:16:49 +00:00
|
|
|
const getRootState = (searchTerm = ''): StateType => {
|
2021-03-03 20:09:58 +00:00
|
|
|
const rootState = getEmptyRootState();
|
|
|
|
return {
|
|
|
|
...rootState,
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'our-conversation-id': {
|
|
|
|
...getDefaultConversation('our-conversation-id'),
|
|
|
|
isMe: true,
|
|
|
|
},
|
|
|
|
'convo-1': {
|
|
|
|
...getDefaultConversation('convo-1'),
|
|
|
|
name: 'In System Contacts',
|
|
|
|
title: 'A. Sorted First',
|
|
|
|
},
|
|
|
|
'convo-2': {
|
|
|
|
...getDefaultConversation('convo-2'),
|
2021-03-11 21:29:31 +00:00
|
|
|
title: 'Should be dropped (has no name)',
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
'convo-3': {
|
|
|
|
...getDefaultConversation('convo-3'),
|
|
|
|
type: 'group',
|
|
|
|
title: 'Should Be Dropped (group)',
|
|
|
|
},
|
|
|
|
'convo-4': {
|
|
|
|
...getDefaultConversation('convo-4'),
|
|
|
|
isBlocked: true,
|
2021-03-11 21:29:31 +00:00
|
|
|
name: 'My Name',
|
2021-03-03 20:09:58 +00:00
|
|
|
title: 'Should Be Dropped (blocked)',
|
|
|
|
},
|
|
|
|
'convo-5': {
|
|
|
|
...getDefaultConversation('convo-5'),
|
|
|
|
discoveredUnregisteredAt: new Date(1999, 3, 20).getTime(),
|
2021-03-15 23:44:43 +00:00
|
|
|
name: 'In System Contacts (and unregistered too long ago)',
|
|
|
|
title: 'C. Sorted Third',
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
'convo-6': {
|
|
|
|
...getDefaultConversation('convo-6'),
|
|
|
|
discoveredUnregisteredAt: Date.now(),
|
2021-03-15 23:44:43 +00:00
|
|
|
name: 'My Name',
|
|
|
|
title: 'Should Be Dropped (unregistered)',
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.ChooseGroupMembers,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm,
|
2021-03-03 20:09:58 +00:00
|
|
|
selectedConversationIds: ['abc'],
|
|
|
|
cantAddContactIdForModal: undefined,
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
maximumGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
groupName: '',
|
|
|
|
groupAvatar: undefined,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
...rootState.user,
|
|
|
|
ourConversationId: 'our-conversation-id',
|
|
|
|
i18n,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
it('returns sorted contacts when there is no search term', () => {
|
|
|
|
const state = getRootState();
|
2021-03-11 21:29:31 +00:00
|
|
|
const result = getCandidateContactsForNewGroup(state);
|
2021-03-03 20:09:58 +00:00
|
|
|
|
|
|
|
const ids = result.map(contact => contact.id);
|
2021-03-15 23:44:43 +00:00
|
|
|
assert.deepEqual(ids, ['convo-1', 'convo-5']);
|
2021-03-03 20:09:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can search for contacts', () => {
|
|
|
|
const state = getRootState('system contacts');
|
2021-03-11 21:29:31 +00:00
|
|
|
const result = getCandidateContactsForNewGroup(state);
|
2021-03-03 20:09:58 +00:00
|
|
|
|
|
|
|
const ids = result.map(contact => contact.id);
|
2021-03-15 23:44:43 +00:00
|
|
|
assert.deepEqual(ids, ['convo-1', 'convo-5']);
|
2021-03-03 20:09:58 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getCantAddContactForModal', () => {
|
|
|
|
it('returns undefined if not in the "choose group members" composer step', () => {
|
|
|
|
assert.isUndefined(getCantAddContactForModal(getEmptyRootState()));
|
|
|
|
|
|
|
|
assert.isUndefined(
|
|
|
|
getCantAddContactForModal({
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.StartDirectConversation,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: '',
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns undefined if there's no contact marked", () => {
|
|
|
|
assert.isUndefined(
|
|
|
|
getCantAddContactForModal({
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
|
|
|
cantAddContactIdForModal: undefined,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: '',
|
2021-03-03 20:09:58 +00:00
|
|
|
groupAvatar: undefined,
|
|
|
|
groupName: '',
|
|
|
|
maximumGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
selectedConversationIds: [],
|
|
|
|
step: ComposerStep.ChooseGroupMembers as const,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the marked contact', () => {
|
|
|
|
const conversation = getDefaultConversation('abc123');
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
getCantAddContactForModal({
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: { abc123: conversation },
|
|
|
|
composer: {
|
|
|
|
cantAddContactIdForModal: 'abc123',
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: '',
|
2021-03-03 20:09:58 +00:00
|
|
|
groupAvatar: undefined,
|
|
|
|
groupName: '',
|
|
|
|
maximumGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
selectedConversationIds: [],
|
|
|
|
step: ComposerStep.ChooseGroupMembers as const,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
conversation
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-20 23:16:49 +00:00
|
|
|
describe('#getComposerConversationSearchTerm', () => {
|
2021-02-23 20:34:28 +00:00
|
|
|
it("returns the composer's contact search term", () => {
|
|
|
|
assert.strictEqual(
|
2021-04-20 23:16:49 +00:00
|
|
|
getComposerConversationSearchTerm({
|
2021-02-23 20:34:28 +00:00
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
2021-03-03 20:09:58 +00:00
|
|
|
step: ComposerStep.StartDirectConversation,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: 'foo bar',
|
2021-02-23 20:34:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
'foo bar'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
describe('#getLeftPaneList', () => {
|
|
|
|
it('sorts conversations based on timestamp then by intl-friendly title', () => {
|
2019-03-12 00:20:16 +00:00
|
|
|
const data: ConversationLookupType = {
|
2019-01-14 21:49:58 +00:00
|
|
|
id1: {
|
|
|
|
id: 'id1',
|
2020-06-26 00:08:58 +00:00
|
|
|
e164: '+18005551111',
|
2019-01-14 21:49:58 +00:00
|
|
|
activeAt: Date.now(),
|
|
|
|
name: 'No timestamp',
|
|
|
|
timestamp: 0,
|
2020-03-10 00:43:09 +00:00
|
|
|
inboxPosition: 0,
|
2019-01-14 21:49:58 +00:00
|
|
|
phoneNumber: 'notused',
|
2019-03-12 00:20:16 +00:00
|
|
|
isArchived: false,
|
2020-10-28 22:54:32 +00:00
|
|
|
markedUnread: false,
|
2019-01-14 21:49:58 +00:00
|
|
|
|
|
|
|
type: 'direct',
|
|
|
|
isMe: false,
|
|
|
|
lastUpdated: Date.now(),
|
2020-06-26 00:08:58 +00:00
|
|
|
title: 'No timestamp',
|
2019-01-14 21:49:58 +00:00
|
|
|
unreadCount: 1,
|
|
|
|
isSelected: false,
|
2019-05-31 22:42:01 +00:00
|
|
|
typingContact: {
|
|
|
|
name: 'Someone There',
|
|
|
|
color: 'blue',
|
|
|
|
phoneNumber: '+18005551111',
|
|
|
|
},
|
2020-05-27 21:37:06 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2019-01-14 21:49:58 +00:00
|
|
|
},
|
|
|
|
id2: {
|
|
|
|
id: 'id2',
|
2020-06-26 00:08:58 +00:00
|
|
|
e164: '+18005551111',
|
2019-01-14 21:49:58 +00:00
|
|
|
activeAt: Date.now(),
|
|
|
|
name: 'B',
|
|
|
|
timestamp: 20,
|
2020-03-10 00:43:09 +00:00
|
|
|
inboxPosition: 21,
|
2019-01-14 21:49:58 +00:00
|
|
|
phoneNumber: 'notused',
|
2019-03-12 00:20:16 +00:00
|
|
|
isArchived: false,
|
2020-10-28 22:54:32 +00:00
|
|
|
markedUnread: false,
|
2019-01-14 21:49:58 +00:00
|
|
|
|
|
|
|
type: 'direct',
|
|
|
|
isMe: false,
|
|
|
|
lastUpdated: Date.now(),
|
2020-06-26 00:08:58 +00:00
|
|
|
title: 'B',
|
2019-01-14 21:49:58 +00:00
|
|
|
unreadCount: 1,
|
|
|
|
isSelected: false,
|
2019-05-31 22:42:01 +00:00
|
|
|
typingContact: {
|
|
|
|
name: 'Someone There',
|
|
|
|
color: 'blue',
|
|
|
|
phoneNumber: '+18005551111',
|
|
|
|
},
|
2020-05-27 21:37:06 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2019-01-14 21:49:58 +00:00
|
|
|
},
|
|
|
|
id3: {
|
|
|
|
id: 'id3',
|
2020-06-26 00:08:58 +00:00
|
|
|
e164: '+18005551111',
|
2019-01-14 21:49:58 +00:00
|
|
|
activeAt: Date.now(),
|
|
|
|
name: 'C',
|
|
|
|
timestamp: 20,
|
2020-03-10 00:43:09 +00:00
|
|
|
inboxPosition: 22,
|
2019-01-14 21:49:58 +00:00
|
|
|
phoneNumber: 'notused',
|
2019-03-12 00:20:16 +00:00
|
|
|
isArchived: false,
|
2020-10-28 22:54:32 +00:00
|
|
|
markedUnread: false,
|
2019-01-14 21:49:58 +00:00
|
|
|
|
|
|
|
type: 'direct',
|
|
|
|
isMe: false,
|
|
|
|
lastUpdated: Date.now(),
|
2020-06-26 00:08:58 +00:00
|
|
|
title: 'C',
|
2019-01-14 21:49:58 +00:00
|
|
|
unreadCount: 1,
|
|
|
|
isSelected: false,
|
2019-05-31 22:42:01 +00:00
|
|
|
typingContact: {
|
|
|
|
name: 'Someone There',
|
|
|
|
color: 'blue',
|
|
|
|
phoneNumber: '+18005551111',
|
|
|
|
},
|
2020-05-27 21:37:06 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2019-01-14 21:49:58 +00:00
|
|
|
},
|
|
|
|
id4: {
|
|
|
|
id: 'id4',
|
2020-06-26 00:08:58 +00:00
|
|
|
e164: '+18005551111',
|
2019-01-14 21:49:58 +00:00
|
|
|
activeAt: Date.now(),
|
|
|
|
name: 'Á',
|
|
|
|
timestamp: 20,
|
2020-03-10 00:43:09 +00:00
|
|
|
inboxPosition: 20,
|
2019-01-14 21:49:58 +00:00
|
|
|
phoneNumber: 'notused',
|
2019-03-12 00:20:16 +00:00
|
|
|
isArchived: false,
|
2020-10-28 22:54:32 +00:00
|
|
|
markedUnread: false,
|
2019-01-14 21:49:58 +00:00
|
|
|
|
|
|
|
type: 'direct',
|
|
|
|
isMe: false,
|
|
|
|
lastUpdated: Date.now(),
|
2020-06-26 00:08:58 +00:00
|
|
|
title: 'A',
|
2019-01-14 21:49:58 +00:00
|
|
|
unreadCount: 1,
|
|
|
|
isSelected: false,
|
2019-05-31 22:42:01 +00:00
|
|
|
typingContact: {
|
|
|
|
name: 'Someone There',
|
|
|
|
color: 'blue',
|
|
|
|
phoneNumber: '+18005551111',
|
|
|
|
},
|
2020-05-27 21:37:06 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2019-01-14 21:49:58 +00:00
|
|
|
},
|
|
|
|
id5: {
|
|
|
|
id: 'id5',
|
2020-06-26 00:08:58 +00:00
|
|
|
e164: '+18005551111',
|
2019-01-14 21:49:58 +00:00
|
|
|
activeAt: Date.now(),
|
|
|
|
name: 'First!',
|
|
|
|
timestamp: 30,
|
2020-03-10 00:43:09 +00:00
|
|
|
inboxPosition: 30,
|
2019-01-14 21:49:58 +00:00
|
|
|
phoneNumber: 'notused',
|
2019-03-12 00:20:16 +00:00
|
|
|
isArchived: false,
|
2020-10-28 22:54:32 +00:00
|
|
|
markedUnread: false,
|
2019-01-14 21:49:58 +00:00
|
|
|
|
|
|
|
type: 'direct',
|
|
|
|
isMe: false,
|
|
|
|
lastUpdated: Date.now(),
|
2020-06-26 00:08:58 +00:00
|
|
|
title: 'First!',
|
2019-01-14 21:49:58 +00:00
|
|
|
unreadCount: 1,
|
|
|
|
isSelected: false,
|
2019-05-31 22:42:01 +00:00
|
|
|
typingContact: {
|
|
|
|
name: 'Someone There',
|
|
|
|
color: 'blue',
|
|
|
|
phoneNumber: '+18005551111',
|
|
|
|
},
|
2020-05-27 21:37:06 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2019-01-14 21:49:58 +00:00
|
|
|
},
|
|
|
|
};
|
2020-07-24 01:35:32 +00:00
|
|
|
const comparator = _getConversationComparator();
|
2019-03-12 00:20:16 +00:00
|
|
|
const { conversations } = _getLeftPaneLists(data, comparator);
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2019-03-12 00:20:16 +00:00
|
|
|
assert.strictEqual(conversations[0].name, 'First!');
|
|
|
|
assert.strictEqual(conversations[1].name, 'Á');
|
|
|
|
assert.strictEqual(conversations[2].name, 'B');
|
|
|
|
assert.strictEqual(conversations[3].name, 'C');
|
|
|
|
assert.strictEqual(conversations[4].name, 'No timestamp');
|
2019-01-14 21:49:58 +00:00
|
|
|
});
|
2020-10-10 14:25:17 +00:00
|
|
|
|
|
|
|
describe('given pinned conversations', () => {
|
|
|
|
it('sorts pinned conversations based on order in storage', () => {
|
|
|
|
const data: ConversationLookupType = {
|
|
|
|
pin2: {
|
|
|
|
id: 'pin2',
|
|
|
|
e164: '+18005551111',
|
|
|
|
activeAt: Date.now(),
|
|
|
|
name: 'Pin Two',
|
|
|
|
timestamp: 30,
|
|
|
|
inboxPosition: 30,
|
|
|
|
phoneNumber: 'notused',
|
|
|
|
isArchived: false,
|
|
|
|
isPinned: true,
|
2020-10-28 22:54:32 +00:00
|
|
|
markedUnread: false,
|
2020-10-10 14:25:17 +00:00
|
|
|
|
|
|
|
type: 'direct',
|
|
|
|
isMe: false,
|
|
|
|
lastUpdated: Date.now(),
|
|
|
|
title: 'Pin Two',
|
|
|
|
unreadCount: 1,
|
|
|
|
isSelected: false,
|
|
|
|
typingContact: {
|
|
|
|
name: 'Someone There',
|
|
|
|
color: 'blue',
|
|
|
|
phoneNumber: '+18005551111',
|
|
|
|
},
|
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
|
|
|
},
|
|
|
|
pin3: {
|
|
|
|
id: 'pin3',
|
|
|
|
e164: '+18005551111',
|
|
|
|
activeAt: Date.now(),
|
|
|
|
name: 'Pin Three',
|
|
|
|
timestamp: 30,
|
|
|
|
inboxPosition: 30,
|
|
|
|
phoneNumber: 'notused',
|
|
|
|
isArchived: false,
|
|
|
|
isPinned: true,
|
2020-10-28 22:54:32 +00:00
|
|
|
markedUnread: false,
|
2020-10-10 14:25:17 +00:00
|
|
|
|
|
|
|
type: 'direct',
|
|
|
|
isMe: false,
|
|
|
|
lastUpdated: Date.now(),
|
|
|
|
title: 'Pin Three',
|
|
|
|
unreadCount: 1,
|
|
|
|
isSelected: false,
|
|
|
|
typingContact: {
|
|
|
|
name: 'Someone There',
|
|
|
|
color: 'blue',
|
|
|
|
phoneNumber: '+18005551111',
|
|
|
|
},
|
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
|
|
|
},
|
|
|
|
pin1: {
|
|
|
|
id: 'pin1',
|
|
|
|
e164: '+18005551111',
|
|
|
|
activeAt: Date.now(),
|
|
|
|
name: 'Pin One',
|
|
|
|
timestamp: 30,
|
|
|
|
inboxPosition: 30,
|
|
|
|
phoneNumber: 'notused',
|
|
|
|
isArchived: false,
|
|
|
|
isPinned: true,
|
2020-10-28 22:54:32 +00:00
|
|
|
markedUnread: false,
|
2020-10-10 14:25:17 +00:00
|
|
|
|
|
|
|
type: 'direct',
|
|
|
|
isMe: false,
|
|
|
|
lastUpdated: Date.now(),
|
|
|
|
title: 'Pin One',
|
|
|
|
unreadCount: 1,
|
|
|
|
isSelected: false,
|
|
|
|
typingContact: {
|
|
|
|
name: 'Someone There',
|
|
|
|
color: 'blue',
|
|
|
|
phoneNumber: '+18005551111',
|
|
|
|
},
|
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-12-04 20:41:40 +00:00
|
|
|
const pinnedConversationIds = ['pin1', 'pin2', 'pin3'];
|
2020-10-10 14:25:17 +00:00
|
|
|
const comparator = _getConversationComparator();
|
2020-12-04 20:41:40 +00:00
|
|
|
const { pinnedConversations } = _getLeftPaneLists(
|
|
|
|
data,
|
|
|
|
comparator,
|
|
|
|
undefined,
|
|
|
|
pinnedConversationIds
|
|
|
|
);
|
2020-10-10 14:25:17 +00:00
|
|
|
|
|
|
|
assert.strictEqual(pinnedConversations[0].name, 'Pin One');
|
|
|
|
assert.strictEqual(pinnedConversations[1].name, 'Pin Two');
|
|
|
|
assert.strictEqual(pinnedConversations[2].name, 'Pin Three');
|
|
|
|
});
|
|
|
|
});
|
2019-01-14 21:49:58 +00:00
|
|
|
});
|
2021-02-12 21:58:14 +00:00
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
describe('#getMaximumGroupSizeModalState', () => {
|
|
|
|
it('returns the modal state', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
|
|
|
cantAddContactIdForModal: undefined,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: 'to be cleared',
|
2021-03-03 20:09:58 +00:00
|
|
|
groupAvatar: undefined,
|
|
|
|
groupName: '',
|
|
|
|
maximumGroupSizeModalState: OneTimeModalState.Showing,
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
selectedConversationIds: [],
|
|
|
|
step: ComposerStep.ChooseGroupMembers as const,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.strictEqual(
|
|
|
|
getMaximumGroupSizeModalState(state),
|
|
|
|
OneTimeModalState.Showing
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getRecommendedGroupSizeModalState', () => {
|
|
|
|
it('returns the modal state', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
|
|
|
cantAddContactIdForModal: undefined,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: 'to be cleared',
|
2021-03-03 20:09:58 +00:00
|
|
|
groupAvatar: undefined,
|
|
|
|
groupName: '',
|
|
|
|
maximumGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.Showing,
|
|
|
|
selectedConversationIds: [],
|
|
|
|
step: ComposerStep.ChooseGroupMembers as const,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.strictEqual(
|
|
|
|
getRecommendedGroupSizeModalState(state),
|
|
|
|
OneTimeModalState.Showing
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getComposeGroupAvatar', () => {
|
|
|
|
it('returns undefined if there is no group avatar', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.SetGroupMetadata as const,
|
|
|
|
selectedConversationIds: ['abc'],
|
|
|
|
cantAddContactIdForModal: undefined,
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
maximumGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
groupName: '',
|
|
|
|
groupAvatar: undefined,
|
|
|
|
isCreating: false,
|
|
|
|
hasError: false as const,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.isUndefined(getComposeGroupAvatar(state));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the group avatar', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.SetGroupMetadata as const,
|
|
|
|
selectedConversationIds: ['abc'],
|
|
|
|
cantAddContactIdForModal: undefined,
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
maximumGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
groupName: '',
|
|
|
|
groupAvatar: new Uint8Array([1, 2, 3]).buffer,
|
|
|
|
isCreating: false,
|
|
|
|
hasError: false as const,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.deepEqual(
|
|
|
|
getComposeGroupAvatar(state),
|
|
|
|
new Uint8Array([1, 2, 3]).buffer
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getComposeGroupName', () => {
|
|
|
|
it('returns the group name', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.SetGroupMetadata as const,
|
|
|
|
selectedConversationIds: ['abc'],
|
|
|
|
cantAddContactIdForModal: undefined,
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
maximumGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
groupName: 'foo bar',
|
|
|
|
groupAvatar: undefined,
|
|
|
|
isCreating: false,
|
|
|
|
hasError: false as const,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.deepEqual(getComposeGroupName(state), 'foo bar');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getComposeSelectedContacts', () => {
|
|
|
|
it("returns the composer's selected contacts", () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'convo-1': {
|
|
|
|
...getDefaultConversation('convo-1'),
|
|
|
|
title: 'Person One',
|
|
|
|
},
|
|
|
|
'convo-2': {
|
|
|
|
...getDefaultConversation('convo-2'),
|
|
|
|
title: 'Person Two',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.SetGroupMetadata as const,
|
|
|
|
selectedConversationIds: ['convo-2', 'convo-1'],
|
|
|
|
cantAddContactIdForModal: undefined,
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
maximumGroupSizeModalState: OneTimeModalState.NeverShown,
|
|
|
|
groupName: 'foo bar',
|
|
|
|
groupAvatar: undefined,
|
|
|
|
isCreating: false,
|
|
|
|
hasError: false as const,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const titles = getComposeSelectedContacts(state).map(
|
|
|
|
contact => contact.title
|
|
|
|
);
|
|
|
|
assert.deepEqual(titles, ['Person Two', 'Person One']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-12 21:58:14 +00:00
|
|
|
describe('#getSelectedConversationId', () => {
|
|
|
|
it('returns undefined if no conversation is selected', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
abc123: getDefaultConversation('abc123'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.isUndefined(getSelectedConversationId(state));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the selected conversation ID', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
abc123: getDefaultConversation('abc123'),
|
|
|
|
},
|
|
|
|
selectedConversationId: 'abc123',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.strictEqual(getSelectedConversationId(state), 'abc123');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getSelectedConversation', () => {
|
|
|
|
it('returns undefined if no conversation is selected', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
abc123: getDefaultConversation('abc123'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.isUndefined(getSelectedConversation(state));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the selected conversation ID', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
abc123: getDefaultConversation('abc123'),
|
|
|
|
},
|
|
|
|
selectedConversationId: 'abc123',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.deepEqual(
|
|
|
|
getSelectedConversation(state),
|
|
|
|
getDefaultConversation('abc123')
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2019-01-14 21:49:58 +00:00
|
|
|
});
|