Skip to content

Commit

Permalink
messageActionSheet tests [nfc]: Tighten in small trivial ways.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gnprice committed Mar 3, 2020
1 parent 8fc6317 commit 7396df5
Showing 1 changed file with 7 additions and 49 deletions.
56 changes: 7 additions & 49 deletions src/message/__tests__/messageActionSheet-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
Expand All @@ -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');
});

Expand All @@ -155,7 +114,6 @@ describe('constructHeaderActionButtons', () => {
message: eg.streamMessage(),
narrow,
});

expect(buttons).not.toContain('deleteTopic');
});
});

0 comments on commit 7396df5

Please sign in to comment.