2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2020-12-04 20:41:40 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
2021-09-09 16:29:01 +00:00
|
|
|
import {
|
2021-11-30 16:29:57 +00:00
|
|
|
getAreWeASubscriber,
|
2021-09-09 16:29:01 +00:00
|
|
|
getEmojiSkinTone,
|
|
|
|
getPinnedConversationIds,
|
2021-10-12 23:59:08 +00:00
|
|
|
getPreferredLeftPaneWidth,
|
2021-09-09 16:29:01 +00:00
|
|
|
getPreferredReactionEmoji,
|
2022-01-26 23:05:26 +00:00
|
|
|
getUsernamesEnabled,
|
2021-09-09 16:29:01 +00:00
|
|
|
} from '../../../state/selectors/items';
|
2020-12-04 20:41:40 +00:00
|
|
|
import type { StateType } from '../../../state/reducer';
|
2021-09-09 16:29:01 +00:00
|
|
|
import type { ItemsStateType } from '../../../state/ducks/items';
|
2020-12-04 20:41:40 +00:00
|
|
|
|
|
|
|
describe('both/state/selectors/items', () => {
|
2021-09-09 16:29:01 +00:00
|
|
|
// Note: we would like to use the full reducer here, to get a real empty state object
|
|
|
|
// but we cannot load the full reducer inside of electron-mocha.
|
|
|
|
function getRootState(items: ItemsStateType): StateType {
|
|
|
|
return {
|
|
|
|
items,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
} as any;
|
|
|
|
}
|
|
|
|
|
2021-11-30 16:29:57 +00:00
|
|
|
describe('#getAreWeASubscriber', () => {
|
|
|
|
it('returns false if the value is not in storage', () => {
|
|
|
|
assert.isFalse(getAreWeASubscriber(getRootState({})));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the value in storage', () => {
|
|
|
|
assert.isFalse(
|
|
|
|
getAreWeASubscriber(getRootState({ areWeASubscriber: false }))
|
|
|
|
);
|
|
|
|
assert.isTrue(
|
|
|
|
getAreWeASubscriber(getRootState({ areWeASubscriber: true }))
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-09-09 16:29:01 +00:00
|
|
|
describe('#getEmojiSkinTone', () => {
|
|
|
|
it('returns 0 if passed anything invalid', () => {
|
|
|
|
[
|
|
|
|
// Invalid types
|
|
|
|
undefined,
|
|
|
|
null,
|
|
|
|
'2',
|
|
|
|
[2],
|
|
|
|
// Numbers out of range
|
|
|
|
-1,
|
|
|
|
6,
|
|
|
|
Infinity,
|
|
|
|
// Invalid numbers
|
|
|
|
0.1,
|
|
|
|
1.2,
|
|
|
|
NaN,
|
|
|
|
].forEach(skinTone => {
|
|
|
|
const state = getRootState({ skinTone });
|
|
|
|
assert.strictEqual(getEmojiSkinTone(state), 0);
|
|
|
|
});
|
|
|
|
});
|
2020-12-04 20:41:40 +00:00
|
|
|
|
2021-09-09 16:29:01 +00:00
|
|
|
it('returns all valid skin tones', () => {
|
|
|
|
[0, 1, 2, 3, 4, 5].forEach(skinTone => {
|
|
|
|
const state = getRootState({ skinTone });
|
|
|
|
assert.strictEqual(getEmojiSkinTone(state), skinTone);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-10-12 23:59:08 +00:00
|
|
|
describe('#getPreferredLeftPaneWidth', () => {
|
|
|
|
it('returns a default if no value is present', () => {
|
|
|
|
const state = getRootState({});
|
|
|
|
assert.strictEqual(getPreferredLeftPaneWidth(state), 320);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns a default value if passed something invalid', () => {
|
|
|
|
[undefined, null, '250', [250], 250.123].forEach(
|
|
|
|
preferredLeftPaneWidth => {
|
|
|
|
const state = getRootState({
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
preferredLeftPaneWidth: preferredLeftPaneWidth as any,
|
|
|
|
});
|
|
|
|
assert.strictEqual(getPreferredLeftPaneWidth(state), 320);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the value in storage if it is valid', () => {
|
|
|
|
const state = getRootState({
|
|
|
|
preferredLeftPaneWidth: 345,
|
|
|
|
});
|
|
|
|
assert.strictEqual(getPreferredLeftPaneWidth(state), 345);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-09-09 16:29:01 +00:00
|
|
|
describe('#getPinnedConversationIds', () => {
|
2020-12-04 20:41:40 +00:00
|
|
|
it('returns pinnedConversationIds key from items', () => {
|
|
|
|
const expected = ['one', 'two'];
|
2021-09-09 16:29:01 +00:00
|
|
|
const state: StateType = getRootState({
|
|
|
|
pinnedConversationIds: expected,
|
|
|
|
});
|
2020-12-04 20:41:40 +00:00
|
|
|
|
|
|
|
const actual = getPinnedConversationIds(state);
|
|
|
|
assert.deepEqual(actual, expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns empty array if no saved data', () => {
|
|
|
|
const expected: Array<string> = [];
|
2021-09-09 16:29:01 +00:00
|
|
|
const state = getRootState({});
|
2020-12-04 20:41:40 +00:00
|
|
|
|
|
|
|
const actual = getPinnedConversationIds(state);
|
|
|
|
assert.deepEqual(actual, expected);
|
|
|
|
});
|
|
|
|
});
|
2021-09-09 16:29:01 +00:00
|
|
|
|
|
|
|
describe('#getPreferredReactionEmoji', () => {
|
|
|
|
// See also: the tests for the `getPreferredReactionEmoji` helper.
|
|
|
|
|
2021-09-09 23:47:30 +00:00
|
|
|
const expectedDefault = ['❤️', '👍🏿', '👎🏿', '😂', '😮', '😢'];
|
|
|
|
|
2021-09-09 16:29:01 +00:00
|
|
|
it('returns the default set if no value is stored', () => {
|
2021-09-09 23:47:30 +00:00
|
|
|
const state = getRootState({ skinTone: 5 });
|
2021-09-09 16:29:01 +00:00
|
|
|
const actual = getPreferredReactionEmoji(state);
|
|
|
|
|
2021-09-09 23:47:30 +00:00
|
|
|
assert.deepStrictEqual(actual, expectedDefault);
|
2021-09-09 16:29:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the default set if the stored value is invalid', () => {
|
2021-09-09 23:47:30 +00:00
|
|
|
const state = getRootState({
|
|
|
|
skinTone: 5,
|
|
|
|
preferredReactionEmoji: ['garbage!!'],
|
|
|
|
});
|
2021-09-09 16:29:01 +00:00
|
|
|
const actual = getPreferredReactionEmoji(state);
|
|
|
|
|
2021-09-09 23:47:30 +00:00
|
|
|
assert.deepStrictEqual(actual, expectedDefault);
|
2021-09-09 16:29:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns a custom set of emoji', () => {
|
2021-09-09 23:47:30 +00:00
|
|
|
const preferredReactionEmoji = ['✨', '❇️', '🤙🏻', '🦈', '💖', '🅿️'];
|
|
|
|
const state = getRootState({ skinTone: 5, preferredReactionEmoji });
|
2021-09-09 16:29:01 +00:00
|
|
|
const actual = getPreferredReactionEmoji(state);
|
|
|
|
|
|
|
|
assert.deepStrictEqual(actual, preferredReactionEmoji);
|
|
|
|
});
|
|
|
|
});
|
2022-01-26 23:05:26 +00:00
|
|
|
|
|
|
|
describe('#getUsernamesEnabled', () => {
|
|
|
|
it('returns false if the flag is missing or disabled', () => {
|
|
|
|
[
|
|
|
|
{},
|
|
|
|
{ remoteConfig: {} },
|
|
|
|
{
|
|
|
|
remoteConfig: {
|
|
|
|
'desktop.usernames': {
|
|
|
|
name: 'desktop.usernames' as const,
|
|
|
|
enabled: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
].forEach(itemsState => {
|
|
|
|
const state = getRootState(itemsState);
|
|
|
|
assert.isFalse(getUsernamesEnabled(state));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true if the flag is enabled', () => {
|
|
|
|
const state = getRootState({
|
|
|
|
remoteConfig: {
|
|
|
|
'desktop.usernames': {
|
|
|
|
name: 'desktop.usernames' as const,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
assert.isTrue(getUsernamesEnabled(state));
|
|
|
|
});
|
|
|
|
});
|
2020-12-04 20:41:40 +00:00
|
|
|
});
|