Skip to content

Commit

Permalink
exampleData: Add eg.subscription and eg.makeSubscription().
Browse files Browse the repository at this point in the history
Also demonstrate using them, to reduce boilerplate in the
newly-well-typed messageActionSheet tests.

Several values change, generally to a more representative value or
a default value.  One notable one is `in_home_view`: this means
"not muted", and so it's an important fact that its default is true.

[chris: cherry-picked from zulip#3946.]
  • Loading branch information
gnprice authored and chrisbobbe committed Jul 10, 2020
1 parent 846e441 commit 9b05139
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
27 changes: 26 additions & 1 deletion src/__tests__/lib/exampleData.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
import deepFreeze from 'deep-freeze';
import { createStore } from 'redux';

import type { CrossRealmBot, Message, PmRecipientUser, Stream, User } from '../../api/modelTypes';
import type {
CrossRealmBot,
Message,
PmRecipientUser,
Stream,
Subscription,
User,
} from '../../api/modelTypes';
import type { Action, GlobalState, RealmState } from '../../reduxTypes';
import type { Auth, Account, Outbox } from '../../types';
import { ZulipVersion } from '../../utils/zulipVersion';
Expand Down Expand Up @@ -178,6 +185,24 @@ export const stream: Stream = makeStream({
description: 'An example stream.',
});

export const makeSubscription = (args: { stream?: Stream } = {}): Subscription => {
const { stream: streamInner = stream } = args;
return deepFreeze({
...streamInner,
color: '#123456',
in_home_view: true,
pin_to_top: false,
audible_notifications: false,
desktop_notifications: false,
email_address: '??? make this value representative before using in a test :)',
is_old_stream: true,
push_notifications: null,
stream_weekly_traffic: 84,
});
};

export const subscription: Subscription = makeSubscription();

/* ========================================================================
* Messages
*/
Expand Down
19 changes: 3 additions & 16 deletions src/message/__tests__/messageActionSheet-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,7 @@ const baseBackgroundData = deepFreeze({
},
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,
},
],
subscriptions: [],
theme: 'default',
twentyFourHourTime: false,
});
Expand Down Expand Up @@ -141,7 +128,7 @@ describe('constructHeaderActionButtons', () => {

const subscriptions = deepFreeze([
{
...baseBackgroundData.subscriptions[0],
...eg.subscription,
name: 'electron issues',
in_home_view: false,
},
Expand All @@ -168,7 +155,7 @@ describe('constructHeaderActionButtons', () => {

const subscriptions = deepFreeze([
{
...baseBackgroundData.subscriptions[0],
...eg.subscription,
name: 'electron issues',
in_home_view: true,
},
Expand Down

0 comments on commit 9b05139

Please sign in to comment.