Skip to content

Commit

Permalink
example data [nfc]: Describe when to define example actions here.
Browse files Browse the repository at this point in the history
Also inline the EVENT_MUTED_USERS example to the one place it's used.
Having the data right there explicitly is nice for seeing exactly
what's happening, which makes it helpful to do that when it doesn't
get repetitious.
  • Loading branch information
gnprice committed Apr 27, 2021
1 parent c7c58c8 commit 0a66a1a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 4 additions & 9 deletions src/__tests__/lib/exampleData.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
ACCOUNT_SWITCH,
LOGIN_SUCCESS,
REALM_INIT,
EVENT_MUTED_USERS,
EVENT_NEW_MESSAGE,
MESSAGE_FETCH_START,
MESSAGE_FETCH_COMPLETE,
Expand Down Expand Up @@ -673,6 +672,8 @@ export const action = deepFreeze({
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.
});

// Ensure every `eg.action.foo` is some well-typed action. (We don't simply
Expand Down Expand Up @@ -706,11 +707,5 @@ export const eventNewMessageActionBase /* \: $Diff<EventNewMessageAction, {| mes
// message: Message,
};

export const eventMutedUsersActionBase = {
type: EVENT_MUTED_USERS,
id: 1234,

// The details of this property are important to what a test that
// uses this action is testing.
// muted_users: [],
};
// If a given action is only relevant to a single test file, no need to
// provide a generic fragment for it here; just define the test data there.
4 changes: 3 additions & 1 deletion src/mute/__tests__/mutedUsersReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Immutable from 'immutable';
import deepFreeze from 'deep-freeze';

import mutedUsersReducer from '../mutedUsersReducer';
import { EVENT_MUTED_USERS } from '../../actionConstants';
import * as eg from '../../__tests__/lib/exampleData';

describe('mutedUsersReducer', () => {
Expand Down Expand Up @@ -36,7 +37,8 @@ describe('mutedUsersReducer', () => {
describe('EVENT_MUTED_USERS', () => {
test('update `muted_users` when event comes in', () => {
const action = deepFreeze({
...eg.eventMutedUsersActionBase,
type: EVENT_MUTED_USERS,
id: 1234,
muted_users: [
{ id: eg.otherUser.user_id, timestamp: 1618822632 },
{ id: eg.thirdUser.user_id, timestamp: 1618822635 },
Expand Down

0 comments on commit 0a66a1a

Please sign in to comment.