signal-desktop/ts/test/state/selectors/conversations_test.ts

145 lines
3.8 KiB
TypeScript
Raw Normal View History

2019-01-14 21:49:58 +00:00
import { assert } from 'chai';
import { ConversationLookupType } from '../../../state/ducks/conversations';
import {
_getConversationComparator,
2019-03-12 00:20:16 +00:00
_getLeftPaneLists,
2019-01-14 21:49:58 +00:00
} from '../../../state/selectors/conversations';
describe('state/selectors/conversations', () => {
describe('#getLeftPaneList', () => {
it('sorts conversations based on timestamp then by intl-friendly title', () => {
2019-03-12 00:20:16 +00:00
const data: ConversationLookupType = {
2019-01-14 21:49:58 +00:00
id1: {
id: 'id1',
e164: '+18005551111',
2019-01-14 21:49:58 +00:00
activeAt: Date.now(),
name: 'No timestamp',
timestamp: 0,
inboxPosition: 0,
2019-01-14 21:49:58 +00:00
phoneNumber: 'notused',
2019-03-12 00:20:16 +00:00
isArchived: false,
2019-01-14 21:49:58 +00:00
type: 'direct',
isMe: false,
lastUpdated: Date.now(),
title: 'No timestamp',
2019-01-14 21:49:58 +00:00
unreadCount: 1,
isSelected: false,
typingContact: {
name: 'Someone There',
color: 'blue',
phoneNumber: '+18005551111',
},
2020-05-27 21:37:06 +00:00
acceptedMessageRequest: true,
2019-01-14 21:49:58 +00:00
},
id2: {
id: 'id2',
e164: '+18005551111',
2019-01-14 21:49:58 +00:00
activeAt: Date.now(),
name: 'B',
timestamp: 20,
inboxPosition: 21,
2019-01-14 21:49:58 +00:00
phoneNumber: 'notused',
2019-03-12 00:20:16 +00:00
isArchived: false,
2019-01-14 21:49:58 +00:00
type: 'direct',
isMe: false,
lastUpdated: Date.now(),
title: 'B',
2019-01-14 21:49:58 +00:00
unreadCount: 1,
isSelected: false,
typingContact: {
name: 'Someone There',
color: 'blue',
phoneNumber: '+18005551111',
},
2020-05-27 21:37:06 +00:00
acceptedMessageRequest: true,
2019-01-14 21:49:58 +00:00
},
id3: {
id: 'id3',
e164: '+18005551111',
2019-01-14 21:49:58 +00:00
activeAt: Date.now(),
name: 'C',
timestamp: 20,
inboxPosition: 22,
2019-01-14 21:49:58 +00:00
phoneNumber: 'notused',
2019-03-12 00:20:16 +00:00
isArchived: false,
2019-01-14 21:49:58 +00:00
type: 'direct',
isMe: false,
lastUpdated: Date.now(),
title: 'C',
2019-01-14 21:49:58 +00:00
unreadCount: 1,
isSelected: false,
typingContact: {
name: 'Someone There',
color: 'blue',
phoneNumber: '+18005551111',
},
2020-05-27 21:37:06 +00:00
acceptedMessageRequest: true,
2019-01-14 21:49:58 +00:00
},
id4: {
id: 'id4',
e164: '+18005551111',
2019-01-14 21:49:58 +00:00
activeAt: Date.now(),
name: 'Á',
timestamp: 20,
inboxPosition: 20,
2019-01-14 21:49:58 +00:00
phoneNumber: 'notused',
2019-03-12 00:20:16 +00:00
isArchived: false,
2019-01-14 21:49:58 +00:00
type: 'direct',
isMe: false,
lastUpdated: Date.now(),
title: 'A',
2019-01-14 21:49:58 +00:00
unreadCount: 1,
isSelected: false,
typingContact: {
name: 'Someone There',
color: 'blue',
phoneNumber: '+18005551111',
},
2020-05-27 21:37:06 +00:00
acceptedMessageRequest: true,
2019-01-14 21:49:58 +00:00
},
id5: {
id: 'id5',
e164: '+18005551111',
2019-01-14 21:49:58 +00:00
activeAt: Date.now(),
name: 'First!',
timestamp: 30,
inboxPosition: 30,
2019-01-14 21:49:58 +00:00
phoneNumber: 'notused',
2019-03-12 00:20:16 +00:00
isArchived: false,
2019-01-14 21:49:58 +00:00
type: 'direct',
isMe: false,
lastUpdated: Date.now(),
title: 'First!',
2019-01-14 21:49:58 +00:00
unreadCount: 1,
isSelected: false,
typingContact: {
name: 'Someone There',
color: 'blue',
phoneNumber: '+18005551111',
},
2020-05-27 21:37:06 +00:00
acceptedMessageRequest: true,
2019-01-14 21:49:58 +00:00
},
};
2020-07-24 01:35:32 +00:00
const comparator = _getConversationComparator();
2019-03-12 00:20:16 +00:00
const { conversations } = _getLeftPaneLists(data, comparator);
2019-01-14 21:49:58 +00:00
2019-03-12 00:20:16 +00:00
assert.strictEqual(conversations[0].name, 'First!');
assert.strictEqual(conversations[1].name, 'Á');
assert.strictEqual(conversations[2].name, 'B');
assert.strictEqual(conversations[3].name, 'C');
assert.strictEqual(conversations[4].name, 'No timestamp');
2019-01-14 21:49:58 +00:00
});
});
});