From c5c667ab1bc8c198587abe5d40b8df314a0ac4c8 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 4 May 2021 15:16:59 -0700 Subject: [PATCH] Left pane: Ensure pinned conversations show only once --- ts/state/selectors/conversations.ts | 1 + .../state/selectors/conversations_test.ts | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index d36e26cba45d..a51dc6588983 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -262,6 +262,7 @@ export const _getLeftPaneLists = ( // We always show pinned conversations if (conversation.isPinned) { pinnedConversations.push(conversation); + continue; } if (conversation.activeAt) { diff --git a/ts/test-both/state/selectors/conversations_test.ts b/ts/test-both/state/selectors/conversations_test.ts index 4f70aaac86ba..cc49edce2374 100644 --- a/ts/test-both/state/selectors/conversations_test.ts +++ b/ts/test-both/state/selectors/conversations_test.ts @@ -1306,13 +1306,22 @@ describe('both/state/selectors/conversations', () => { }, }; const comparator = _getConversationComparator(); - const { conversations } = _getLeftPaneLists(data, comparator); + const { + archivedConversations, + conversations, + pinnedConversations, + } = _getLeftPaneLists(data, comparator); 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'); + assert.strictEqual(conversations.length, 5); + + assert.strictEqual(archivedConversations.length, 0); + + assert.strictEqual(pinnedConversations.length, 0); }); describe('given pinned conversations', () => { @@ -1400,7 +1409,11 @@ describe('both/state/selectors/conversations', () => { const pinnedConversationIds = ['pin1', 'pin2', 'pin3']; const comparator = _getConversationComparator(); - const { pinnedConversations } = _getLeftPaneLists( + const { + archivedConversations, + conversations, + pinnedConversations, + } = _getLeftPaneLists( data, comparator, undefined, @@ -1410,6 +1423,10 @@ describe('both/state/selectors/conversations', () => { assert.strictEqual(pinnedConversations[0].name, 'Pin One'); assert.strictEqual(pinnedConversations[1].name, 'Pin Two'); assert.strictEqual(pinnedConversations[2].name, 'Pin Three'); + + assert.strictEqual(archivedConversations.length, 0); + + assert.strictEqual(conversations.length, 0); }); it('includes archived and pinned conversations with no active_at', () => { @@ -1545,8 +1562,9 @@ describe('both/state/selectors/conversations', () => { const pinnedConversationIds = ['pin1', 'pin2', 'pin3']; const comparator = _getConversationComparator(); const { - pinnedConversations, archivedConversations, + conversations, + pinnedConversations, } = _getLeftPaneLists( data, comparator, @@ -1561,6 +1579,8 @@ describe('both/state/selectors/conversations', () => { assert.strictEqual(archivedConversations[0].name, 'Pin Four'); assert.strictEqual(archivedConversations.length, 1); + + assert.strictEqual(conversations.length, 0); }); }); });