2021-02-23 20:34:28 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
2021-03-03 20:09:58 +00:00
|
|
|
import * as sinon from 'sinon';
|
2021-02-23 20:34:28 +00:00
|
|
|
import { RowType } from '../../../components/ConversationList';
|
|
|
|
import { FindDirection } from '../../../components/leftPane/LeftPaneHelper';
|
2023-01-25 23:51:08 +00:00
|
|
|
import {
|
|
|
|
getDefaultConversation,
|
|
|
|
getDefaultGroupListItem,
|
|
|
|
} from '../../../test-both/helpers/getDefaultConversation';
|
2021-02-23 20:34:28 +00:00
|
|
|
|
|
|
|
import { LeftPaneComposeHelper } from '../../../components/leftPane/LeftPaneComposeHelper';
|
|
|
|
|
|
|
|
describe('LeftPaneComposeHelper', () => {
|
2021-03-03 20:09:58 +00:00
|
|
|
let sinonSandbox: sinon.SinonSandbox;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
sinonSandbox = sinon.createSandbox();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
sinonSandbox.restore();
|
|
|
|
});
|
|
|
|
|
2021-04-02 21:43:39 +00:00
|
|
|
describe('getBackAction', () => {
|
|
|
|
it('returns the "show inbox" action', () => {
|
|
|
|
const showInbox = sinon.fake();
|
|
|
|
const helper = new LeftPaneComposeHelper({
|
|
|
|
composeContacts: [],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-04-02 21:43:39 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: '',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-04-02 21:43:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(helper.getBackAction({ showInbox }), showInbox);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
describe('getRowCount', () => {
|
2021-03-03 20:09:58 +00:00
|
|
|
it('returns 1 (for the "new group" button) if not searching and there are no contacts', () => {
|
|
|
|
assert.strictEqual(
|
|
|
|
new LeftPaneComposeHelper({
|
|
|
|
composeContacts: [],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: '',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
}).getRowCount(),
|
|
|
|
1
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the number of contacts + 2 (for the "new group" button and header) if not searching', () => {
|
|
|
|
assert.strictEqual(
|
|
|
|
new LeftPaneComposeHelper({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: '',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
}).getRowCount(),
|
|
|
|
4
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-04-20 23:16:49 +00:00
|
|
|
it('returns the number of contacts + number of groups + 3 (for the "new group" button and the headers) if not searching', () => {
|
|
|
|
assert.strictEqual(
|
|
|
|
new LeftPaneComposeHelper({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2023-01-25 23:51:08 +00:00
|
|
|
composeGroups: [getDefaultGroupListItem(), getDefaultGroupListItem()],
|
2021-04-20 23:16:49 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: '',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-04-20 23:16:49 +00:00
|
|
|
}).getRowCount(),
|
|
|
|
7
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-11-12 01:17:29 +00:00
|
|
|
it('returns the number of contacts, number groups + 4 (for headers and username)', () => {
|
|
|
|
assert.strictEqual(
|
|
|
|
new LeftPaneComposeHelper({
|
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2023-01-25 23:51:08 +00:00
|
|
|
composeGroups: [getDefaultGroupListItem(), getDefaultGroupListItem()],
|
2021-11-12 01:17:29 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: 'someone',
|
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-11-12 01:17:29 +00:00
|
|
|
}).getRowCount(),
|
|
|
|
8
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('if usernames are disabled, two less rows are shown', () => {
|
|
|
|
assert.strictEqual(
|
|
|
|
new LeftPaneComposeHelper({
|
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2023-01-25 23:51:08 +00:00
|
|
|
composeGroups: [getDefaultGroupListItem(), getDefaultGroupListItem()],
|
2021-11-12 01:17:29 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: 'someone',
|
|
|
|
isUsernamesEnabled: false,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-11-12 01:17:29 +00:00
|
|
|
}).getRowCount(),
|
|
|
|
6
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-04-20 23:16:49 +00:00
|
|
|
it('returns the number of conversations + the headers, but not for a phone number', () => {
|
2021-02-23 20:34:28 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
new LeftPaneComposeHelper({
|
|
|
|
composeContacts: [],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-02-23 20:34:28 +00:00
|
|
|
regionCode: 'US',
|
2022-10-18 17:12:02 +00:00
|
|
|
searchTerm: 'foobar',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-02-23 20:34:28 +00:00
|
|
|
}).getRowCount(),
|
2021-11-12 01:17:29 +00:00
|
|
|
2
|
2021-02-23 20:34:28 +00:00
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
new LeftPaneComposeHelper({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
|
|
|
regionCode: 'US',
|
2022-10-18 17:12:02 +00:00
|
|
|
searchTerm: 'foobar',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-04-20 23:16:49 +00:00
|
|
|
}).getRowCount(),
|
2021-11-12 01:17:29 +00:00
|
|
|
5
|
2021-04-20 23:16:49 +00:00
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
new LeftPaneComposeHelper({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2023-01-25 23:51:08 +00:00
|
|
|
composeGroups: [getDefaultGroupListItem()],
|
2021-02-23 20:34:28 +00:00
|
|
|
regionCode: 'US',
|
2022-10-18 17:12:02 +00:00
|
|
|
searchTerm: 'foobar',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-02-23 20:34:28 +00:00
|
|
|
}).getRowCount(),
|
2021-11-12 01:17:29 +00:00
|
|
|
7
|
2021-02-23 20:34:28 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-04-05 00:38:22 +00:00
|
|
|
it('returns 2 (for the "Start new conversation" button) if searching for a phone number with no contacts', () => {
|
2021-03-03 20:09:58 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
new LeftPaneComposeHelper({
|
|
|
|
composeContacts: [],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: '+16505551234',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
}).getRowCount(),
|
2022-04-05 00:38:22 +00:00
|
|
|
2
|
2021-03-03 20:09:58 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-11-12 01:17:29 +00:00
|
|
|
it('returns 2 if just username in results', () => {
|
|
|
|
assert.strictEqual(
|
|
|
|
new LeftPaneComposeHelper({
|
|
|
|
composeContacts: [],
|
|
|
|
composeGroups: [],
|
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: 'someone',
|
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-11-12 01:17:29 +00:00
|
|
|
}).getRowCount(),
|
|
|
|
2
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-04-05 00:38:22 +00:00
|
|
|
it('returns the number of contacts + 2 (for the "Start new conversation" button and header) if searching for a phone number', () => {
|
2021-02-23 20:34:28 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
new LeftPaneComposeHelper({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-02-23 20:34:28 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: '+16505551234',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-02-23 20:34:28 +00:00
|
|
|
}).getRowCount(),
|
2022-04-05 00:38:22 +00:00
|
|
|
5
|
2021-02-23 20:34:28 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getRow', () => {
|
2021-03-03 20:09:58 +00:00
|
|
|
it('returns a "new group" button if not searching and there are no contacts', () => {
|
|
|
|
const helper = new LeftPaneComposeHelper({
|
|
|
|
composeContacts: [],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: '',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(helper.getRow(0), {
|
|
|
|
type: RowType.CreateNewGroup,
|
|
|
|
});
|
|
|
|
assert.isUndefined(helper.getRow(1));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns a "new group" button, a header, and contacts if not searching', () => {
|
2021-05-07 22:21:10 +00:00
|
|
|
const composeContacts = [
|
|
|
|
getDefaultConversation(),
|
|
|
|
getDefaultConversation(),
|
|
|
|
];
|
2021-02-23 20:34:28 +00:00
|
|
|
const helper = new LeftPaneComposeHelper({
|
|
|
|
composeContacts,
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-02-23 20:34:28 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: '',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
assert.deepEqual(helper.getRow(0), {
|
|
|
|
type: RowType.CreateNewGroup,
|
|
|
|
});
|
|
|
|
assert.deepEqual(helper.getRow(1), {
|
|
|
|
type: RowType.Header,
|
|
|
|
i18nKey: 'contactsHeader',
|
|
|
|
});
|
|
|
|
assert.deepEqual(helper.getRow(2), {
|
|
|
|
type: RowType.Contact,
|
|
|
|
contact: composeContacts[0],
|
|
|
|
});
|
|
|
|
assert.deepEqual(helper.getRow(3), {
|
|
|
|
type: RowType.Contact,
|
|
|
|
contact: composeContacts[1],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-20 23:16:49 +00:00
|
|
|
it('returns a "new group" button, a header, contacts, groups header, and groups -- if not searching', () => {
|
2021-05-07 22:21:10 +00:00
|
|
|
const composeContacts = [
|
|
|
|
getDefaultConversation(),
|
|
|
|
getDefaultConversation(),
|
|
|
|
];
|
|
|
|
const composeGroups = [
|
2023-01-25 23:51:08 +00:00
|
|
|
getDefaultGroupListItem(),
|
|
|
|
getDefaultGroupListItem(),
|
2021-05-07 22:21:10 +00:00
|
|
|
];
|
2021-04-20 23:16:49 +00:00
|
|
|
const helper = new LeftPaneComposeHelper({
|
|
|
|
composeContacts,
|
|
|
|
composeGroups,
|
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: '',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-04-20 23:16:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(helper.getRow(0), {
|
|
|
|
type: RowType.CreateNewGroup,
|
|
|
|
});
|
2023-01-25 23:51:08 +00:00
|
|
|
|
2021-04-20 23:16:49 +00:00
|
|
|
assert.deepEqual(helper.getRow(1), {
|
|
|
|
type: RowType.Header,
|
|
|
|
i18nKey: 'contactsHeader',
|
|
|
|
});
|
|
|
|
assert.deepEqual(helper.getRow(2), {
|
|
|
|
type: RowType.Contact,
|
|
|
|
contact: composeContacts[0],
|
|
|
|
});
|
|
|
|
assert.deepEqual(helper.getRow(3), {
|
|
|
|
type: RowType.Contact,
|
|
|
|
contact: composeContacts[1],
|
|
|
|
});
|
|
|
|
assert.deepEqual(helper.getRow(4), {
|
|
|
|
type: RowType.Header,
|
|
|
|
i18nKey: 'groupsHeader',
|
|
|
|
});
|
|
|
|
assert.deepEqual(helper.getRow(5), {
|
2023-01-25 23:51:08 +00:00
|
|
|
type: RowType.SelectSingleGroup,
|
|
|
|
group: composeGroups[0],
|
2021-04-20 23:16:49 +00:00
|
|
|
});
|
|
|
|
assert.deepEqual(helper.getRow(6), {
|
2023-01-25 23:51:08 +00:00
|
|
|
type: RowType.SelectSingleGroup,
|
|
|
|
group: composeGroups[1],
|
2021-04-20 23:16:49 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-11-12 01:17:29 +00:00
|
|
|
it('returns no rows if searching, no results, and usernames are disabled', () => {
|
2021-03-03 20:09:58 +00:00
|
|
|
const helper = new LeftPaneComposeHelper({
|
|
|
|
composeContacts: [],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: 'foo bar',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: false,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.isUndefined(helper.getRow(0));
|
|
|
|
assert.isUndefined(helper.getRow(1));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns one row per contact if searching', () => {
|
2021-05-07 22:21:10 +00:00
|
|
|
const composeContacts = [
|
|
|
|
getDefaultConversation(),
|
|
|
|
getDefaultConversation(),
|
|
|
|
];
|
2021-03-03 20:09:58 +00:00
|
|
|
const helper = new LeftPaneComposeHelper({
|
|
|
|
composeContacts,
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: 'foo bar',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
});
|
|
|
|
|
2021-04-20 23:16:49 +00:00
|
|
|
assert.deepEqual(helper.getRow(1), {
|
2021-02-23 20:34:28 +00:00
|
|
|
type: RowType.Contact,
|
|
|
|
contact: composeContacts[0],
|
|
|
|
});
|
2021-04-20 23:16:49 +00:00
|
|
|
assert.deepEqual(helper.getRow(2), {
|
2021-02-23 20:34:28 +00:00
|
|
|
type: RowType.Contact,
|
|
|
|
contact: composeContacts[1],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
it('returns a "start new conversation" row if searching for a phone number and there are no results', () => {
|
|
|
|
const helper = new LeftPaneComposeHelper({
|
|
|
|
composeContacts: [],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
2022-04-05 00:38:22 +00:00
|
|
|
searchTerm: '+1(650) 555 12 34',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(helper.getRow(0), {
|
2022-04-05 00:38:22 +00:00
|
|
|
type: RowType.Header,
|
|
|
|
i18nKey: 'findByPhoneNumberHeader',
|
|
|
|
});
|
|
|
|
assert.deepEqual(helper.getRow(1), {
|
2021-03-03 20:09:58 +00:00
|
|
|
type: RowType.StartNewConversation,
|
2022-04-05 00:38:22 +00:00
|
|
|
phoneNumber: {
|
|
|
|
isValid: true,
|
|
|
|
userInput: '+1(650) 555 12 34',
|
|
|
|
e164: '+16505551234',
|
|
|
|
},
|
|
|
|
isFetching: false,
|
2021-03-03 20:09:58 +00:00
|
|
|
});
|
2022-04-05 00:38:22 +00:00
|
|
|
assert.isUndefined(helper.getRow(2));
|
2021-03-03 20:09:58 +00:00
|
|
|
});
|
|
|
|
|
2021-11-12 01:17:29 +00:00
|
|
|
it('returns just a "find by username" header if no results', () => {
|
|
|
|
const username = 'someone';
|
|
|
|
|
|
|
|
const helper = new LeftPaneComposeHelper({
|
|
|
|
composeContacts: [],
|
|
|
|
composeGroups: [],
|
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: username,
|
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {
|
|
|
|
[`username:${username}`]: true,
|
|
|
|
},
|
2021-11-12 01:17:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(helper.getRow(0), {
|
|
|
|
type: RowType.Header,
|
|
|
|
i18nKey: 'findByUsernameHeader',
|
|
|
|
});
|
|
|
|
assert.deepEqual(helper.getRow(1), {
|
|
|
|
type: RowType.UsernameSearchResult,
|
|
|
|
username,
|
2022-04-05 00:38:22 +00:00
|
|
|
isFetchingUsername: true,
|
2021-11-12 01:17:29 +00:00
|
|
|
});
|
|
|
|
assert.isUndefined(helper.getRow(2));
|
|
|
|
});
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
it('returns a "start new conversation" row, a header, and contacts if searching for a phone number', () => {
|
2021-05-07 22:21:10 +00:00
|
|
|
const composeContacts = [
|
|
|
|
getDefaultConversation(),
|
|
|
|
getDefaultConversation(),
|
|
|
|
];
|
2021-02-23 20:34:28 +00:00
|
|
|
const helper = new LeftPaneComposeHelper({
|
|
|
|
composeContacts,
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-02-23 20:34:28 +00:00
|
|
|
regionCode: 'US',
|
2022-04-05 00:38:22 +00:00
|
|
|
searchTerm: '+1(650) 555 12 34',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(helper.getRow(0), {
|
2021-03-03 20:09:58 +00:00
|
|
|
type: RowType.Header,
|
|
|
|
i18nKey: 'contactsHeader',
|
|
|
|
});
|
2022-04-05 00:38:22 +00:00
|
|
|
assert.deepEqual(helper.getRow(1), {
|
2021-02-23 20:34:28 +00:00
|
|
|
type: RowType.Contact,
|
|
|
|
contact: composeContacts[0],
|
|
|
|
});
|
2022-04-05 00:38:22 +00:00
|
|
|
assert.deepEqual(helper.getRow(2), {
|
2021-02-23 20:34:28 +00:00
|
|
|
type: RowType.Contact,
|
|
|
|
contact: composeContacts[1],
|
|
|
|
});
|
2022-04-05 00:38:22 +00:00
|
|
|
assert.deepEqual(helper.getRow(3), {
|
|
|
|
type: RowType.Header,
|
|
|
|
i18nKey: 'findByPhoneNumberHeader',
|
|
|
|
});
|
|
|
|
assert.deepEqual(helper.getRow(4), {
|
|
|
|
type: RowType.StartNewConversation,
|
|
|
|
phoneNumber: {
|
|
|
|
isValid: true,
|
|
|
|
userInput: '+1(650) 555 12 34',
|
|
|
|
e164: '+16505551234',
|
|
|
|
},
|
|
|
|
isFetching: false,
|
|
|
|
});
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getConversationAndMessageAtIndex', () => {
|
|
|
|
it('returns undefined because keyboard shortcuts are not supported', () => {
|
|
|
|
const helper = new LeftPaneComposeHelper({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-02-23 20:34:28 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: 'foo bar',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.isUndefined(helper.getConversationAndMessageAtIndex(0));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getConversationAndMessageInDirection', () => {
|
|
|
|
it('returns undefined because keyboard shortcuts are not supported', () => {
|
|
|
|
const helper = new LeftPaneComposeHelper({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-02-23 20:34:28 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: 'foo bar',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.isUndefined(
|
|
|
|
helper.getConversationAndMessageInDirection(
|
|
|
|
{ direction: FindDirection.Down, unreadOnly: false },
|
|
|
|
undefined,
|
|
|
|
undefined
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('shouldRecomputeRowHeights', () => {
|
2021-11-12 01:17:29 +00:00
|
|
|
it('returns false if just search changes, so "Find by username" header is in same position', () => {
|
2021-02-23 20:34:28 +00:00
|
|
|
const helper = new LeftPaneComposeHelper({
|
2021-11-12 01:17:29 +00:00
|
|
|
composeContacts: [],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-02-23 20:34:28 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: 'foo bar',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.isFalse(
|
|
|
|
helper.shouldRecomputeRowHeights({
|
2021-11-12 01:17:29 +00:00
|
|
|
composeContacts: [],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
2021-11-12 01:17:29 +00:00
|
|
|
searchTerm: 'different search',
|
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-02-23 20:34:28 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
assert.isFalse(
|
|
|
|
helper.shouldRecomputeRowHeights({
|
2021-11-12 01:17:29 +00:00
|
|
|
composeContacts: [],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
2021-11-12 01:17:29 +00:00
|
|
|
searchTerm: 'last search',
|
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-11-12 01:17:29 +00:00
|
|
|
it('returns true if "Find by usernames" header changes location or goes away', () => {
|
2021-03-03 20:09:58 +00:00
|
|
|
const helper = new LeftPaneComposeHelper({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: '',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.isFalse(
|
|
|
|
helper.shouldRecomputeRowHeights({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation()],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
2021-02-23 20:34:28 +00:00
|
|
|
searchTerm: '',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-11-12 01:17:29 +00:00
|
|
|
it('returns true if search changes or becomes an e164', () => {
|
2021-03-03 20:09:58 +00:00
|
|
|
const helper = new LeftPaneComposeHelper({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: 'foo bar',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.isTrue(
|
|
|
|
helper.shouldRecomputeRowHeights({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: '',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
assert.isTrue(
|
|
|
|
helper.shouldRecomputeRowHeights({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: '+16505551234',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-11-12 01:17:29 +00:00
|
|
|
it('returns true if going from no search to some search (showing "Find by username" section)', () => {
|
2021-03-03 20:09:58 +00:00
|
|
|
const helper = new LeftPaneComposeHelper({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: '',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.isTrue(
|
|
|
|
helper.shouldRecomputeRowHeights({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: 'foo bar',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-04-20 23:16:49 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be true if going from contact to group or vice versa', () => {
|
|
|
|
const helperContacts = new LeftPaneComposeHelper({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: 'foo bar',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-04-20 23:16:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.isTrue(
|
|
|
|
helperContacts.shouldRecomputeRowHeights({
|
|
|
|
composeContacts: [],
|
2023-01-25 23:51:08 +00:00
|
|
|
composeGroups: [getDefaultGroupListItem(), getDefaultGroupListItem()],
|
2021-04-20 23:16:49 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: 'foo bar',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-04-20 23:16:49 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
const helperGroups = new LeftPaneComposeHelper({
|
|
|
|
composeContacts: [],
|
2023-01-25 23:51:08 +00:00
|
|
|
composeGroups: [getDefaultGroupListItem(), getDefaultGroupListItem()],
|
2021-04-20 23:16:49 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: 'foo bar',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-04-20 23:16:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.isTrue(
|
|
|
|
helperGroups.shouldRecomputeRowHeights({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2021-04-20 23:16:49 +00:00
|
|
|
composeGroups: [],
|
2021-03-03 20:09:58 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: 'foo bar',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
})
|
|
|
|
);
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
2021-04-20 23:16:49 +00:00
|
|
|
|
|
|
|
it('should be true if the headers are in different row indices as before', () => {
|
|
|
|
const helperContacts = new LeftPaneComposeHelper({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation(), getDefaultConversation()],
|
2023-01-25 23:51:08 +00:00
|
|
|
composeGroups: [getDefaultGroupListItem()],
|
2021-04-20 23:16:49 +00:00
|
|
|
regionCode: 'US',
|
|
|
|
searchTerm: 'soup',
|
2021-11-12 01:17:29 +00:00
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-04-20 23:16:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.isTrue(
|
|
|
|
helperContacts.shouldRecomputeRowHeights({
|
2021-05-07 22:21:10 +00:00
|
|
|
composeContacts: [getDefaultConversation()],
|
2023-01-25 23:51:08 +00:00
|
|
|
composeGroups: [getDefaultGroupListItem(), getDefaultGroupListItem()],
|
2021-04-20 23:16:49 +00:00
|
|
|
regionCode: 'US',
|
2021-11-12 01:17:29 +00:00
|
|
|
searchTerm: 'soup',
|
|
|
|
isUsernamesEnabled: true,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-04-20 23:16:49 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
|
|
|
});
|