diff --git a/src/webview/__tests__/__snapshots__/generateInboundEventEditSequence-test.js.snap.android b/src/webview/__tests__/__snapshots__/generateInboundEventEditSequence-test.js.snap.android index 046f2913f6f..a118313e597 100644 --- a/src/webview/__tests__/__snapshots__/generateInboundEventEditSequence-test.js.snap.android +++ b/src/webview/__tests__/__snapshots__/generateInboundEventEditSequence-test.js.snap.android @@ -88,8 +88,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Feb 5, 1995
-
+
# stream 1
topic 1
@@ -132,8 +132,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Mar 5, 1995
-
+
# stream 1
topic 1
@@ -181,8 +181,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Feb 19, 1995
-
+
# stream 1
topic 1
@@ -205,8 +205,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N
-
+
# stream 1
topic 2
@@ -237,8 +237,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Mar 5, 1995
-
+
# stream 1
topic 1
@@ -261,8 +261,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N
-
+
# stream 2
topic 2
@@ -293,8 +293,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Mar 5, 1995
-
+
# stream 1
topic 1
@@ -608,8 +608,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Feb 5, 1995
-
+
# stream 1
topic 1
@@ -688,8 +688,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Feb 19, 1995
-
+
# stream 1
topic 1
@@ -712,8 +712,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N
-
+
# stream 1
topic 2
@@ -876,8 +876,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Mar 5, 1995
-
+
# stream 1
topic 1
@@ -900,8 +900,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N
-
+
# stream 2
topic 2
@@ -924,8 +924,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N
-
+
# stream 1
topic 1
@@ -996,8 +996,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N
-
+
# stream 1
topic 1
@@ -1526,6 +1526,38 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible all-pm
" `; +exports[`messages -> piece descriptors -> content HTML is stable/sensible other interesting cases (single messages) message in unsubscribed stream 1`] = ` +"
+
+ Dec 31, 1969 +
+
+
+ # stream 1 +
+
example topic
+
Dec 31, 1969
+
+
+ \\"Nonrandom +
+
+
+
+ Nonrandom name sender User +
+
11:59 PM
+
+

This is an example stream message.

+ + + +
+ +
" +`; + exports[`messages -> piece descriptors -> content HTML is stable/sensible other interesting cases (single messages) message with a poll 1`] = ` "
@@ -1534,7 +1566,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1576,7 +1608,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1608,7 +1640,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1640,7 +1672,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1672,7 +1704,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1704,7 +1736,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1736,7 +1768,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1768,7 +1800,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1800,7 +1832,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1832,7 +1864,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1864,7 +1896,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1896,7 +1928,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1928,7 +1960,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1958,9 +1990,9 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other Dec 31, 1969
-
- # nonrandom stream +
+ # stream 1
example topic
Dec 31, 1969
@@ -1992,7 +2024,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -2026,7 +2058,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -2058,7 +2090,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -2090,7 +2122,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -2122,7 +2154,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
diff --git a/src/webview/__tests__/__snapshots__/generateInboundEventEditSequence-test.js.snap.ios b/src/webview/__tests__/__snapshots__/generateInboundEventEditSequence-test.js.snap.ios index 046f2913f6f..a118313e597 100644 --- a/src/webview/__tests__/__snapshots__/generateInboundEventEditSequence-test.js.snap.ios +++ b/src/webview/__tests__/__snapshots__/generateInboundEventEditSequence-test.js.snap.ios @@ -88,8 +88,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Feb 5, 1995
-
+
# stream 1
topic 1
@@ -132,8 +132,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Mar 5, 1995
-
+
# stream 1
topic 1
@@ -181,8 +181,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Feb 19, 1995
-
+
# stream 1
topic 1
@@ -205,8 +205,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N
-
+
# stream 1
topic 2
@@ -237,8 +237,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Mar 5, 1995
-
+
# stream 1
topic 1
@@ -261,8 +261,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N
-
+
# stream 2
topic 2
@@ -293,8 +293,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Mar 5, 1995
-
+
# stream 1
topic 1
@@ -608,8 +608,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Feb 5, 1995
-
+
# stream 1
topic 1
@@ -688,8 +688,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Feb 19, 1995
-
+
# stream 1
topic 1
@@ -712,8 +712,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N
-
+
# stream 1
topic 2
@@ -876,8 +876,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N Mar 5, 1995
-
+
# stream 1
topic 1
@@ -900,8 +900,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N
-
+
# stream 2
topic 2
@@ -924,8 +924,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N
-
+
# stream 1
topic 1
@@ -996,8 +996,8 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible HOME_N
-
+
# stream 1
topic 1
@@ -1526,6 +1526,38 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible all-pm
" `; +exports[`messages -> piece descriptors -> content HTML is stable/sensible other interesting cases (single messages) message in unsubscribed stream 1`] = ` +"
+
+ Dec 31, 1969 +
+
+
+ # stream 1 +
+
example topic
+
Dec 31, 1969
+
+
+ \\"Nonrandom +
+
+
+
+ Nonrandom name sender User +
+
11:59 PM
+
+

This is an example stream message.

