Skip to content

Commit

Permalink
exampleData types: Annotate exported example actions.
Browse files Browse the repository at this point in the history
Following Greg's recommendation at
  https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Flow.20types-first/near/1237928.

This will help move us along toward Flow's new "Types-First" mode;
switching entirely is zulip#4907.
  • Loading branch information
chrisbobbe committed Jul 29, 2021
1 parent 5b113bd commit d84bc96
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 203 deletions.
277 changes: 137 additions & 140 deletions src/__tests__/lib/exampleData.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import type {
} from '../../api/modelTypes';
import { makeUserId } from '../../api/idTypes';
import type {
AccountSwitchAction,
LoginSuccessAction,
RealmInitAction,
MessageFetchStartAction,
MessageFetchCompleteAction,
Action,
GlobalState,
CaughtUpState,
Expand Down Expand Up @@ -561,150 +566,142 @@ export const realmState = (extra?: $Rest<RealmState, { ... }>): RealmState =>
* Complete actions which need no further data.
*/

export const action = deepFreeze({
account_switch: {
type: ACCOUNT_SWITCH,
index: 0,
},
login_success: {
type: LOGIN_SUCCESS,
realm: selfAccount.realm,
export const accountSwitchAction: AccountSwitchAction = deepFreeze({
type: ACCOUNT_SWITCH,
index: 0,
});
export const loginSuccessAction: LoginSuccessAction = deepFreeze({
type: LOGIN_SUCCESS,
realm: selfAccount.realm,
email: selfAccount.email,
apiKey: selfAccount.apiKey,
});
export const realmInitAction: RealmInitAction = deepFreeze({
type: REALM_INIT,
data: {
last_event_id: 34,
msg: '',
queue_id: 1,
alert_words: [],
max_message_id: 100,
muted_topics: [],
muted_users: [],
presences: {},
max_icon_file_size: 3,
realm_add_emoji_by_admins_only: true,
realm_allow_community_topic_editing: true,
realm_allow_edit_history: true,
realm_allow_message_deleting: true,
realm_allow_message_editing: true,
realm_authentication_methods: { GitHub: true, Email: true, Google: true },
realm_available_video_chat_providers: {},
realm_bot_creation_policy: 3,
realm_bot_domain: 'example.com',
realm_create_stream_by_admins_only: true,
realm_default_language: 'en',
realm_default_twenty_four_hour_time: true,
realm_description: 'description',
realm_disallow_disposable_email_addresses: true,
realm_email_auth_enabled: true,
realm_email_changes_disabled: true,
realm_google_hangouts_domain: '',
realm_icon_source: 'U',
realm_icon_url: 'example.com/some/path',
realm_inline_image_preview: true,
realm_inline_url_embed_preview: true,
realm_invite_by_admins_only: true,
realm_invite_required: true,
realm_is_zephyr_mirror_realm: true,
realm_mandatory_topics: true,
realm_message_content_delete_limit_seconds: 3,
realm_message_content_edit_limit_seconds: 3,
realm_message_retention_days: 3,
realm_name: 'Test',
realm_name_changes_disabled: true,
realm_notifications_stream_id: 3,
realm_password_auth_enabled: true,
realm_presence_disabled: true,
realm_restricted_to_domain: true,
realm_send_welcome_emails: true,
realm_show_digest_email: true,
realm_signup_notifications_stream_id: 3,
realm_uri: selfAccount.realm.toString(),
realm_video_chat_provider: 1,
realm_waiting_period_threshold: 3,
zulip_feature_level: 1,
realm_emoji: {},
realm_filters: [],
avatar_source: 'G',
avatar_url: null,
avatar_url_medium: 'url',
can_create_streams: false,
cross_realm_bots: [],
email: selfAccount.email,
apiKey: selfAccount.apiKey,
},
realm_init: {
type: REALM_INIT,
data: {
last_event_id: 34,
msg: '',
queue_id: 1,
alert_words: [],
max_message_id: 100,
muted_topics: [],
muted_users: [],
presences: {},
max_icon_file_size: 3,
realm_add_emoji_by_admins_only: true,
realm_allow_community_topic_editing: true,
realm_allow_edit_history: true,
realm_allow_message_deleting: true,
realm_allow_message_editing: true,
realm_authentication_methods: { GitHub: true, Email: true, Google: true },
realm_available_video_chat_providers: {},
realm_bot_creation_policy: 3,
realm_bot_domain: 'example.com',
realm_create_stream_by_admins_only: true,
realm_default_language: 'en',
realm_default_twenty_four_hour_time: true,
realm_description: 'description',
realm_disallow_disposable_email_addresses: true,
realm_email_auth_enabled: true,
realm_email_changes_disabled: true,
realm_google_hangouts_domain: '',
realm_icon_source: 'U',
realm_icon_url: 'example.com/some/path',
realm_inline_image_preview: true,
realm_inline_url_embed_preview: true,
realm_invite_by_admins_only: true,
realm_invite_required: true,
realm_is_zephyr_mirror_realm: true,
realm_mandatory_topics: true,
realm_message_content_delete_limit_seconds: 3,
realm_message_content_edit_limit_seconds: 3,
realm_message_retention_days: 3,
realm_name: 'Test',
realm_name_changes_disabled: true,
realm_notifications_stream_id: 3,
realm_password_auth_enabled: true,
realm_presence_disabled: true,
realm_restricted_to_domain: true,
realm_send_welcome_emails: true,
realm_show_digest_email: true,
realm_signup_notifications_stream_id: 3,
realm_uri: selfAccount.realm.toString(),
realm_video_chat_provider: 1,
realm_waiting_period_threshold: 3,
zulip_feature_level: 1,
realm_emoji: {},
realm_filters: [],
avatar_source: 'G',
avatar_url: null,
avatar_url_medium: 'url',
can_create_streams: false,
cross_realm_bots: [],
email: selfAccount.email,
enter_sends: true,
full_name: 'Full name',
is_admin: false,
realm_non_active_users: [],
realm_users: [],
user_id: makeUserId(4),
realm_user_groups: [],
recent_private_conversations: [],
enter_sends: true,
full_name: 'Full name',
is_admin: false,
realm_non_active_users: [],
realm_users: [],
user_id: makeUserId(4),
realm_user_groups: [],
recent_private_conversations: [],
streams: [],
never_subscribed: [],
subscriptions: [],
unsubscribed: [],
default_language: 'en',
emojiset: 'google',
emojiset_choices: {},
high_contrast_mode: true,
left_side_userlist: true,
night_mode: true,
timezone: '',
translate_emoticons: true,
twenty_four_hour_time: true,
default_desktop_notifications: true,
enable_desktop_notifications: true,
enable_digest_emails: true,
enable_offline_email_notifications: true,
enable_offline_push_notifications: true,
enable_online_push_notifications: true,
enable_sounds: true,
enable_stream_desktop_notifications: true,
enable_stream_email_notifications: true,
enable_stream_push_notifications: true,
enable_stream_sounds: true,
message_content_in_email_notifications: true,
pm_content_in_desktop_notifications: true,
realm_name_in_notifications: true,
unread_msgs: {
streams: [],
never_subscribed: [],
subscriptions: [],
unsubscribed: [],
default_language: 'en',
emojiset: 'google',
emojiset_choices: {},
high_contrast_mode: true,
left_side_userlist: true,
night_mode: true,
timezone: '',
translate_emoticons: true,
twenty_four_hour_time: true,
default_desktop_notifications: true,
enable_desktop_notifications: true,
enable_digest_emails: true,
enable_offline_email_notifications: true,
enable_offline_push_notifications: true,
enable_online_push_notifications: true,
enable_sounds: true,
enable_stream_desktop_notifications: true,
enable_stream_email_notifications: true,
enable_stream_push_notifications: true,
enable_stream_sounds: true,
message_content_in_email_notifications: true,
pm_content_in_desktop_notifications: true,
realm_name_in_notifications: true,
unread_msgs: {
streams: [],
huddles: [],
count: 0,
pms: [],
mentions: [],
},
user_status: {},
huddles: [],
count: 0,
pms: [],
mentions: [],
},
zulipVersion,
},
message_fetch_start: {
type: MESSAGE_FETCH_START,
narrow: HOME_NARROW,
numBefore: 0,
numAfter: 20,
user_status: {},
},
message_fetch_complete: {
type: MESSAGE_FETCH_COMPLETE,
messages: [],
narrow: HOME_NARROW,
anchor: 0,
numBefore: 50,
numAfter: 50,
foundNewest: undefined,
foundOldest: undefined,
ownUserId: selfUser.user_id,
},
// If a given action is only relevant to a single test file, no need to
// provide a generic example of it here; just define it there.
zulipVersion,
});

// Ensure every `eg.action.foo` is some well-typed action. (We don't simply
// annotate `action` itself, because we want to keep the information of
// which one has which specific type.)
/* eslint-disable-next-line no-unused-expressions */
(action: {| [string]: Action |});
export const messageFetchStartAction: MessageFetchStartAction = deepFreeze({
type: MESSAGE_FETCH_START,
narrow: HOME_NARROW,
numBefore: 0,
numAfter: 20,
});
export const messageFetchCompleteAction: MessageFetchCompleteAction = deepFreeze({
type: MESSAGE_FETCH_COMPLETE,
messages: [],
narrow: HOME_NARROW,
anchor: 0,
numBefore: 50,
numAfter: 50,
foundNewest: undefined,
foundOldest: undefined,
ownUserId: selfUser.user_id,
});
// If a given action is only relevant to a single test file, no need to
// provide a generic example of it here; just define it there.

/* ========================================================================
* Action factories
Expand Down Expand Up @@ -751,7 +748,7 @@ export const mkActionEventNewMessage = (

export const backgroundData: BackgroundData = deepFreeze({
alertWords: [],
allImageEmojiById: action.realm_init.data.realm_emoji,
allImageEmojiById: realmInitAction.data.realm_emoji,
auth: selfAuth,
debug: baseReduxState.session.debug,
doNotMarkMessagesAsRead: baseReduxState.settings.doNotMarkMessagesAsRead,
Expand Down
6 changes: 3 additions & 3 deletions src/account/__tests__/accountsReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('accountsReducer', () => {
expect(
accountsReducer(
deepFreeze([account1, account2, account3]),
deepFreeze({ ...eg.action.realm_init, zulipVersion: newZulipVersion }),
deepFreeze({ ...eg.realmInitAction, zulipVersion: newZulipVersion }),
),
).toEqual([{ ...account1, zulipVersion: newZulipVersion }, account2, account3]);
});
Expand All @@ -36,8 +36,8 @@ describe('accountsReducer', () => {
accountsReducer(
deepFreeze([account1, account2, account3]),
deepFreeze({
...eg.action.realm_init,
data: { ...eg.action.realm_init.data, zulip_feature_level: newZulipFeatureLevel },
...eg.realmInitAction,
data: { ...eg.realmInitAction.data, zulip_feature_level: newZulipFeatureLevel },
}),
),
).toEqual([{ ...account1, zulipFeatureLevel: newZulipFeatureLevel }, account2, account3]);
Expand Down
10 changes: 5 additions & 5 deletions src/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ type DismissServerCompatNoticeAction = {|
type: typeof DISMISS_SERVER_COMPAT_NOTICE,
|};

type AccountSwitchAction = {|
export type AccountSwitchAction = {|
type: typeof ACCOUNT_SWITCH,
index: number,
|};
Expand All @@ -149,7 +149,7 @@ type AccountRemoveAction = {|
index: number,
|};

type LoginSuccessAction = {|
export type LoginSuccessAction = {|
type: typeof LOGIN_SUCCESS,
realm: URL,
email: string,
Expand All @@ -160,7 +160,7 @@ type LogoutAction = {|
type: typeof LOGOUT,
|};

type RealmInitAction = {|
export type RealmInitAction = {|
type: typeof REALM_INIT,
data: InitialData,
zulipVersion: ZulipVersion,
Expand All @@ -185,7 +185,7 @@ type AckPushTokenAction = {|
pushToken: string,
|};

type MessageFetchStartAction = {|
export type MessageFetchStartAction = {|
type: typeof MESSAGE_FETCH_START,
narrow: Narrow,
numBefore: number,
Expand Down Expand Up @@ -216,7 +216,7 @@ type MessageFetchErrorAction = {|
error: Error,
|};

type MessageFetchCompleteAction = {|
export type MessageFetchCompleteAction = {|
type: typeof MESSAGE_FETCH_COMPLETE,
messages: Message[],
narrow: Narrow,
Expand Down
Loading

0 comments on commit d84bc96

Please sign in to comment.