signal-desktop/ts/test-node/components/leftPane/LeftPaneSetGroupMetadataHelper_test.ts

113 lines
3.2 KiB
TypeScript
Raw Normal View History

2021-03-03 20:09:58 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import * as sinon from 'sinon';
import { RowType, _testHeaderText } from '../../../components/ConversationList';
2021-05-07 22:21:10 +00:00
import { getDefaultConversation } from '../../../test-both/helpers/getDefaultConversation';
2022-11-16 20:18:02 +00:00
import { DurationInSeconds } from '../../../util/durations';
2021-03-03 20:09:58 +00:00
import { LeftPaneSetGroupMetadataHelper } from '../../../components/leftPane/LeftPaneSetGroupMetadataHelper';
2021-08-06 00:17:05 +00:00
function getComposeState() {
return {
groupAvatar: undefined,
2022-11-16 20:18:02 +00:00
groupExpireTimer: DurationInSeconds.ZERO,
2021-08-06 00:17:05 +00:00
groupName: '',
hasError: false,
isCreating: false,
isEditingAvatar: false,
selectedContacts: [],
userAvatarData: [],
};
}
2021-03-03 20:09:58 +00:00
describe('LeftPaneSetGroupMetadataHelper', () => {
describe('getBackAction', () => {
it('returns the "show composer" action if a request is not active', () => {
const showChooseGroupMembers = sinon.fake();
const helper = new LeftPaneSetGroupMetadataHelper({
2021-08-06 00:17:05 +00:00
...getComposeState(),
});
assert.strictEqual(
helper.getBackAction({ showChooseGroupMembers }),
showChooseGroupMembers
);
});
it("returns undefined (i.e., you can't go back) if a request is active", () => {
const helper = new LeftPaneSetGroupMetadataHelper({
2021-08-06 00:17:05 +00:00
...getComposeState(),
groupName: 'Foo Bar',
isCreating: true,
});
assert.isUndefined(
helper.getBackAction({ showChooseGroupMembers: sinon.fake() })
);
});
});
2021-03-03 20:09:58 +00:00
describe('getRowCount', () => {
it('returns 0 if there are no contacts', () => {
assert.strictEqual(
new LeftPaneSetGroupMetadataHelper({
2021-08-06 00:17:05 +00:00
...getComposeState(),
2021-03-03 20:09:58 +00:00
}).getRowCount(),
0
);
});
it('returns the number of candidate contacts + 2 if there are any', () => {
assert.strictEqual(
new LeftPaneSetGroupMetadataHelper({
2021-08-06 00:17:05 +00:00
...getComposeState(),
2021-05-07 22:21:10 +00:00
selectedContacts: [
getDefaultConversation(),
getDefaultConversation(),
],
2021-03-03 20:09:58 +00:00
}).getRowCount(),
4
);
});
});
describe('getRow', () => {
it('returns undefined if there are no contacts', () => {
assert.isUndefined(
new LeftPaneSetGroupMetadataHelper({
2021-08-06 00:17:05 +00:00
...getComposeState(),
2021-03-03 20:09:58 +00:00
}).getRow(0)
);
});
it('returns a header, then the contacts, then a blank space if there are contacts', () => {
2021-05-07 22:21:10 +00:00
const selectedContacts = [
getDefaultConversation(),
getDefaultConversation(),
];
2021-03-03 20:09:58 +00:00
const helper = new LeftPaneSetGroupMetadataHelper({
2021-08-06 00:17:05 +00:00
...getComposeState(),
2021-03-03 20:09:58 +00:00
selectedContacts,
});
assert.deepEqual(
_testHeaderText(helper.getRow(0)),
2023-03-30 00:03:25 +00:00
'icu:setGroupMetadata__members-header'
);
2021-03-03 20:09:58 +00:00
assert.deepEqual(helper.getRow(1), {
type: RowType.Contact,
contact: selectedContacts[0],
isClickable: false,
});
assert.deepEqual(helper.getRow(2), {
type: RowType.Contact,
contact: selectedContacts[1],
isClickable: false,
});
assert.deepEqual(helper.getRow(3), { type: RowType.Blank });
});
});
});