Skip to content

Commit 0bfc94c

Browse files
committed
narrows tests: Trim down explicit data in example MESSAGE_FETCH_COMPLETEs
1 parent aab9f85 commit 0bfc94c

File tree

1 file changed

+20
-50
lines changed

1 file changed

+20
-50
lines changed

src/chat/__tests__/narrowsReducer-test.js

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
} from '../../utils/narrow';
1818
import {
1919
MESSAGE_FETCH_ERROR,
20-
MESSAGE_FETCH_COMPLETE,
2120
EVENT_MESSAGE_DELETE,
2221
EVENT_UPDATE_MESSAGE_FLAGS,
2322
} from '../../actionConstants';
@@ -361,17 +360,11 @@ describe('narrowsReducer', () => {
361360
test('if no messages returned still create the key in state', () => {
362361
const initialState = Immutable.Map([[HOME_NARROW_STR, [1, 2, 3]]]);
363362

364-
const action = deepFreeze({
365-
type: MESSAGE_FETCH_COMPLETE,
366-
anchor: 2,
363+
const action = {
364+
...eg.action.message_fetch_complete,
367365
narrow: pm1to1NarrowFromUser(eg.otherUser),
368366
messages: [],
369-
numBefore: 100,
370-
numAfter: 100,
371-
foundNewest: false,
372-
foundOldest: false,
373-
ownUserId: eg.selfUser.user_id,
374-
});
367+
};
375368

376369
const expectedState = Immutable.Map([
377370
[HOME_NARROW_STR, [1, 2, 3]],
@@ -386,21 +379,16 @@ describe('narrowsReducer', () => {
386379
test('no duplicate messages', () => {
387380
const initialState = Immutable.Map([[HOME_NARROW_STR, [1, 2, 3]]]);
388381

389-
const action = deepFreeze({
390-
type: MESSAGE_FETCH_COMPLETE,
391-
anchor: 2,
382+
const action = {
383+
...eg.action.message_fetch_complete,
392384
narrow: HOME_NARROW,
385+
anchor: 2,
393386
messages: [
394387
eg.streamMessage({ id: 2 }),
395388
eg.streamMessage({ id: 3 }),
396389
eg.streamMessage({ id: 4 }),
397390
],
398-
numBefore: 100,
399-
numAfter: 100,
400-
foundNewest: false,
401-
foundOldest: false,
402-
ownUserId: eg.selfUser.user_id,
403-
});
391+
};
404392

405393
const expectedState = Immutable.Map([[HOME_NARROW_STR, [1, 2, 3, 4]]]);
406394

@@ -413,20 +401,15 @@ describe('narrowsReducer', () => {
413401
test('added messages are sorted by id', () => {
414402
const initialState = Immutable.Map([[HOME_NARROW_STR, [1, 2]]]);
415403

416-
const action = deepFreeze({
417-
type: MESSAGE_FETCH_COMPLETE,
418-
anchor: 2,
404+
const action = {
405+
...eg.action.message_fetch_complete,
419406
narrow: HOME_NARROW,
407+
anchor: 2,
420408
messages: [
421409
eg.streamMessage({ id: 3, timestamp: 2 }),
422410
eg.streamMessage({ id: 4, timestamp: 1 }),
423411
],
424-
numBefore: 100,
425-
numAfter: 100,
426-
foundNewest: false,
427-
foundOldest: false,
428-
ownUserId: eg.selfUser.user_id,
429-
});
412+
};
430413

431414
const expectedState = Immutable.Map([[HOME_NARROW_STR, [1, 2, 3, 4]]]);
432415

@@ -439,20 +422,15 @@ describe('narrowsReducer', () => {
439422
test('when anchor is FIRST_UNREAD_ANCHOR previous messages are replaced', () => {
440423
const initialState = Immutable.Map([[HOME_NARROW_STR, [1, 2]]]);
441424

442-
const action = deepFreeze({
443-
anchor: FIRST_UNREAD_ANCHOR,
444-
type: MESSAGE_FETCH_COMPLETE,
425+
const action = {
426+
...eg.action.message_fetch_complete,
445427
narrow: HOME_NARROW,
428+
anchor: FIRST_UNREAD_ANCHOR,
446429
messages: [
447430
eg.streamMessage({ id: 3, timestamp: 2 }),
448431
eg.streamMessage({ id: 4, timestamp: 1 }),
449432
],
450-
numBefore: 100,
451-
numAfter: 100,
452-
foundNewest: false,
453-
foundOldest: false,
454-
ownUserId: eg.selfUser.user_id,
455-
});
433+
};
456434

457435
const expectedState = Immutable.Map([[HOME_NARROW_STR, [3, 4]]]);
458436

@@ -464,20 +442,15 @@ describe('narrowsReducer', () => {
464442
test('when anchor is LAST_MESSAGE_ANCHOR previous messages are replaced', () => {
465443
const initialState = Immutable.Map([[HOME_NARROW_STR, [1, 2]]]);
466444

467-
const action = deepFreeze({
468-
anchor: LAST_MESSAGE_ANCHOR,
469-
type: MESSAGE_FETCH_COMPLETE,
445+
const action = {
446+
...eg.action.message_fetch_complete,
470447
narrow: HOME_NARROW,
448+
anchor: LAST_MESSAGE_ANCHOR,
471449
messages: [
472450
eg.streamMessage({ id: 3, timestamp: 2 }),
473451
eg.streamMessage({ id: 4, timestamp: 1 }),
474452
],
475-
numBefore: 100,
476-
numAfter: 0,
477-
foundNewest: true,
478-
foundOldest: false,
479-
ownUserId: eg.selfUser.user_id,
480-
});
453+
};
481454

482455
const expectedState = Immutable.Map([[HOME_NARROW_STR, [3, 4]]]);
483456

@@ -489,10 +462,7 @@ describe('narrowsReducer', () => {
489462
test('if fetched messages are from a search narrow, ignore them', () => {
490463
const initialState = Immutable.Map([[HOME_NARROW_STR, [1, 2]]]);
491464

492-
const action = deepFreeze({
493-
...eg.action.message_fetch_complete,
494-
narrow: SEARCH_NARROW('some query'),
495-
});
465+
const action = { ...eg.action.message_fetch_complete, narrow: SEARCH_NARROW('some query') };
496466

497467
const newState = narrowsReducer(initialState, action);
498468

0 commit comments

Comments
 (0)