48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
// Copyright 2021 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
import { assert } from 'chai';
|
|
import { getDefaultConversation } from '../helpers/getDefaultConversation';
|
|
|
|
import { filterAndSortConversationsByRecent } from '../../util/filterAndSortConversations';
|
|
|
|
describe('filterAndSortConversationsByRecent', () => {
|
|
const conversations = [
|
|
getDefaultConversation({
|
|
title: '+16505551234',
|
|
activeAt: 1,
|
|
}),
|
|
getDefaultConversation({
|
|
title: 'Abraham Lincoln',
|
|
activeAt: 4,
|
|
}),
|
|
getDefaultConversation({
|
|
title: 'Boxing Club',
|
|
activeAt: 3,
|
|
}),
|
|
getDefaultConversation({
|
|
title: 'Not recent',
|
|
}),
|
|
getDefaultConversation({
|
|
title: 'George Washington',
|
|
e164: '+16505559876',
|
|
activeAt: 2,
|
|
}),
|
|
];
|
|
|
|
it('sorts by recency when no search term is provided', () => {
|
|
const titles = filterAndSortConversationsByRecent(
|
|
conversations,
|
|
'',
|
|
'US'
|
|
).map(contact => contact.title);
|
|
assert.sameMembers(titles, [
|
|
'+16505551234',
|
|
'George Washington',
|
|
'Boxing Club',
|
|
'Abraham Lincoln',
|
|
'Not recent',
|
|
]);
|
|
});
|
|
});
|