+ + + +
+ +
" +`; + exports[`messages -> piece descriptors -> content HTML is stable/sensible other interesting cases (single messages) message with a poll 1`] = ` "
@@ -1534,7 +1566,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1576,7 +1608,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1608,7 +1640,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1640,7 +1672,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1672,7 +1704,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1704,7 +1736,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1736,7 +1768,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1768,7 +1800,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1800,7 +1832,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1832,7 +1864,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1864,7 +1896,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1896,7 +1928,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1928,7 +1960,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -1958,9 +1990,9 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other Dec 31, 1969
-
- # nonrandom stream +
+ # stream 1
example topic
Dec 31, 1969
@@ -1992,7 +2024,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -2026,7 +2058,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -2058,7 +2090,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -2090,7 +2122,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
@@ -2122,7 +2154,7 @@ exports[`messages -> piece descriptors -> content HTML is stable/sensible other
- # nonrandom stream + # stream 1
example topic
Dec 31, 1969
diff --git a/src/webview/__tests__/generateInboundEventEditSequence-test.js b/src/webview/__tests__/generateInboundEventEditSequence-test.js index 87c08aa50cf..fa9a32fc73a 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, + GlobalSettingsState, + Debug, + Narrow, + Message, + Outbox, + FlagsState, +} from '../../types'; 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,14 @@ const pmMessages6 = [ }), ]; -const plusBackgroundData = { - ...eg.plusBackgroundData, - streams: new Map([stream1, stream2].map(s => [s.stream_id, s])), -}; +const baseState = eg.reduxStatePlus({ + streams: [...eg.plusReduxState.streams, stream1, stream2], + subscriptions: [ + ...eg.plusReduxState.subscriptions, + eg.makeSubscription({ stream: stream1 }), + eg.makeSubscription({ stream: stream2 }), + ], +}); /** * Highlight changes in content-HTML generation. @@ -224,7 +238,19 @@ const plusBackgroundData = { * and `messageListElementHtml`. */ describe('messages -> piece descriptors -> content HTML is stable/sensible', () => { - const check = ({ backgroundData = plusBackgroundData, narrow, messages }) => { + const check = ({ + state = baseState, + globalSettings = getGlobalSettings(eg.plusReduxState), + debug = getDebug(eg.plusReduxState), + narrow, + messages, + }: {| + state?: PerAccountState, + globalSettings?: GlobalSettingsState, + debug?: Debug, + narrow: Narrow, + messages: $ReadOnlyArray, + |}) => { invariant( messages.every((message, i, allMessages) => { const prevMessage: Message | void = allMessages[i - 1]; @@ -245,8 +271,16 @@ 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, globalSettings, debug), + elements: [], + _: mock_, + }, + { + backgroundData: getBackgroundData(state, globalSettings, debug), + elements: getMessageListElements(messages, narrow), + _: mock_, + }, ), ); @@ -388,10 +422,25 @@ describe('messages -> piece descriptors -> content HTML is stable/sensible', () const baseSingleMessage = eg.streamMessage({ id: -1, timestamp: -1, - stream: eg.makeStream({ stream_id: 1, name: 'nonrandom stream' }), + stream: stream1, sender: singleMessageSender, }); + test('message in unsubscribed stream', () => { + check({ + narrow: HOME_NARROW, + messages: [baseSingleMessage], + state: eg.reduxStatePlus({ + streams: [...eg.plusReduxState.streams, stream1, stream2], + subscriptions: [ + ...eg.plusReduxState.subscriptions, + // no subscription for stream1 + eg.makeSubscription({ stream: stream2 }), + ], + }), + }); + }); + test('message with reactions', () => { check({ narrow: HOME_NARROW, @@ -417,15 +466,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 +530,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 }; flags[flag] = { [baseSingleMessage.id]: true }; check({ narrow: HOME_NARROW, messages: [baseSingleMessage], - backgroundData: { ...eg.plusBackgroundData, flags }, + state: eg.reduxStatePlus({ flags }), }); }); }); @@ -502,10 +546,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]]), - }, + }), }); }); @@ -519,15 +562,14 @@ describe('messages -> piece descriptors -> content HTML is stable/sensible', () check({ narrow: HOME_NARROW, messages: [baseSingleMessage], - backgroundData: { - ...eg.plusBackgroundData, + state: eg.reduxStatePlus({ userStatuses: Immutable.Map([ [ baseSingleMessage.sender_id, { away: false, status_text: null, status_emoji: statusEmoji }, ], ]), - }, + }), }); }); }); @@ -547,19 +589,34 @@ describe('getEditSequence correct for interesting changes', () => { return msglistElementsDiv.cloneNode(true); }; + type CheckArg = {| + state?: PerAccountState, + globalSettings?: GlobalSettingsState, + debug?: Debug, + 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, + globalSettings: oldGlobalSettings = getGlobalSettings(eg.plusReduxState), + debug: oldDebug = getDebug(eg.plusReduxState), narrow: oldNarrow = HOME_NARROW, messages: oldMessages, - }, + }: CheckArg, { - backgroundData: newBackgroundData = plusBackgroundData, + state: newState = baseState, + globalSettings: newGlobalSettings = getGlobalSettings(eg.plusReduxState), + debug: newDebug = getDebug(eg.plusReduxState), narrow: newNarrow = HOME_NARROW, messages: newMessages, - }, + }: CheckArg, ) => { + const oldBackgroundData = getBackgroundData(oldState, oldGlobalSettings, oldDebug); + const newBackgroundData = getBackgroundData(newState, newGlobalSettings, newDebug); + const oldElements = getMessageListElements(oldMessages, oldNarrow); const newElements = getMessageListElements(newMessages, newNarrow); @@ -801,17 +858,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 } }, + }), }, ); }); @@ -821,17 +876,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: {} }, + }), }, ); }); @@ -844,14 +897,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]]), - }, + }), }, ); }); @@ -861,14 +913,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() }), }, ); }); @@ -892,8 +943,7 @@ describe('getEditSequence correct for interesting changes', () => { check( ...[emojiStatusA, emojiStatusB].map(emojiStatus => ({ messages: [message], - backgroundData: { - ...eg.plusBackgroundData, + state: eg.reduxStatePlus({ userStatuses: Immutable.Map([ [ message.sender_id, @@ -904,7 +954,7 @@ describe('getEditSequence correct for interesting changes', () => { }, ], ]), - }, + }), })), ); });