Skip to content

Commit

Permalink
caughtUpReducer tests: Fix some FlowFixMes.
Browse files Browse the repository at this point in the history
Fixing these will end up saving us from quite a lot of Flow errors
when it's time to upgrade Flow to 0.122.0, which we'll do with the
React Native v0.63 upgrade (zulip#4245). Yay!
  • Loading branch information
chrisbobbe committed Dec 4, 2020
1 parent 5fb6057 commit 659d174
Showing 1 changed file with 73 additions and 62 deletions.
135 changes: 73 additions & 62 deletions src/caughtup/__tests__/caughtUpReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import deepFreeze from 'deep-freeze';

import * as eg from '../../__tests__/lib/exampleData';
import caughtUpReducer from '../caughtUpReducer';
import { MESSAGE_FETCH_START, MESSAGE_FETCH_ERROR } from '../../actionConstants';
import { MESSAGE_FETCH_ERROR } from '../../actionConstants';
import { LAST_MESSAGE_ANCHOR, FIRST_UNREAD_ANCHOR } from '../../anchor';
import {
HOME_NARROW,
Expand All @@ -23,11 +23,10 @@ describe('caughtUpReducer', () => {
});

const action = deepFreeze({
type: MESSAGE_FETCH_START,
...eg.action.message_fetch_start,
narrow: HOME_NARROW,
});

// $FlowFixMe bogus action object
const newState = caughtUpReducer(initialState, action);

expect(newState).toBe(initialState);
Expand Down Expand Up @@ -96,8 +95,11 @@ describe('caughtUpReducer', () => {
const action = deepFreeze({
...eg.action.message_fetch_complete,
anchor: 1,
// $FlowFixMe bogus messages in action
messages: [{ id: 1 }, { id: 2 }, { id: 3 }],
messages: [
eg.streamMessage({ id: 1 }),
eg.streamMessage({ id: 2 }),
eg.streamMessage({ id: 3 }),
],
numBefore: 5,
numAfter: 5,
});
Expand Down Expand Up @@ -144,8 +146,13 @@ describe('caughtUpReducer', () => {
const action = deepFreeze({
...eg.action.message_fetch_complete,
anchor: 3,
// $FlowFixMe bogus messages in action
messages: [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }],
messages: [
eg.streamMessage({ id: 1 }),
eg.streamMessage({ id: 2 }),
eg.streamMessage({ id: 3 }),
eg.streamMessage({ id: 4 }),
eg.streamMessage({ id: 5 }),
],
numBefore: 2,
numAfter: 2,
foundNewest: undefined,
Expand Down Expand Up @@ -175,8 +182,13 @@ describe('caughtUpReducer', () => {
const action = deepFreeze({
...eg.action.message_fetch_complete,
anchor: 3,
// $FlowFixMe bogus messages in action
messages: [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }],
messages: [
eg.streamMessage({ id: 1 }),
eg.streamMessage({ id: 2 }),
eg.streamMessage({ id: 3 }),
eg.streamMessage({ id: 4 }),
eg.streamMessage({ id: 5 }),
],
numBefore: 2,
numAfter: 2,
});
Expand All @@ -200,13 +212,13 @@ describe('caughtUpReducer', () => {
...eg.action.message_fetch_complete,
anchor: FIRST_UNREAD_ANCHOR,
messages: [
{ id: 1, flags: ['read'] },
{ id: 2, flags: ['read'] },
{ id: 3, flags: ['read'] },
{ id: 4, flags: [] },
{ id: 5, flags: [] },
{ id: 6, flags: [] },
{ id: 7, flags: [] },
eg.streamMessage({ id: 1, flags: ['read'] }),
eg.streamMessage({ id: 2, flags: ['read'] }),
eg.streamMessage({ id: 3, flags: ['read'] }),
eg.streamMessage({ id: 4, flags: [] }),
eg.streamMessage({ id: 5, flags: [] }),
eg.streamMessage({ id: 6, flags: [] }),
eg.streamMessage({ id: 7, flags: [] }),
],
numBefore: 3,
numAfter: 3,
Expand All @@ -219,7 +231,6 @@ describe('caughtUpReducer', () => {
},
};

// $FlowFixMe bogus messages in action
const newState = caughtUpReducer(initialState, action);

expect(newState).toEqual(expectedState);
Expand All @@ -232,12 +243,12 @@ describe('caughtUpReducer', () => {
...eg.action.message_fetch_complete,
anchor: FIRST_UNREAD_ANCHOR,
messages: [
{ id: 1, flags: ['read'] },
{ id: 2, flags: ['read'] },
{ id: 3, flags: [] },
{ id: 4, flags: [] },
{ id: 5, flags: [] },
{ id: 6, flags: [] },
eg.streamMessage({ id: 1, flags: ['read'] }),
eg.streamMessage({ id: 2, flags: ['read'] }),
eg.streamMessage({ id: 3, flags: [] }),
eg.streamMessage({ id: 4, flags: [] }),
eg.streamMessage({ id: 5, flags: [] }),
eg.streamMessage({ id: 6, flags: [] }),
],
numBefore: 3,
numAfter: 4,
Expand All @@ -250,7 +261,6 @@ describe('caughtUpReducer', () => {
},
};

// $FlowFixMe bogus messages in action
const newState = caughtUpReducer(initialState, action);

expect(newState).toEqual(expectedState);
Expand All @@ -263,12 +273,12 @@ describe('caughtUpReducer', () => {
...eg.action.message_fetch_complete,
anchor: FIRST_UNREAD_ANCHOR,
messages: [
{ id: 1, flags: ['read'] },
{ id: 2, flags: ['read'] },
{ id: 3, flags: ['read'] },
{ id: 4, flags: [] },
{ id: 5, flags: [] },
{ id: 6, flags: [] },
eg.streamMessage({ id: 1, flags: ['read'] }),
eg.streamMessage({ id: 2, flags: ['read'] }),
eg.streamMessage({ id: 3, flags: ['read'] }),
eg.streamMessage({ id: 4, flags: [] }),
eg.streamMessage({ id: 5, flags: [] }),
eg.streamMessage({ id: 6, flags: [] }),
],
numBefore: 3,
numAfter: 4,
Expand All @@ -281,7 +291,6 @@ describe('caughtUpReducer', () => {
},
};

// $FlowFixMe bogus messages in action
const newState = caughtUpReducer(initialState, action);

expect(newState).toEqual(expectedState);
Expand All @@ -294,11 +303,11 @@ describe('caughtUpReducer', () => {
...eg.action.message_fetch_complete,
anchor: FIRST_UNREAD_ANCHOR,
messages: [
{ id: 1, flags: ['read'] },
{ id: 2, flags: ['read'] },
{ id: 3, flags: [] },
{ id: 4, flags: [] },
{ id: 5, flags: [] },
eg.streamMessage({ id: 1, flags: ['read'] }),
eg.streamMessage({ id: 2, flags: ['read'] }),
eg.streamMessage({ id: 3, flags: [] }),
eg.streamMessage({ id: 4, flags: [] }),
eg.streamMessage({ id: 5, flags: [] }),
],
numBefore: 3,
numAfter: 4,
Expand All @@ -311,7 +320,6 @@ describe('caughtUpReducer', () => {
},
};

// $FlowFixMe bogus messages in action
const newState = caughtUpReducer(initialState, action);

expect(newState).toEqual(expectedState);
Expand All @@ -324,8 +332,13 @@ describe('caughtUpReducer', () => {
...eg.action.message_fetch_complete,
narrow: ALL_PRIVATE_NARROW,
anchor: LAST_MESSAGE_ANCHOR,
// $FlowFixMe bogus messages in action
messages: [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }],
messages: [
eg.streamMessage({ id: 1 }),
eg.streamMessage({ id: 2 }),
eg.streamMessage({ id: 3 }),
eg.streamMessage({ id: 4 }),
eg.streamMessage({ id: 5 }),
],
numBefore: 10,
numAfter: 0,
});
Expand All @@ -352,16 +365,16 @@ describe('caughtUpReducer', () => {
...eg.action.message_fetch_complete,
anchor: 6,
messages: [
{ id: 1 },
{ id: 2 },
{ id: 3 },
{ id: 4 },
{ id: 5 },
{ id: 6 },
{ id: 7 },
{ id: 8 },
{ id: 9 },
{ id: 10 },
eg.streamMessage({ id: 1 }),
eg.streamMessage({ id: 2 }),
eg.streamMessage({ id: 3 }),
eg.streamMessage({ id: 4 }),
eg.streamMessage({ id: 5 }),
eg.streamMessage({ id: 6 }),
eg.streamMessage({ id: 7 }),
eg.streamMessage({ id: 8 }),
eg.streamMessage({ id: 9 }),
eg.streamMessage({ id: 10 }),
],
numBefore: 5,
numAfter: 5,
Expand All @@ -374,7 +387,6 @@ describe('caughtUpReducer', () => {
},
};

// $FlowFixMe bogus messages in action
const newState = caughtUpReducer(initialState, action);

expect(newState).toEqual(expectedState);
Expand All @@ -389,17 +401,17 @@ describe('caughtUpReducer', () => {
...eg.action.message_fetch_complete,
anchor: 5,
messages: [
{ id: 0 },
{ id: 1 },
{ id: 2 },
{ id: 3 },
{ id: 4 },
{ id: 5 },
{ id: 6 },
{ id: 7 },
{ id: 8 },
{ id: 9 },
{ id: 10 },
eg.streamMessage({ id: 0 }),
eg.streamMessage({ id: 1 }),
eg.streamMessage({ id: 2 }),
eg.streamMessage({ id: 3 }),
eg.streamMessage({ id: 4 }),
eg.streamMessage({ id: 5 }),
eg.streamMessage({ id: 6 }),
eg.streamMessage({ id: 7 }),
eg.streamMessage({ id: 8 }),
eg.streamMessage({ id: 9 }),
eg.streamMessage({ id: 10 }),
],
numBefore: 5,
numAfter: 5,
Expand All @@ -412,7 +424,6 @@ describe('caughtUpReducer', () => {
},
};

// $FlowFixMe bogus messages in action
const newState = caughtUpReducer(initialState, action);

expect(newState).toEqual(expectedState);
Expand Down

0 comments on commit 659d174

Please sign in to comment.