diff --git a/src/webview/__tests__/generateInboundEventEditSequence-test.js b/src/webview/__tests__/generateInboundEventEditSequence-test.js index c967597742b..43c9f2cca82 100644 --- a/src/webview/__tests__/generateInboundEventEditSequence-test.js +++ b/src/webview/__tests__/generateInboundEventEditSequence-test.js @@ -14,11 +14,21 @@ import { keyFromNarrow, ALL_PRIVATE_NARROW, } from '../../utils/narrow'; -import type { Message, Outbox, FlagsState } from '../../types'; +import type { + PerAccountState, + GlobalState, + Narrow, + Message, + Outbox, + FlagsState, +} from '../../types'; +import { assumeSecretlyGlobalState } from '../../reduxTypes'; import type { ReadWrite } from '../../generics'; import { getEditSequence } from '../generateInboundEventEditSequence'; import { applyEditSequence } from '../js/handleInboundEvents'; import getMessageListElements from '../../message/getMessageListElements'; +import { getGlobalSettings, getDebug } from '../../selectors'; +import { getBackgroundData } from '../backgroundData'; // Tell ESLint to recognize `check` as a helper function that runs // assertions. @@ -184,10 +194,9 @@ const pmMessages6 = [ }), ]; -const plusBackgroundData = { - ...eg.plusBackgroundData, - streams: new Map([stream1, stream2].map(s => [s.stream_id, s])), -}; +const baseState = eg.reduxStatePlus({ + streams: [stream1, stream2], +}); /** * Highlight changes in content-HTML generation. @@ -224,7 +233,17 @@ const plusBackgroundData = { * and `messageListElementHtml`. */ describe('messages -> piece descriptors -> content HTML is stable/sensible', () => { - const check = ({ backgroundData = plusBackgroundData, narrow, messages }) => { + const check = ({ + state = eg.plusReduxState, + globalState = assumeSecretlyGlobalState(state), + narrow, + messages, + }: {| + state?: PerAccountState, + globalState?: GlobalState, + narrow: Narrow, + messages: $ReadOnlyArray, + |}) => { invariant( messages.every((message, i, allMessages) => { const prevMessage: Message | void = allMessages[i - 1]; @@ -245,8 +264,24 @@ describe('messages -> piece descriptors -> content HTML is stable/sensible', () // Simulate applying an edit-sequence event to the DOM. applyEditSequence( getEditSequence( - { backgroundData, elements: [], _: mock_ }, - { backgroundData, elements: getMessageListElements(messages, narrow), _: mock_ }, + { + backgroundData: getBackgroundData( + state, + getGlobalSettings(globalState), + getDebug(globalState), + ), + elements: [], + _: mock_, + }, + { + backgroundData: getBackgroundData( + state, + getGlobalSettings(globalState), + getDebug(globalState), + ), + elements: getMessageListElements(messages, narrow), + _: mock_, + }, ), ); @@ -417,15 +452,10 @@ describe('messages -> piece descriptors -> content HTML is stable/sensible', () check({ narrow: HOME_NARROW, - backgroundData: { - ...eg.plusBackgroundData, - ownUser: stableSelfUser, - allUsersById: new Map([ - [singleMessageSender.user_id, singleMessageSender], - [stableSelfUser.user_id, stableSelfUser], - [stableOtherUser.user_id, stableOtherUser], - ]), - }, + state: eg.reduxStatePlus({ + realm: { ...eg.plusReduxState.realm, user_id: stableSelfUser.user_id }, + users: [singleMessageSender, stableSelfUser, stableOtherUser], + }), messages: [ { ...baseSingleMessage, @@ -486,14 +516,14 @@ describe('messages -> piece descriptors -> content HTML is stable/sensible', () }); }); - Object.keys(eg.baseReduxState.flags).forEach(flag => { + Object.keys(eg.plusReduxState.flags).forEach(flag => { test(`message with flag: ${flag}`, () => { - const flags: ReadWrite = { ...eg.plusBackgroundData.flags }; + const flags: ReadWrite = { ...eg.baseBackgroundData.flags }; flags[flag] = { [baseSingleMessage.id]: true }; check({ narrow: HOME_NARROW, messages: [baseSingleMessage], - backgroundData: { ...eg.plusBackgroundData, flags }, + state: eg.reduxStatePlus({ flags }), }); }); }); @@ -502,10 +532,9 @@ describe('messages -> piece descriptors -> content HTML is stable/sensible', () check({ narrow: HOME_NARROW, messages: [baseSingleMessage], - backgroundData: { - ...eg.plusBackgroundData, + state: eg.reduxStatePlus({ mutedUsers: Immutable.Map([[baseSingleMessage.sender_id, 1644366787]]), - }, + }), }); }); }); @@ -524,19 +553,39 @@ describe('getEditSequence correct for interesting changes', () => { return msglistElementsDiv.cloneNode(true); }; + type CheckArg = {| + state?: PerAccountState, + globalState?: GlobalState, + narrow?: Narrow, + messages: $ReadOnlyArray, + |}; + const check = ( - // TODO: Test with a variety of different things in background data + // TODO: Test with a variety of different things in state/globalState { - backgroundData: oldBackgroundData = plusBackgroundData, + state: oldState = baseState, + globalState: oldGlobalState = assumeSecretlyGlobalState(oldState), narrow: oldNarrow = HOME_NARROW, messages: oldMessages, - }, + }: CheckArg, { - backgroundData: newBackgroundData = plusBackgroundData, + state: newState = baseState, + globalState: newGlobalState = assumeSecretlyGlobalState(newState), narrow: newNarrow = HOME_NARROW, messages: newMessages, - }, + }: CheckArg, ) => { + const oldBackgroundData = getBackgroundData( + oldState, + getGlobalSettings(oldGlobalState), + getDebug(oldGlobalState), + ); + const newBackgroundData = getBackgroundData( + newState, + getGlobalSettings(newGlobalState), + getDebug(newGlobalState), + ); + const oldElements = getMessageListElements(oldMessages, oldNarrow); const newElements = getMessageListElements(newMessages, newNarrow); @@ -778,17 +827,15 @@ describe('getEditSequence correct for interesting changes', () => { check( { messages: [message], - backgroundData: { - ...eg.plusBackgroundData, - flags: { ...eg.plusBackgroundData.flags, starred: {} }, - }, + state: eg.reduxStatePlus({ + flags: { ...eg.plusReduxState.flags, starred: {} }, + }), }, { messages: [message], - backgroundData: { - ...eg.plusBackgroundData, - flags: { ...eg.plusBackgroundData.flags, starred: { [message.id]: true } }, - }, + state: eg.reduxStatePlus({ + flags: { ...eg.plusReduxState.flags, starred: { [message.id]: true } }, + }), }, ); }); @@ -798,17 +845,15 @@ describe('getEditSequence correct for interesting changes', () => { check( { messages: [message], - backgroundData: { - ...eg.plusBackgroundData, - flags: { ...eg.plusBackgroundData.flags, starred: { [message.id]: true } }, - }, + state: eg.reduxStatePlus({ + flags: { ...eg.plusReduxState.flags, starred: { [message.id]: true } }, + }), }, { messages: [message], - backgroundData: { - ...eg.plusBackgroundData, - flags: { ...eg.plusBackgroundData.flags, starred: {} }, - }, + state: eg.reduxStatePlus({ + flags: { ...eg.plusReduxState.flags, starred: {} }, + }), }, ); }); @@ -821,14 +866,13 @@ describe('getEditSequence correct for interesting changes', () => { check( { messages: [message], - backgroundData: { ...eg.plusBackgroundData, mutedUsers: Immutable.Map() }, + state: eg.reduxStatePlus({ mutedUsers: Immutable.Map() }), }, { messages: [message], - backgroundData: { - ...eg.plusBackgroundData, + state: eg.reduxStatePlus({ mutedUsers: Immutable.Map([[message.sender_id, 1644366787]]), - }, + }), }, ); }); @@ -838,14 +882,13 @@ describe('getEditSequence correct for interesting changes', () => { check( { messages: [message], - backgroundData: { - ...eg.plusBackgroundData, + state: eg.reduxStatePlus({ mutedUsers: Immutable.Map([[message.sender_id, 1644366787]]), - }, + }), }, { messages: [message], - backgroundData: { ...eg.plusBackgroundData, mutedUsers: Immutable.Map() }, + state: eg.reduxStatePlus({ mutedUsers: Immutable.Map() }), }, ); });