Skip to content

Commit

Permalink
messageActionSheet [nfc]: Refactor tests to make them type-checked.
Browse files Browse the repository at this point in the history
We are moving towards making all our tests type-checked. This
commit is a move in that direction.
  • Loading branch information
agrawal-d authored and rk-for-zulip committed Feb 29, 2020
1 parent 664ee09 commit 4670210
Showing 1 changed file with 83 additions and 50 deletions.
133 changes: 83 additions & 50 deletions src/message/__tests__/messageActionSheet-test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,59 @@
// @flow strict-local
import deepFreeze from 'deep-freeze';

import * as eg from '../../__tests__/exampleData';
import { constructMessageActionButtons, constructHeaderActionButtons } from '../messageActionSheet';

const baseBackgroundData = deepFreeze({
auth: {
realm: '',
email: 'Zoe@zulip.com',
alertWords: [],
allImageEmojiById: eg.action.realm_init.data.realm_emoji,
auth: eg.selfAuth,
debug: {
doNotMarkMessagesAsRead: false,
},
subscriptions: [],
mute: [],
flags: {
read: {},
starred: {
// Key has to be number according to the type declaration. $FlowFixMe.
1: true,
// Key has to be number according to the type declaration. $FlowFixMe.
2: true,
},
collapsed: {},
mentioned: {},
wildcard_mentioned: {},
summarize_in_home: {},
summarize_in_stream: {},
force_expand: {},
force_collapse: {},
has_alert_word: {},
historical: {},
is_me_message: {},
},
ownUser: { email: 'Zoe@zulip.com' },
mute: [['announce', 'stream events']],
ownUser: eg.selfUser,
subscriptions: [
{
...eg.makeStream(),
color: '#ffffff',
in_home_view: false,
pin_to_top: false,
audible_notifications: false,
desktop_notifications: false,
email_address: 'stream@email.com',
is_old_stream: false,
push_notifications: true,
stream_weekly_traffic: 2,
},
],
theme: 'default',
twentyFourHourTime: false,
});

describe('constructActionButtons', () => {
const narrow = deepFreeze([]);

test('show star message option if message is not starred', () => {
const message = deepFreeze({
id: 3,
reactions: [],
});
const message = eg.streamMessage({ id: 3 });

const buttons = constructMessageActionButtons({
backgroundData: baseBackgroundData,
Expand All @@ -37,10 +65,7 @@ describe('constructActionButtons', () => {
});

test('show unstar message option if message is starred', () => {
const message = deepFreeze({
id: 1,
reactions: [],
});
const message = eg.streamMessage({ id: 1 });

const buttons = constructMessageActionButtons({
backgroundData: baseBackgroundData,
Expand All @@ -52,9 +77,15 @@ describe('constructActionButtons', () => {
});

test('show reactions option if message is has at least one reaction', () => {
const message = deepFreeze({
id: 1,
reactions: [{}],
const message = eg.streamMessage({
reactions: [
{
user_id: 12345,
emoji_name: 'haha',
reaction_type: 'unicode_emoji',
emoji_code: '',
},
],
});

const buttons = constructMessageActionButtons({
Expand All @@ -68,88 +99,90 @@ describe('constructActionButtons', () => {
});

describe('constructHeaderActionButtons', () => {
const narrow = deepFreeze([]);

test('show Unmute topic option if topic is muted', () => {
const subscriptions = deepFreeze([
{ name: 'denmark', in_home_view: true },
{ name: 'donald', in_home_view: false },
]);
const mute = deepFreeze([['electron issues', 'issue #556']]);

const backgroundData = deepFreeze({ ...baseBackgroundData, mute });

const message = deepFreeze({
type: 'stream',
const message = eg.streamMessage({
display_recipient: 'electron issues',
subject: 'issue #556',
});

const mute = deepFreeze([['electron issues', 'issue #556']]);

const buttons = constructHeaderActionButtons({
backgroundData: { mute, subscriptions },
backgroundData,
message,
narrow,
});

expect(buttons).toContain('unmuteTopic');
});

test('show mute topic option if topic is not muted', () => {
const message = deepFreeze({
type: 'stream',
display_recipient: 'electron issues',
subject: 'PR #558',
});

const subscriptions = deepFreeze([
{ name: 'denmark', in_home_view: true },
{ name: 'donald', in_home_view: false },
]);

const mute = deepFreeze([]);

const backgroundData = deepFreeze({ ...baseBackgroundData, mute });

const buttons = constructHeaderActionButtons({
backgroundData: { mute, subscriptions },
message,
backgroundData,
message: eg.streamMessage(),
narrow,
});

expect(buttons).toContain('muteTopic');
});

test('show Unmute stream option if stream is not in home view', () => {
const message = deepFreeze({
type: 'stream',
const message = eg.streamMessage({
display_recipient: 'electron issues',
});

const subscriptions = deepFreeze([
{
...baseBackgroundData.subscriptions[0],
name: 'electron issues',
in_home_view: false,
},
]);

const mute = deepFreeze([]);
const backgroundData = deepFreeze({
...baseBackgroundData,
subscriptions,
});

const buttons = constructHeaderActionButtons({
backgroundData: { mute, subscriptions },
backgroundData,
message,
narrow,
});

expect(buttons).toContain('unmuteStream');
});

test('show mute stream option if stream is in home view', () => {
const message = deepFreeze({
type: 'stream',
const message = eg.streamMessage({
display_recipient: 'electron issues',
});

const subscriptions = deepFreeze([
{ name: 'denmark', in_home_view: true },
{ name: 'donald', in_home_view: false },
{
...baseBackgroundData.subscriptions[0],
name: 'electron issues',
in_home_view: true,
},
]);

const mute = deepFreeze([]);
const backgroundData = deepFreeze({
...baseBackgroundData,
subscriptions,
});

const buttons = constructHeaderActionButtons({
backgroundData: { mute, subscriptions },
backgroundData,
message,
narrow,
});

expect(buttons).toContain('muteStream');
Expand Down

0 comments on commit 4670210

Please sign in to comment.