From 7396df53845d4a01fc27e5f59ca52d5b3568e684 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Mon, 2 Mar 2020 15:43:20 -0800 Subject: [PATCH] messageActionSheet tests [nfc]: Tighten in small trivial ways. This makes a little less background noise in reading these tests from the aspects that are boring, helping the parts that are distinctive to each test stand out. By making the file about 25% shorter, it also helps look at several tests at once so as to see what they're doing in common and how they differ. --- .../__tests__/messageActionSheet-test.js | 56 +++---------------- 1 file changed, 7 insertions(+), 49 deletions(-) diff --git a/src/message/__tests__/messageActionSheet-test.js b/src/message/__tests__/messageActionSheet-test.js index 701c3e758c2..fef193ba338 100644 --- a/src/message/__tests__/messageActionSheet-test.js +++ b/src/message/__tests__/messageActionSheet-test.js @@ -23,40 +23,31 @@ describe('constructActionButtons', () => { test('show star message option if message is not starred', () => { const message = eg.streamMessage(); const flags = { ...baseBackgroundData.flags, starred: {} }; - const buttons = constructMessageActionButtons({ backgroundData: { ...baseBackgroundData, flags }, message, narrow, }); - expect(buttons).toContain('starMessage'); }); test('show unstar message option if message is starred', () => { const message = eg.streamMessage(); const flags = { ...baseBackgroundData.flags, starred: { [message.id]: true } }; - const buttons = constructMessageActionButtons({ backgroundData: { ...baseBackgroundData, flags }, message, narrow, }); - expect(buttons).toContain('unstarMessage'); }); test('show reactions option if message is has at least one reaction', () => { - const message = eg.streamMessage({ - reactions: [eg.unicodeEmojiReaction], - }); - const buttons = constructMessageActionButtons({ backgroundData: baseBackgroundData, - message, + message: eg.streamMessage({ reactions: [eg.unicodeEmojiReaction] }), narrow, }); - expect(buttons).toContain('showReactions'); }); }); @@ -66,86 +57,54 @@ describe('constructHeaderActionButtons', () => { test('show Unmute topic option if topic is muted', () => { const mute = deepFreeze([['electron issues', 'issue #556']]); - - const backgroundData = deepFreeze({ ...baseBackgroundData, mute }); - const message = eg.streamMessage({ display_recipient: 'electron issues', subject: 'issue #556', }); - const buttons = constructHeaderActionButtons({ - backgroundData, + backgroundData: { ...baseBackgroundData, mute }, message, narrow, }); - expect(buttons).toContain('unmuteTopic'); }); test('show mute topic option if topic is not muted', () => { - const mute = deepFreeze([]); - - const backgroundData = deepFreeze({ ...baseBackgroundData, mute }); - const buttons = constructHeaderActionButtons({ - backgroundData, + backgroundData: { ...baseBackgroundData, mute: [] }, message: eg.streamMessage(), narrow, }); - expect(buttons).toContain('muteTopic'); }); test('show Unmute stream option if stream is not in home view', () => { const subscriptions = [{ ...eg.subscription, in_home_view: false }]; - - const backgroundData = deepFreeze({ - ...baseBackgroundData, - subscriptions, - }); - const buttons = constructHeaderActionButtons({ - backgroundData, + backgroundData: { ...baseBackgroundData, subscriptions }, message: eg.streamMessage(), narrow, }); - expect(buttons).toContain('unmuteStream'); }); test('show mute stream option if stream is in home view', () => { const subscriptions = [{ ...eg.subscription, in_home_view: true }]; - - const backgroundData = deepFreeze({ - ...baseBackgroundData, - subscriptions, - }); - const buttons = constructHeaderActionButtons({ - backgroundData, + backgroundData: { ...baseBackgroundData, subscriptions }, message: eg.streamMessage(), narrow, }); - expect(buttons).toContain('muteStream'); }); test('show delete topic option if current user is an admin', () => { - const backgroundData = deepFreeze({ - ...baseBackgroundData, - ownUser: { - ...baseBackgroundData.ownUser, - is_admin: true, - }, - }); - + const ownUser = { ...eg.selfUser, is_admin: true }; const buttons = constructHeaderActionButtons({ - backgroundData, + backgroundData: { ...baseBackgroundData, ownUser }, message: eg.streamMessage(), narrow, }); - expect(buttons).toContain('deleteTopic'); }); @@ -155,7 +114,6 @@ describe('constructHeaderActionButtons', () => { message: eg.streamMessage(), narrow, }); - expect(buttons).not.toContain('deleteTopic'); }); });