2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2019 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';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { v4 as generateUuid } from 'uuid';
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2021-01-06 15:41:43 +00:00
|
|
|
import {
|
2021-03-03 20:09:58 +00:00
|
|
|
ComposerStep,
|
2022-02-16 18:36:21 +00:00
|
|
|
ConversationVerificationState,
|
|
|
|
OneTimeModalState,
|
2021-11-01 19:13:35 +00:00
|
|
|
} from '../../../state/ducks/conversationsEnums';
|
|
|
|
import type {
|
|
|
|
ConversationLookupType,
|
|
|
|
ConversationType,
|
2021-01-06 15:41:43 +00:00
|
|
|
} from '../../../state/ducks/conversations';
|
2021-11-01 19:13:35 +00:00
|
|
|
import { 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-04-28 20:44:48 +00:00
|
|
|
getAllComposableConversations,
|
2021-03-11 21:29:31 +00:00
|
|
|
getCandidateContactsForNewGroup,
|
2021-05-04 16:17:32 +00:00
|
|
|
getComposableContacts,
|
|
|
|
getComposableGroups,
|
2021-03-03 20:09:58 +00:00
|
|
|
getComposeGroupAvatar,
|
|
|
|
getComposeGroupName,
|
2021-04-20 23:16:49 +00:00
|
|
|
getComposerConversationSearchTerm,
|
2021-03-03 20:09:58 +00:00
|
|
|
getComposerStep,
|
2021-05-04 16:17:32 +00:00
|
|
|
getComposeSelectedContacts,
|
2021-05-28 16:15:17 +00:00
|
|
|
getContactNameColorSelector,
|
2021-04-29 18:32:38 +00:00
|
|
|
getConversationByIdSelector,
|
2023-08-10 16:43:33 +00:00
|
|
|
getConversationServiceIdsStoppingSend,
|
2024-02-06 02:13:13 +00:00
|
|
|
getSafeConversationWithSameTitle,
|
2021-05-04 16:17:32 +00:00
|
|
|
getConversationSelector,
|
2022-02-16 18:36:21 +00:00
|
|
|
getConversationsStoppingSend,
|
2021-05-04 16:17:32 +00:00
|
|
|
getFilteredCandidateContactsForNewGroup,
|
|
|
|
getFilteredComposeContacts,
|
|
|
|
getFilteredComposeGroups,
|
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
|
|
|
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';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { StateType } from '../../../state/reducer';
|
|
|
|
import { reducer as rootReducer } from '../../../state/reducer';
|
2021-09-18 00:30:08 +00:00
|
|
|
import { setupI18n } from '../../../util/setupI18n';
|
2023-08-10 16:43:33 +00:00
|
|
|
import type { ServiceIdString } from '../../../types/ServiceId';
|
|
|
|
import { generateAci, getAciFromPrefix } from '../../../types/ServiceId';
|
2021-02-23 20:34:28 +00:00
|
|
|
import enMessages from '../../../../_locales/en/messages.json';
|
2021-10-26 22:59:08 +00:00
|
|
|
import {
|
|
|
|
getDefaultConversation,
|
2022-11-19 08:31:18 +00:00
|
|
|
getDefaultGroup,
|
2023-08-16 20:54:39 +00:00
|
|
|
getDefaultConversationWithServiceId,
|
2021-10-26 22:59:08 +00:00
|
|
|
} from '../../helpers/getDefaultConversation';
|
2021-08-16 14:33:27 +00:00
|
|
|
import {
|
|
|
|
defaultStartDirectConversationComposerState,
|
|
|
|
defaultChooseGroupMembersComposerState,
|
|
|
|
defaultSetGroupMetadataComposerState,
|
|
|
|
} from '../../helpers/defaultComposerStates';
|
2021-08-06 00:17:05 +00:00
|
|
|
|
2022-11-11 04:10:30 +00:00
|
|
|
describe('both/state/selectors/conversations-extra', () => {
|
2023-08-10 16:43:33 +00:00
|
|
|
const SERVICE_ID_1 = generateAci();
|
|
|
|
const SERVICE_ID_2 = generateAci();
|
2022-11-11 04:10:30 +00:00
|
|
|
|
2021-01-06 15:41:43 +00:00
|
|
|
const getEmptyRootState = (): StateType => {
|
|
|
|
return rootReducer(undefined, noopAction());
|
|
|
|
};
|
|
|
|
|
2021-05-07 22:21:10 +00:00
|
|
|
function makeConversation(id: string): ConversationType {
|
2022-09-26 20:18:11 +00:00
|
|
|
const title = `${id} title`;
|
2021-05-07 22:21:10 +00:00
|
|
|
return getDefaultConversation({
|
2021-01-06 15:41:43 +00:00
|
|
|
id,
|
2022-09-26 20:18:11 +00:00
|
|
|
searchableTitle: title,
|
|
|
|
title,
|
|
|
|
titleNoDefault: title,
|
2021-05-07 22:21:10 +00:00
|
|
|
});
|
2021-01-06 15:41:43 +00:00
|
|
|
}
|
|
|
|
|
2022-11-19 08:31:18 +00:00
|
|
|
function makeGroup(id: string): ConversationType {
|
|
|
|
const title = `${id} title`;
|
|
|
|
return getDefaultGroup({
|
|
|
|
id,
|
|
|
|
searchableTitle: title,
|
|
|
|
title,
|
|
|
|
titleNoDefault: title,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
function makeConversationWithServiceId(
|
2021-10-26 22:59:08 +00:00
|
|
|
id: string
|
2023-08-16 20:54:39 +00:00
|
|
|
): ConversationType & { serviceId: ServiceIdString } {
|
2022-09-26 20:18:11 +00:00
|
|
|
const title = `${id} title`;
|
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
return getDefaultConversationWithServiceId(
|
2021-10-26 22:59:08 +00:00
|
|
|
{
|
|
|
|
id,
|
2022-09-26 20:18:11 +00:00
|
|
|
searchableTitle: title,
|
|
|
|
title,
|
|
|
|
titleNoDefault: title,
|
2021-10-26 22:59:08 +00:00
|
|
|
},
|
2023-08-10 16:43:33 +00:00
|
|
|
getAciFromPrefix(id)
|
2021-10-26 22:59:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
2021-04-29 18:32:38 +00:00
|
|
|
describe('#getConversationByIdSelector', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
2021-05-07 22:21:10 +00:00
|
|
|
conversationLookup: { abc123: makeConversation('abc123') },
|
2021-04-29 18:32:38 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
it('returns undefined if the conversation is not in the lookup', () => {
|
|
|
|
const selector = getConversationByIdSelector(state);
|
|
|
|
const actual = selector('xyz');
|
|
|
|
assert.isUndefined(actual);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the conversation in the lookup if it exists', () => {
|
|
|
|
const selector = getConversationByIdSelector(state);
|
|
|
|
const actual = selector('abc123');
|
|
|
|
assert.strictEqual(actual?.title, 'abc123 title');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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());
|
|
|
|
});
|
|
|
|
|
2024-06-06 00:19:48 +00:00
|
|
|
it('returns conversation by uuid', () => {
|
2021-01-06 15:41:43 +00:00
|
|
|
const id = 'id';
|
|
|
|
|
2021-05-07 22:21:10 +00:00
|
|
|
const conversation = makeConversation(id);
|
|
|
|
const wrongConversation = makeConversation('wrong');
|
2021-01-06 15:41:43 +00:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
[id]: wrongConversation,
|
|
|
|
},
|
|
|
|
conversationsByE164: {
|
2021-07-14 00:46:02 +00:00
|
|
|
[id]: wrongConversation,
|
2021-01-06 15:41:43 +00:00
|
|
|
},
|
2023-08-16 20:54:39 +00:00
|
|
|
conversationsByServiceId: {
|
2021-07-14 00:46:02 +00:00
|
|
|
[id]: conversation,
|
2021-01-06 15:41:43 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const selector = getConversationSelector(state);
|
|
|
|
|
|
|
|
const actual = selector(id);
|
|
|
|
|
|
|
|
assert.strictEqual(actual, conversation);
|
|
|
|
});
|
2021-07-14 00:46:02 +00:00
|
|
|
it('returns conversation by e164', () => {
|
2021-01-06 15:41:43 +00:00
|
|
|
const id = 'id';
|
|
|
|
|
2021-05-07 22:21:10 +00:00
|
|
|
const conversation = makeConversation(id);
|
|
|
|
const wrongConversation = makeConversation('wrong');
|
2021-01-06 15:41:43 +00:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
[id]: wrongConversation,
|
|
|
|
},
|
2021-07-14 00:46:02 +00:00
|
|
|
conversationsByE164: {
|
2021-01-06 15:41:43 +00:00
|
|
|
[id]: conversation,
|
|
|
|
},
|
2024-06-06 00:19:48 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const selector = getConversationSelector(state);
|
|
|
|
|
|
|
|
const actual = selector(id);
|
|
|
|
|
|
|
|
assert.strictEqual(actual, conversation);
|
|
|
|
});
|
|
|
|
it('returns conversation by groupId', () => {
|
|
|
|
const id = 'id';
|
|
|
|
|
|
|
|
const conversation = makeConversation(id);
|
|
|
|
const wrongConversation = makeConversation('wrong');
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
2021-01-06 15:41:43 +00:00
|
|
|
[id]: wrongConversation,
|
|
|
|
},
|
2024-06-06 00:19:48 +00:00
|
|
|
conversationsByGroupId: {
|
|
|
|
[id]: conversation,
|
|
|
|
},
|
2021-01-06 15:41:43 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const selector = getConversationSelector(state);
|
|
|
|
|
|
|
|
const actual = selector(id);
|
|
|
|
|
|
|
|
assert.strictEqual(actual, conversation);
|
|
|
|
});
|
2024-06-06 00:19:48 +00:00
|
|
|
it('returns conversation by groupId first', () => {
|
2021-01-06 15:41:43 +00:00
|
|
|
const id = 'id';
|
|
|
|
|
2021-05-07 22:21:10 +00:00
|
|
|
const conversation = makeConversation(id);
|
|
|
|
const wrongConversation = makeConversation('wrong');
|
2021-01-06 15:41:43 +00:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
[id]: wrongConversation,
|
|
|
|
},
|
|
|
|
conversationsByGroupId: {
|
|
|
|
[id]: conversation,
|
|
|
|
},
|
2024-06-06 00:19:48 +00:00
|
|
|
conversationsByE164: {
|
|
|
|
[id]: wrongConversation,
|
|
|
|
},
|
|
|
|
conversationsByServiceId: {
|
|
|
|
[id]: wrongConversation,
|
|
|
|
},
|
2021-01-06 15:41:43 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const selector = getConversationSelector(state);
|
|
|
|
|
|
|
|
const actual = selector(id);
|
|
|
|
|
|
|
|
assert.strictEqual(actual, conversation);
|
|
|
|
});
|
|
|
|
it('returns conversation by conversationId', () => {
|
|
|
|
const id = 'id';
|
|
|
|
|
2021-05-07 22:21:10 +00:00
|
|
|
const conversation = makeConversation(id);
|
2021-01-06 15:41:43 +00:00
|
|
|
|
|
|
|
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';
|
|
|
|
|
2021-05-07 22:21:10 +00:00
|
|
|
const conversation = makeConversation(id);
|
2021-01-06 15:41:43 +00:00
|
|
|
|
|
|
|
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: {
|
2021-05-07 22:21:10 +00:00
|
|
|
[id]: makeConversation('third'),
|
2021-01-06 15:41:43 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const thirdSelector = getConversationSelector(thirdState);
|
|
|
|
const thirdActual = thirdSelector(id);
|
|
|
|
|
|
|
|
assert.notStrictEqual(actual, thirdActual);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-02-16 18:36:21 +00:00
|
|
|
describe('#getConversationsStoppingSend', () => {
|
2021-08-31 20:58:39 +00:00
|
|
|
it('returns an empty array if there are no conversations stopping send', () => {
|
|
|
|
const state = getEmptyRootState();
|
|
|
|
|
2022-02-16 18:36:21 +00:00
|
|
|
assert.isEmpty(getConversationsStoppingSend(state));
|
2021-08-31 20:58:39 +00:00
|
|
|
});
|
|
|
|
|
2022-02-16 18:36:21 +00:00
|
|
|
it('returns all conversations stopping send', () => {
|
2023-08-10 16:43:33 +00:00
|
|
|
const convo1 = makeConversation(SERVICE_ID_1);
|
|
|
|
const convo2 = makeConversation(SERVICE_ID_2);
|
2022-02-16 18:36:21 +00:00
|
|
|
const state: StateType = {
|
2021-08-31 20:58:39 +00:00
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
2023-08-10 16:43:33 +00:00
|
|
|
[SERVICE_ID_1]: convo1,
|
|
|
|
[SERVICE_ID_2]: convo2,
|
2021-08-31 20:58:39 +00:00
|
|
|
},
|
2022-02-16 18:36:21 +00:00
|
|
|
verificationDataByConversation: {
|
|
|
|
'convo a': {
|
|
|
|
type: ConversationVerificationState.PendingVerification as const,
|
2023-08-10 16:43:33 +00:00
|
|
|
serviceIdsNeedingVerification: [SERVICE_ID_1],
|
2022-02-16 18:36:21 +00:00
|
|
|
},
|
|
|
|
'convo b': {
|
|
|
|
type: ConversationVerificationState.PendingVerification as const,
|
2023-08-10 16:43:33 +00:00
|
|
|
serviceIdsNeedingVerification: [SERVICE_ID_2, SERVICE_ID_1],
|
2022-02-16 18:36:21 +00:00
|
|
|
},
|
2021-08-31 20:58:39 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
assert.sameDeepMembers(getConversationServiceIdsStoppingSend(state), [
|
|
|
|
SERVICE_ID_1,
|
|
|
|
SERVICE_ID_2,
|
2022-02-16 18:36:21 +00:00
|
|
|
]);
|
2021-08-31 20:58:39 +00:00
|
|
|
|
2022-02-16 18:36:21 +00:00
|
|
|
assert.sameDeepMembers(getConversationsStoppingSend(state), [
|
|
|
|
convo1,
|
|
|
|
convo2,
|
|
|
|
]);
|
2021-08-31 20:58:39 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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', () => {
|
2023-08-16 20:54:39 +00:00
|
|
|
const abc = makeConversationWithServiceId('abc');
|
|
|
|
const def = makeConversationWithServiceId('def');
|
2021-03-03 20:09:58 +00:00
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
2023-08-16 20:54:39 +00:00
|
|
|
conversationsByServiceId: {
|
|
|
|
[abc.serviceId]: abc,
|
|
|
|
[def.serviceId]: def,
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
2023-08-16 20:54:39 +00:00
|
|
|
invitedServiceIdsForNewlyCreatedGroup: [def.serviceId, abc.serviceId],
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
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(),
|
2021-08-16 14:33:27 +00:00
|
|
|
composer: defaultStartDirectConversationComposerState,
|
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(),
|
2021-08-16 14:33:27 +00:00
|
|
|
composer: defaultChooseGroupMembersComposerState,
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
const result = getComposerStep(state);
|
|
|
|
|
|
|
|
assert.strictEqual(result, ComposerStep.ChooseGroupMembers);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the third step of the composer', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
2021-08-16 14:33:27 +00:00
|
|
|
composer: defaultSetGroupMetadataComposerState,
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
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(),
|
2021-08-16 14:33:27 +00:00
|
|
|
composer: defaultStartDirectConversationComposerState,
|
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(),
|
2021-08-16 14:33:27 +00:00
|
|
|
composer: defaultSetGroupMetadataComposerState,
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
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-08-16 14:33:27 +00:00
|
|
|
...defaultSetGroupMetadataComposerState,
|
|
|
|
hasError: true,
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#isCreatingGroup', () => {
|
|
|
|
it('returns false if not in the "set group metadata" composer step', () => {
|
|
|
|
assert.isFalse(hasGroupCreationError(getEmptyRootState()));
|
|
|
|
|
|
|
|
assert.isFalse(
|
|
|
|
isCreatingGroup({
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
2021-08-16 14:33:27 +00:00
|
|
|
composer: defaultStartDirectConversationComposerState,
|
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(),
|
2021-08-16 14:33:27 +00:00
|
|
|
composer: defaultSetGroupMetadataComposerState,
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true if the group is being created', () => {
|
|
|
|
assert.isTrue(
|
|
|
|
isCreatingGroup({
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
2021-08-16 14:33:27 +00:00
|
|
|
...defaultSetGroupMetadataComposerState,
|
|
|
|
isCreating: true,
|
|
|
|
hasError: false,
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
|
|
|
|
2021-04-28 20:44:48 +00:00
|
|
|
describe('#getAllComposableConversations', () => {
|
|
|
|
const getRootState = (): StateType => {
|
|
|
|
const rootState = getEmptyRootState();
|
|
|
|
return {
|
|
|
|
...rootState,
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'our-conversation-id': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('our-conversation-id'),
|
2021-04-28 20:44:48 +00:00
|
|
|
isMe: true,
|
2021-05-04 16:17:32 +00:00
|
|
|
profileName: 'My own name',
|
2021-04-28 20:44:48 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
...rootState.user,
|
|
|
|
ourConversationId: 'our-conversation-id',
|
|
|
|
i18n,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const getRootStateWithConversations = (): StateType => {
|
|
|
|
const result = getRootState();
|
|
|
|
Object.assign(result.conversations.conversationLookup, {
|
|
|
|
'convo-1': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-1'),
|
2021-05-04 16:17:32 +00:00
|
|
|
type: 'direct',
|
|
|
|
profileName: 'A',
|
2021-04-28 20:44:48 +00:00
|
|
|
title: 'A',
|
|
|
|
},
|
|
|
|
'convo-2': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-2'),
|
2021-04-28 20:44:48 +00:00
|
|
|
isGroupV1AndDisabled: true,
|
2021-05-04 16:17:32 +00:00
|
|
|
name: '2',
|
2021-04-28 20:44:48 +00:00
|
|
|
title: 'Should Be Dropped (GV1)',
|
|
|
|
},
|
|
|
|
'convo-3': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-3'),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'B',
|
2021-04-28 20:44:48 +00:00
|
|
|
title: 'B',
|
|
|
|
},
|
|
|
|
'convo-4': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-4'),
|
2021-04-28 20:44:48 +00:00
|
|
|
isBlocked: true,
|
2021-05-04 16:17:32 +00:00
|
|
|
name: '4',
|
2021-04-28 20:44:48 +00:00
|
|
|
title: 'Should Be Dropped (blocked)',
|
|
|
|
},
|
|
|
|
'convo-5': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-5'),
|
2021-04-28 20:44:48 +00:00
|
|
|
discoveredUnregisteredAt: new Date(1999, 3, 20).getTime(),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'C',
|
2021-04-28 20:44:48 +00:00
|
|
|
title: 'C',
|
|
|
|
},
|
|
|
|
'convo-6': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-6'),
|
2021-04-28 20:44:48 +00:00
|
|
|
profileSharing: true,
|
2022-02-09 20:33:19 +00:00
|
|
|
name: 'Should Be Dropped (no title)',
|
2022-09-26 20:18:11 +00:00
|
|
|
title: 'Unknown group',
|
|
|
|
titleNoDefault: undefined,
|
2021-04-28 20:44:48 +00:00
|
|
|
},
|
|
|
|
'convo-7': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-7'),
|
2021-04-28 20:44:48 +00:00
|
|
|
discoveredUnregisteredAt: Date.now(),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: '7',
|
2021-04-28 20:44:48 +00:00
|
|
|
title: 'Should Be Dropped (unregistered)',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
it('returns no gv1, no blocked, no missing titles', () => {
|
|
|
|
const state = getRootStateWithConversations();
|
|
|
|
const result = getAllComposableConversations(state);
|
|
|
|
|
|
|
|
const ids = result.map(contact => contact.id);
|
|
|
|
assert.deepEqual(ids, [
|
|
|
|
'our-conversation-id',
|
|
|
|
'convo-1',
|
|
|
|
'convo-3',
|
|
|
|
'convo-5',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-04 16:17:32 +00:00
|
|
|
describe('#getComposableContacts', () => {
|
|
|
|
const getRootState = (): StateType => {
|
|
|
|
const rootState = getEmptyRootState();
|
|
|
|
return {
|
|
|
|
...rootState,
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'our-conversation-id': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('our-conversation-id'),
|
2021-05-04 16:17:32 +00:00
|
|
|
isMe: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
...rootState.user,
|
|
|
|
ourConversationId: 'our-conversation-id',
|
|
|
|
i18n,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
it('returns only direct contacts, including me', () => {
|
|
|
|
const state = {
|
|
|
|
...getRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'convo-0': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-0'),
|
2021-05-04 16:17:32 +00:00
|
|
|
isMe: true,
|
|
|
|
profileSharing: false,
|
|
|
|
},
|
|
|
|
'convo-1': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-1'),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'Friends!',
|
|
|
|
},
|
|
|
|
'convo-2': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-2'),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'Alice',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const result = getComposableContacts(state);
|
|
|
|
|
|
|
|
const ids = result.map(group => group.id);
|
|
|
|
assert.deepEqual(ids, ['convo-0', 'convo-2']);
|
|
|
|
});
|
|
|
|
it('excludes blocked, unregistered, and missing name/profileSharing', () => {
|
|
|
|
const state = {
|
|
|
|
...getRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'convo-0': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-0'),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'Ex',
|
|
|
|
isBlocked: true,
|
|
|
|
},
|
|
|
|
'convo-1': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-1'),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'Bob',
|
|
|
|
discoveredUnregisteredAt: Date.now(),
|
|
|
|
},
|
|
|
|
'convo-2': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-2'),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'Charlie',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const result = getComposableContacts(state);
|
|
|
|
|
|
|
|
const ids = result.map(group => group.id);
|
|
|
|
assert.deepEqual(ids, ['convo-2']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getCandidateContactsForNewGroup', () => {
|
|
|
|
const getRootState = (): StateType => {
|
|
|
|
const rootState = getEmptyRootState();
|
|
|
|
return {
|
|
|
|
...rootState,
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'our-conversation-id': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('our-conversation-id'),
|
2021-05-04 16:17:32 +00:00
|
|
|
isMe: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
...rootState.user,
|
|
|
|
ourConversationId: 'our-conversation-id',
|
|
|
|
i18n,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
it('returns only direct contacts, without me', () => {
|
|
|
|
const state = {
|
|
|
|
...getRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'convo-0': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-0'),
|
2021-05-04 16:17:32 +00:00
|
|
|
isMe: true,
|
|
|
|
name: 'Me!',
|
|
|
|
},
|
|
|
|
'convo-1': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-1'),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'Friends!',
|
|
|
|
},
|
|
|
|
'convo-2': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-2'),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'Alice',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const result = getCandidateContactsForNewGroup(state);
|
|
|
|
|
|
|
|
const ids = result.map(group => group.id);
|
|
|
|
assert.deepEqual(ids, ['convo-2']);
|
|
|
|
});
|
|
|
|
it('excludes blocked, unregistered, and missing name/profileSharing', () => {
|
|
|
|
const state = {
|
|
|
|
...getRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'convo-0': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-0'),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'Ex',
|
|
|
|
isBlocked: true,
|
|
|
|
},
|
|
|
|
'convo-1': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-1'),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'Bob',
|
|
|
|
discoveredUnregisteredAt: Date.now(),
|
|
|
|
},
|
|
|
|
'convo-2': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-2'),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'Charlie',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const result = getCandidateContactsForNewGroup(state);
|
|
|
|
|
|
|
|
const ids = result.map(group => group.id);
|
|
|
|
assert.deepEqual(ids, ['convo-2']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getComposableGroups', () => {
|
|
|
|
const getRootState = (): StateType => {
|
|
|
|
const rootState = getEmptyRootState();
|
|
|
|
return {
|
|
|
|
...rootState,
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'our-conversation-id': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('our-conversation-id'),
|
2021-05-04 16:17:32 +00:00
|
|
|
isMe: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
...rootState.user,
|
|
|
|
ourConversationId: 'our-conversation-id',
|
|
|
|
i18n,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
it('returns only groups with name', () => {
|
|
|
|
const state = {
|
|
|
|
...getRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'convo-0': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-0'),
|
2021-05-04 16:17:32 +00:00
|
|
|
isMe: true,
|
|
|
|
name: 'Me!',
|
|
|
|
},
|
|
|
|
'convo-1': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-1'),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'Friends!',
|
|
|
|
},
|
|
|
|
'convo-2': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-2'),
|
2021-05-04 16:17:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const result = getComposableGroups(state);
|
|
|
|
|
|
|
|
const ids = result.map(group => group.id);
|
|
|
|
assert.deepEqual(ids, ['convo-1']);
|
|
|
|
});
|
|
|
|
it('excludes blocked, and missing name/profileSharing', () => {
|
|
|
|
const state = {
|
|
|
|
...getRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'convo-0': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-0'),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'Family!',
|
|
|
|
isBlocked: true,
|
|
|
|
},
|
|
|
|
'convo-1': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-1'),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'Friends!',
|
|
|
|
},
|
|
|
|
'convo-2': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-2'),
|
2021-05-04 16:17:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const result = getComposableGroups(state);
|
|
|
|
|
|
|
|
const ids = result.map(group => group.id);
|
|
|
|
assert.deepEqual(ids, ['convo-1']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getFilteredComposeContacts', () => {
|
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': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('our-conversation-id'),
|
2021-05-04 16:17:32 +00:00
|
|
|
name: 'Me, Myself, and I',
|
|
|
|
title: 'Me, Myself, and I',
|
|
|
|
searchableTitle: 'Note to Self',
|
2021-02-23 20:34:28 +00:00
|
|
|
isMe: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
composer: {
|
2021-08-16 14:33:27 +00:00
|
|
|
...defaultStartDirectConversationComposerState,
|
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, {
|
|
|
|
'convo-1': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-1'),
|
2021-02-23 20:34:28 +00:00
|
|
|
name: 'In System Contacts',
|
|
|
|
title: 'A. Sorted First',
|
|
|
|
},
|
|
|
|
'convo-2': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-2'),
|
2021-02-23 20:34:28 +00:00
|
|
|
title: 'Should Be Dropped (no name, no profile sharing)',
|
|
|
|
},
|
|
|
|
'convo-3': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-3'),
|
2021-02-23 20:34:28 +00:00
|
|
|
title: 'Should Be Dropped (group)',
|
|
|
|
},
|
|
|
|
'convo-4': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-4'),
|
2021-02-23 20:34:28 +00:00
|
|
|
isBlocked: true,
|
|
|
|
title: 'Should Be Dropped (blocked)',
|
|
|
|
},
|
|
|
|
'convo-5': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-5'),
|
2021-02-23 20:34:28 +00:00
|
|
|
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': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-6'),
|
2021-02-23 20:34:28 +00:00
|
|
|
profileSharing: true,
|
2021-05-04 16:17:32 +00:00
|
|
|
profileName: 'C. Has Profile Sharing',
|
2021-02-23 20:34:28 +00:00
|
|
|
title: 'C. Has Profile Sharing',
|
|
|
|
},
|
|
|
|
'convo-7': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-7'),
|
2021-02-23 20:34:28 +00:00
|
|
|
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');
|
2021-05-04 16:17:32 +00:00
|
|
|
const result = getFilteredComposeContacts(state);
|
2021-02-23 20:34:28 +00:00
|
|
|
|
|
|
|
assert.isEmpty(result);
|
|
|
|
});
|
|
|
|
|
2021-05-04 16:17:32 +00:00
|
|
|
it('includes Note to Self with no search term', () => {
|
2021-04-20 23:16:49 +00:00
|
|
|
const state = getRootStateWithConversations();
|
2021-05-04 16:17:32 +00:00
|
|
|
const result = getFilteredComposeContacts(state);
|
2021-02-23 20:34:28 +00:00
|
|
|
|
|
|
|
const ids = result.map(contact => contact.id);
|
2021-05-04 16:17:32 +00:00
|
|
|
assert.deepEqual(ids, [
|
|
|
|
'convo-1',
|
|
|
|
'convo-5',
|
|
|
|
'convo-6',
|
2023-06-21 16:33:59 +00:00
|
|
|
'our-conversation-id',
|
2021-05-04 16:17:32 +00:00
|
|
|
]);
|
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-05-04 16:17:32 +00:00
|
|
|
const result = getFilteredComposeContacts(state);
|
2021-02-23 20:34:28 +00:00
|
|
|
|
|
|
|
const ids = result.map(contact => contact.id);
|
2022-04-05 00:38:22 +00:00
|
|
|
assert.deepEqual(ids, ['convo-1', 'convo-5']);
|
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');
|
2021-05-04 16:17:32 +00:00
|
|
|
const result = getFilteredComposeContacts(state);
|
2021-04-27 22:35:35 +00:00
|
|
|
|
|
|
|
const ids = result.map(contact => contact.id);
|
2021-05-04 16:17:32 +00:00
|
|
|
assert.deepEqual(ids, ['our-conversation-id']);
|
2021-04-27 22:35:35 +00:00
|
|
|
});
|
|
|
|
|
2021-04-28 20:44:48 +00:00
|
|
|
it('returns note to self when searching for your own name', () => {
|
2021-04-27 22:35:35 +00:00
|
|
|
const state = getRootStateWithConversations('Myself');
|
2021-05-04 16:17:32 +00:00
|
|
|
const result = getFilteredComposeContacts(state);
|
2021-04-27 22:35:35 +00:00
|
|
|
|
|
|
|
const ids = result.map(contact => contact.id);
|
2021-05-04 16:17:32 +00:00
|
|
|
assert.deepEqual(ids, ['our-conversation-id']);
|
2021-04-27 22:35:35 +00:00
|
|
|
});
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
|
|
|
|
2021-05-04 16:17:32 +00:00
|
|
|
describe('#getFilteredComposeGroups', () => {
|
2021-04-20 23:16:49 +00:00
|
|
|
const getState = (searchTerm = ''): StateType => {
|
|
|
|
const rootState = getEmptyRootState();
|
|
|
|
return {
|
|
|
|
...rootState,
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'our-conversation-id': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('our-conversation-id'),
|
2021-04-20 23:16:49 +00:00
|
|
|
isMe: true,
|
|
|
|
},
|
|
|
|
'convo-1': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-1'),
|
2021-04-20 23:16:49 +00:00
|
|
|
name: 'In System Contacts',
|
|
|
|
title: 'Should be dropped (contact)',
|
|
|
|
},
|
|
|
|
'convo-2': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-2'),
|
2021-04-20 23:16:49 +00:00
|
|
|
title: 'Should be dropped (contact)',
|
|
|
|
},
|
|
|
|
'convo-3': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-3'),
|
2021-04-20 23:16:49 +00:00
|
|
|
name: 'Hello World',
|
|
|
|
title: 'Hello World',
|
|
|
|
},
|
|
|
|
'convo-4': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-4'),
|
2021-04-20 23:16:49 +00:00
|
|
|
isBlocked: true,
|
|
|
|
title: 'Should be dropped (blocked)',
|
|
|
|
},
|
|
|
|
'convo-5': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-5'),
|
2021-04-20 23:16:49 +00:00
|
|
|
title: 'Unknown Group',
|
|
|
|
},
|
|
|
|
'convo-6': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-6'),
|
2021-04-20 23:16:49 +00:00
|
|
|
name: 'Signal',
|
|
|
|
title: 'Signal',
|
|
|
|
},
|
|
|
|
'convo-7': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-7'),
|
2021-04-20 23:16:49 +00:00
|
|
|
profileSharing: false,
|
|
|
|
name: 'Signal Fake',
|
|
|
|
title: 'Signal Fake',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
composer: {
|
2021-08-16 14:33:27 +00:00
|
|
|
...defaultStartDirectConversationComposerState,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
...rootState.user,
|
|
|
|
ourConversationId: 'our-conversation-id',
|
|
|
|
i18n,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
it('can search for groups', () => {
|
|
|
|
const state = getState('hello');
|
2021-05-04 16:17:32 +00:00
|
|
|
const result = getFilteredComposeGroups(state);
|
2021-04-20 23:16:49 +00:00
|
|
|
|
|
|
|
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();
|
2021-05-04 16:17:32 +00:00
|
|
|
const result = getFilteredComposeGroups(state);
|
2021-04-20 23:16:49 +00:00
|
|
|
|
|
|
|
const ids = result.map(group => group.id);
|
|
|
|
assert.deepEqual(ids, ['convo-3', 'convo-6', 'convo-7']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-04 16:17:32 +00:00
|
|
|
describe('#getFilteredCandidateContactsForNewGroup', () => {
|
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': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('our-conversation-id'),
|
2021-03-03 20:09:58 +00:00
|
|
|
isMe: true,
|
|
|
|
},
|
|
|
|
'convo-1': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-1'),
|
2021-03-03 20:09:58 +00:00
|
|
|
name: 'In System Contacts',
|
|
|
|
title: 'A. Sorted First',
|
|
|
|
},
|
|
|
|
'convo-2': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('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': {
|
2022-11-19 08:31:18 +00:00
|
|
|
...makeGroup('convo-3'),
|
2021-03-03 20:09:58 +00:00
|
|
|
title: 'Should Be Dropped (group)',
|
|
|
|
},
|
|
|
|
'convo-4': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-4'),
|
2021-03-03 20:09:58 +00:00
|
|
|
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': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-5'),
|
2021-03-03 20:09:58 +00:00
|
|
|
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': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-6'),
|
2021-03-03 20:09:58 +00:00
|
|
|
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: {
|
2021-08-16 14:33:27 +00:00
|
|
|
...defaultChooseGroupMembersComposerState,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm,
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
...rootState.user,
|
|
|
|
ourConversationId: 'our-conversation-id',
|
|
|
|
i18n,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
it('returns sorted contacts when there is no search term', () => {
|
|
|
|
const state = getRootState();
|
2021-05-04 16:17:32 +00:00
|
|
|
const result = getFilteredCandidateContactsForNewGroup(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-05-04 16:17:32 +00:00
|
|
|
const result = getFilteredCandidateContactsForNewGroup(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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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-08-16 14:33:27 +00:00
|
|
|
...defaultStartDirectConversationComposerState,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: 'foo bar',
|
2021-02-23 20:34:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
'foo bar'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-04 16:17:32 +00:00
|
|
|
describe('#_getLeftPaneLists', () => {
|
2019-01-14 21:49:58 +00:00
|
|
|
it('sorts conversations based on timestamp then by intl-friendly title', () => {
|
2019-03-12 00:20:16 +00:00
|
|
|
const data: ConversationLookupType = {
|
2021-05-07 22:21:10 +00:00
|
|
|
id1: getDefaultConversation({
|
2019-01-14 21:49:58 +00:00
|
|
|
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,
|
2023-09-27 21:23:52 +00:00
|
|
|
typingContactIdTimestamps: { [generateUuid()]: Date.now() },
|
2020-05-27 21:37:06 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2021-05-07 22:21:10 +00:00
|
|
|
}),
|
|
|
|
id2: getDefaultConversation({
|
2019-01-14 21:49:58 +00:00
|
|
|
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,
|
2023-09-27 21:23:52 +00:00
|
|
|
typingContactIdTimestamps: { [generateUuid()]: Date.now() },
|
2020-05-27 21:37:06 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2021-05-07 22:21:10 +00:00
|
|
|
}),
|
|
|
|
id3: getDefaultConversation({
|
2019-01-14 21:49:58 +00:00
|
|
|
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,
|
2023-09-27 21:23:52 +00:00
|
|
|
typingContactIdTimestamps: { [generateUuid()]: Date.now() },
|
2020-05-27 21:37:06 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2021-05-07 22:21:10 +00:00
|
|
|
}),
|
|
|
|
id4: getDefaultConversation({
|
2019-01-14 21:49:58 +00:00
|
|
|
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,
|
2023-09-27 21:23:52 +00:00
|
|
|
typingContactIdTimestamps: { [generateUuid()]: Date.now() },
|
2020-05-27 21:37:06 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2021-05-07 22:21:10 +00:00
|
|
|
}),
|
|
|
|
id5: getDefaultConversation({
|
2019-01-14 21:49:58 +00:00
|
|
|
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,
|
2023-09-27 21:23:52 +00:00
|
|
|
typingContactIdTimestamps: { [generateUuid()]: Date.now() },
|
2020-05-27 21:37:06 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2021-05-07 22:21:10 +00:00
|
|
|
}),
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
2020-07-24 01:35:32 +00:00
|
|
|
const comparator = _getConversationComparator();
|
2021-11-11 22:43:05 +00:00
|
|
|
const { archivedConversations, conversations, pinnedConversations } =
|
|
|
|
_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');
|
2021-05-04 22:16:59 +00:00
|
|
|
assert.strictEqual(conversations.length, 5);
|
|
|
|
|
|
|
|
assert.strictEqual(archivedConversations.length, 0);
|
|
|
|
|
|
|
|
assert.strictEqual(pinnedConversations.length, 0);
|
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 = {
|
2021-05-07 22:21:10 +00:00
|
|
|
pin2: getDefaultConversation({
|
2020-10-10 14:25:17 +00:00
|
|
|
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,
|
2023-09-27 21:23:52 +00:00
|
|
|
typingContactIdTimestamps: { [generateUuid()]: Date.now() },
|
2020-10-10 14:25:17 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2021-05-07 22:21:10 +00:00
|
|
|
}),
|
|
|
|
pin3: getDefaultConversation({
|
2020-10-10 14:25:17 +00:00
|
|
|
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,
|
2023-09-27 21:23:52 +00:00
|
|
|
typingContactIdTimestamps: { [generateUuid()]: Date.now() },
|
2020-10-10 14:25:17 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2021-05-07 22:21:10 +00:00
|
|
|
}),
|
|
|
|
pin1: getDefaultConversation({
|
2020-10-10 14:25:17 +00:00
|
|
|
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,
|
2023-09-27 21:23:52 +00:00
|
|
|
typingContactIdTimestamps: { [generateUuid()]: Date.now() },
|
2020-10-10 14:25:17 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2021-05-07 22:21:10 +00:00
|
|
|
}),
|
2020-10-10 14:25:17 +00:00
|
|
|
};
|
|
|
|
|
2020-12-04 20:41:40 +00:00
|
|
|
const pinnedConversationIds = ['pin1', 'pin2', 'pin3'];
|
2020-10-10 14:25:17 +00:00
|
|
|
const comparator = _getConversationComparator();
|
2021-11-11 22:43:05 +00:00
|
|
|
const { archivedConversations, conversations, 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');
|
2021-05-04 22:16:59 +00:00
|
|
|
|
|
|
|
assert.strictEqual(archivedConversations.length, 0);
|
|
|
|
|
|
|
|
assert.strictEqual(conversations.length, 0);
|
2020-10-10 14:25:17 +00:00
|
|
|
});
|
2021-05-04 16:17:32 +00:00
|
|
|
|
|
|
|
it('includes archived and pinned conversations with no active_at', () => {
|
|
|
|
const data: ConversationLookupType = {
|
2021-05-07 22:21:10 +00:00
|
|
|
pin2: getDefaultConversation({
|
2021-05-04 16:17:32 +00:00
|
|
|
id: 'pin2',
|
|
|
|
e164: '+18005551111',
|
|
|
|
name: 'Pin Two',
|
|
|
|
timestamp: 30,
|
|
|
|
inboxPosition: 30,
|
|
|
|
phoneNumber: 'notused',
|
|
|
|
isArchived: false,
|
|
|
|
isPinned: true,
|
|
|
|
markedUnread: false,
|
|
|
|
|
|
|
|
type: 'direct',
|
|
|
|
isMe: false,
|
|
|
|
lastUpdated: Date.now(),
|
|
|
|
title: 'Pin Two',
|
|
|
|
unreadCount: 1,
|
|
|
|
isSelected: false,
|
2023-09-27 21:23:52 +00:00
|
|
|
typingContactIdTimestamps: { [generateUuid()]: Date.now() },
|
2021-05-04 16:17:32 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2021-05-07 22:21:10 +00:00
|
|
|
}),
|
|
|
|
pin3: getDefaultConversation({
|
2021-05-04 16:17:32 +00:00
|
|
|
id: 'pin3',
|
|
|
|
e164: '+18005551111',
|
|
|
|
name: 'Pin Three',
|
|
|
|
timestamp: 30,
|
|
|
|
inboxPosition: 30,
|
|
|
|
phoneNumber: 'notused',
|
|
|
|
isArchived: false,
|
|
|
|
isPinned: true,
|
|
|
|
markedUnread: false,
|
|
|
|
|
|
|
|
type: 'direct',
|
|
|
|
isMe: false,
|
|
|
|
lastUpdated: Date.now(),
|
|
|
|
title: 'Pin Three',
|
|
|
|
unreadCount: 1,
|
|
|
|
isSelected: false,
|
2023-09-27 21:23:52 +00:00
|
|
|
typingContactIdTimestamps: { [generateUuid()]: Date.now() },
|
2021-05-04 16:17:32 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2021-05-07 22:21:10 +00:00
|
|
|
}),
|
|
|
|
pin1: getDefaultConversation({
|
2021-05-04 16:17:32 +00:00
|
|
|
id: 'pin1',
|
|
|
|
e164: '+18005551111',
|
|
|
|
name: 'Pin One',
|
|
|
|
timestamp: 30,
|
|
|
|
inboxPosition: 30,
|
|
|
|
phoneNumber: 'notused',
|
|
|
|
isArchived: true,
|
|
|
|
isPinned: true,
|
|
|
|
markedUnread: false,
|
|
|
|
|
|
|
|
type: 'direct',
|
|
|
|
isMe: false,
|
|
|
|
lastUpdated: Date.now(),
|
|
|
|
title: 'Pin One',
|
|
|
|
unreadCount: 1,
|
|
|
|
isSelected: false,
|
2023-09-27 21:23:52 +00:00
|
|
|
typingContactIdTimestamps: { [generateUuid()]: Date.now() },
|
2021-05-04 16:17:32 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2021-05-07 22:21:10 +00:00
|
|
|
}),
|
|
|
|
pin4: getDefaultConversation({
|
2021-05-04 16:17:32 +00:00
|
|
|
id: 'pin1',
|
|
|
|
e164: '+18005551111',
|
|
|
|
name: 'Pin Four',
|
|
|
|
timestamp: 30,
|
|
|
|
inboxPosition: 30,
|
|
|
|
phoneNumber: 'notused',
|
|
|
|
activeAt: Date.now(),
|
|
|
|
isArchived: true,
|
|
|
|
isPinned: false,
|
|
|
|
markedUnread: false,
|
|
|
|
|
|
|
|
type: 'direct',
|
|
|
|
isMe: false,
|
|
|
|
lastUpdated: Date.now(),
|
|
|
|
title: 'Pin One',
|
|
|
|
unreadCount: 1,
|
|
|
|
isSelected: false,
|
2023-09-27 21:23:52 +00:00
|
|
|
typingContactIdTimestamps: { [generateUuid()]: Date.now() },
|
2021-05-04 16:17:32 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2021-05-07 22:21:10 +00:00
|
|
|
}),
|
|
|
|
pin5: getDefaultConversation({
|
2021-05-04 16:17:32 +00:00
|
|
|
id: 'pin1',
|
|
|
|
e164: '+18005551111',
|
|
|
|
name: 'Pin Five',
|
|
|
|
timestamp: 30,
|
|
|
|
inboxPosition: 30,
|
|
|
|
phoneNumber: 'notused',
|
|
|
|
isArchived: false,
|
|
|
|
isPinned: false,
|
|
|
|
markedUnread: false,
|
|
|
|
|
|
|
|
type: 'direct',
|
|
|
|
isMe: false,
|
|
|
|
lastUpdated: Date.now(),
|
|
|
|
title: 'Pin One',
|
|
|
|
unreadCount: 1,
|
|
|
|
isSelected: false,
|
2023-09-27 21:23:52 +00:00
|
|
|
typingContactIdTimestamps: { [generateUuid()]: Date.now() },
|
2021-05-04 16:17:32 +00:00
|
|
|
|
|
|
|
acceptedMessageRequest: true,
|
2021-05-07 22:21:10 +00:00
|
|
|
}),
|
2021-05-04 16:17:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const pinnedConversationIds = ['pin1', 'pin2', 'pin3'];
|
|
|
|
const comparator = _getConversationComparator();
|
2021-11-11 22:43:05 +00:00
|
|
|
const { archivedConversations, conversations, pinnedConversations } =
|
|
|
|
_getLeftPaneLists(data, comparator, undefined, pinnedConversationIds);
|
2021-05-04 16:17:32 +00:00
|
|
|
|
|
|
|
assert.strictEqual(pinnedConversations[0].name, 'Pin One');
|
|
|
|
assert.strictEqual(pinnedConversations[1].name, 'Pin Two');
|
|
|
|
assert.strictEqual(pinnedConversations[2].name, 'Pin Three');
|
|
|
|
assert.strictEqual(pinnedConversations.length, 3);
|
|
|
|
|
|
|
|
assert.strictEqual(archivedConversations[0].name, 'Pin Four');
|
|
|
|
assert.strictEqual(archivedConversations.length, 1);
|
2021-05-04 22:16:59 +00:00
|
|
|
|
|
|
|
assert.strictEqual(conversations.length, 0);
|
2021-05-04 16:17:32 +00:00
|
|
|
});
|
2020-10-10 14:25:17 +00:00
|
|
|
});
|
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: {
|
2021-08-16 14:33:27 +00:00
|
|
|
...defaultChooseGroupMembersComposerState,
|
2021-03-03 20:09:58 +00:00
|
|
|
maximumGroupSizeModalState: OneTimeModalState.Showing,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.strictEqual(
|
|
|
|
getMaximumGroupSizeModalState(state),
|
|
|
|
OneTimeModalState.Showing
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getRecommendedGroupSizeModalState', () => {
|
|
|
|
it('returns the modal state', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
2021-08-16 14:33:27 +00:00
|
|
|
...defaultChooseGroupMembersComposerState,
|
2021-03-03 20:09:58 +00:00
|
|
|
recommendedGroupSizeModalState: OneTimeModalState.Showing,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.strictEqual(
|
|
|
|
getRecommendedGroupSizeModalState(state),
|
|
|
|
OneTimeModalState.Showing
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getComposeGroupAvatar', () => {
|
|
|
|
it('returns undefined if there is no group avatar', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
2021-08-16 14:33:27 +00:00
|
|
|
...defaultSetGroupMetadataComposerState,
|
2021-03-03 20:09:58 +00:00
|
|
|
groupAvatar: undefined,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.isUndefined(getComposeGroupAvatar(state));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the group avatar', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
2021-08-16 14:33:27 +00:00
|
|
|
...defaultSetGroupMetadataComposerState,
|
2021-09-24 00:49:05 +00:00
|
|
|
groupAvatar: new Uint8Array([1, 2, 3]),
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2021-09-24 00:49:05 +00:00
|
|
|
assert.deepEqual(getComposeGroupAvatar(state), new Uint8Array([1, 2, 3]));
|
2021-03-03 20:09:58 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getComposeGroupName', () => {
|
|
|
|
it('returns the group name', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
composer: {
|
2021-08-16 14:33:27 +00:00
|
|
|
...defaultSetGroupMetadataComposerState,
|
2021-03-03 20:09:58 +00:00
|
|
|
groupName: 'foo bar',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.deepEqual(getComposeGroupName(state), 'foo bar');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getComposeSelectedContacts', () => {
|
|
|
|
it("returns the composer's selected contacts", () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
'convo-1': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-1'),
|
2021-03-03 20:09:58 +00:00
|
|
|
title: 'Person One',
|
|
|
|
},
|
|
|
|
'convo-2': {
|
2021-05-07 22:21:10 +00:00
|
|
|
...makeConversation('convo-2'),
|
2021-03-03 20:09:58 +00:00
|
|
|
title: 'Person Two',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
composer: {
|
2021-08-16 14:33:27 +00:00
|
|
|
...defaultSetGroupMetadataComposerState,
|
2021-03-03 20:09:58 +00:00
|
|
|
selectedConversationIds: ['convo-2', 'convo-1'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const titles = getComposeSelectedContacts(state).map(
|
|
|
|
contact => contact.title
|
|
|
|
);
|
|
|
|
assert.deepEqual(titles, ['Person Two', 'Person One']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-02-06 02:13:13 +00:00
|
|
|
describe('#getSafeConversationWithSameTitle', () => {
|
2021-04-21 16:31:12 +00:00
|
|
|
it('returns a selector that finds conversations by title', () => {
|
2024-02-06 02:13:13 +00:00
|
|
|
const unsafe = { ...makeConversation('abc'), title: 'Janet' };
|
|
|
|
const safe = { ...makeConversation('def'), title: 'Janet' };
|
|
|
|
const unique = { ...makeConversation('geh'), title: 'Rick' };
|
2021-04-21 16:31:12 +00:00
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
2024-02-06 02:13:13 +00:00
|
|
|
abc: unsafe,
|
|
|
|
def: safe,
|
|
|
|
geh: unique,
|
2021-04-21 16:31:12 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2024-02-06 02:13:13 +00:00
|
|
|
const janet = getSafeConversationWithSameTitle(state, {
|
|
|
|
possiblyUnsafeConversation: unsafe,
|
|
|
|
});
|
|
|
|
assert.strictEqual(janet, safe);
|
2021-04-21 16:31:12 +00:00
|
|
|
|
2024-02-06 02:13:13 +00:00
|
|
|
const rick = getSafeConversationWithSameTitle(state, {
|
|
|
|
possiblyUnsafeConversation: unique,
|
|
|
|
});
|
|
|
|
assert.strictEqual(rick, undefined);
|
2021-04-21 16:31:12 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-12 21:58:14 +00:00
|
|
|
describe('#getSelectedConversationId', () => {
|
|
|
|
it('returns undefined if no conversation is selected', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
2021-05-07 22:21:10 +00:00
|
|
|
abc123: makeConversation('abc123'),
|
2021-02-12 21:58:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.isUndefined(getSelectedConversationId(state));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the selected conversation ID', () => {
|
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
2021-05-07 22:21:10 +00:00
|
|
|
abc123: makeConversation('abc123'),
|
2021-02-12 21:58:14 +00:00
|
|
|
},
|
|
|
|
selectedConversationId: 'abc123',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.strictEqual(getSelectedConversationId(state), 'abc123');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-28 16:15:17 +00:00
|
|
|
describe('#getContactNameColorSelector', () => {
|
|
|
|
it('returns the right color order sorted by UUID ASC', () => {
|
2022-11-19 08:31:18 +00:00
|
|
|
const group: ConversationType = {
|
|
|
|
...makeGroup('group'),
|
|
|
|
sortedGroupMembers: [
|
2023-08-16 20:54:39 +00:00
|
|
|
makeConversationWithServiceId('fff'),
|
|
|
|
makeConversationWithServiceId('f00'),
|
|
|
|
makeConversationWithServiceId('e00'),
|
|
|
|
makeConversationWithServiceId('d00'),
|
|
|
|
makeConversationWithServiceId('c00'),
|
|
|
|
makeConversationWithServiceId('b00'),
|
|
|
|
makeConversationWithServiceId('a00'),
|
2022-11-19 08:31:18 +00:00
|
|
|
],
|
|
|
|
};
|
2021-05-28 16:15:17 +00:00
|
|
|
const state = {
|
|
|
|
...getEmptyRootState(),
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
group,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const contactNameColorSelector = getContactNameColorSelector(state);
|
|
|
|
|
2021-10-26 22:59:08 +00:00
|
|
|
assert.equal(contactNameColorSelector('group', 'a00'), '200');
|
|
|
|
assert.equal(contactNameColorSelector('group', 'b00'), '120');
|
|
|
|
assert.equal(contactNameColorSelector('group', 'c00'), '300');
|
|
|
|
assert.equal(contactNameColorSelector('group', 'd00'), '010');
|
|
|
|
assert.equal(contactNameColorSelector('group', 'e00'), '210');
|
|
|
|
assert.equal(contactNameColorSelector('group', 'f00'), '330');
|
|
|
|
assert.equal(contactNameColorSelector('group', 'fff'), '230');
|
2021-05-28 16:15:17 +00:00
|
|
|
});
|
2021-08-19 20:14:41 +00:00
|
|
|
|
|
|
|
it('returns the right colors for direct conversation', () => {
|
|
|
|
const direct = makeConversation('theirId');
|
|
|
|
const emptyState = getEmptyRootState();
|
|
|
|
const state = {
|
|
|
|
...emptyState,
|
|
|
|
user: {
|
|
|
|
...emptyState.user,
|
|
|
|
ourConversationId: 'us',
|
|
|
|
},
|
|
|
|
conversations: {
|
|
|
|
...getEmptyState(),
|
|
|
|
conversationLookup: {
|
|
|
|
direct,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const contactNameColorSelector = getContactNameColorSelector(state);
|
|
|
|
|
|
|
|
assert.equal(contactNameColorSelector('direct', 'theirId'), '200');
|
|
|
|
assert.equal(contactNameColorSelector('direct', 'us'), '200');
|
|
|
|
});
|
2021-05-28 16:15:17 +00:00
|
|
|
});
|
2019-01-14 21:49:58 +00:00
|
|
|
});
|