-
-
Notifications
You must be signed in to change notification settings - Fork 654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
msglist tests: Use Redux state in inputs, not background data #5290
Conversation
c96e10f
to
303d268
Compare
303d268
to
ad8d134
Compare
Looks like a flake in the Jest tests; investigating. |
One of the `check` functions hasn't been using our `baseState` that we put together with stream1 and stream2, to give background for the messages in those streams (streamMessages1, streamMessages2, etc.) that we pass to `check`. So, use that `baseState`. Also, the question of whether those streams are subscribed has effectively been left up to chance: if `eg.plusReduxState` *happens* to have a `subscriptions` entry for stream1 or stream2 (i.e., one where the stream_id matches), then we render a stream header as "subscribed"; otherwise not [1]. `eg.plusReduxState` currently has two `subscriptions` entries, both with random stream_ids. Most of the time they differ from stream1 and stream2 (effectively making those streams "unsubscribed"), but we saw a flake in CI for zulip#5290 where they must've collided. Settle the question by saying the streams are actually subscribed, which is the common case. [1] If "subscribed", the background color is the stream's color (#123456 in current example data); otherwise, the fallback hsl(0, 0%, 80%). And the text color is `foregroundColorFromBackground` of that.
OK, I think I've fixed the flake with this revision. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This generally looks good -- two comments below.
(And the first commit is shared with #5283, I think -- is that right?)
@@ -486,14 +536,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<FlagsState> = { ...eg.baseBackgroundData.flags }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gets changed to "plus" when the rest of the eg.baseBackgroundData
does, but then changed back to "base" when other things are getting changed to plus
:
- Object.keys(eg.baseReduxState.flags).forEach(flag => {
+ Object.keys(eg.plusReduxState.flags).forEach(flag => {
test(`message with flag: ${flag}`, () => {
- const flags: ReadWrite<FlagsState> = { ...eg.plusBackgroundData.flags };
+ const flags: ReadWrite<FlagsState> = { ...eg.baseBackgroundData.flags };
flags[flag] = { [baseSingleMessage.id]: true };
Is that intentional? It feels like it's going in the opposite direction from the rest of that commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this! No, it wasn't intentional.
const check = ({ backgroundData = baseBackgroundData, narrow, messages }) => { | ||
const check = ({ | ||
state = baseState, | ||
globalState = assumeSecretlyGlobalState(state), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not proliferate calls to assumeSecretlyGlobalState
like this -- each one of them is effectively a TODO that will need to be resolved in order to complete #5006.
In this case (and that of the other check
function below), I think what's really happening semantically is that it wants a copy of the account-independent part of the state. That is, all the parts of the global state that aren't any account's state.
We don't yet have a type for expressing that directly. Perhaps I should add one. But I think two good ways to express what these test functions want in the meantime would be:
Use a global state from example data:
globalState = eg.plusReduxState,
It's fine that that may not agree with the per-account state it gets, because we're really only looking at the account-independent parts of this -- for everything account-specific, we rely on that per-account state.
Or pass the two pieces we actually use, separately:
globalSettings = getGlobalSettings(eg.plusReduxState),
debug = getDebug(eg.plusReduxState),
No existing call site gets any more verbose, because they don't actually pass these anyway. Future call sites mostly won't either, because they'll be passing only the pieces that those respective tests care about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, seems sensible. My next revision uses the "pass the two pieces we actually use" approach.
One of the `check` functions hasn't been using our `baseState` that we put together with stream1 and stream2, to give background for the messages in those streams (streamMessages1, streamMessages2, etc.) that we pass to `check`. So, use that `baseState`. Also, the question of whether those streams are subscribed has effectively been left up to chance: if `eg.plusReduxState` *happens* to have a `subscriptions` entry for stream1 or stream2 (i.e., one where the stream_id matches), then we render a stream header as "subscribed"; otherwise not [1]. `eg.plusReduxState` currently has two `subscriptions` entries, both with random stream_ids. Most of the time they differ from stream1 and stream2 (effectively making those streams "unsubscribed"), but we saw a flake in CI for zulip#5290 where they must've collided. Settle the question by saying the streams are actually subscribed, which is the common case. [1] If "subscribed", the background color is the stream's color (#123456 in current example data); otherwise, the fallback hsl(0, 0%, 80%). And the text color is `foregroundColorFromBackground` of that.
813eccc
to
db2dc4a
Compare
Thanks for the review! Revision pushed. |
Thanks for the revision! Looks good, but there are some errors after rebase -- #5283 added more tests to this file, which need to be adjusted for this refactor. Please go ahead and merge after resolving those. |
One of the `check` functions hasn't been using our `baseState` that we put together with stream1 and stream2, to give background for the messages in those streams (streamMessages1, streamMessages2, etc.) that we pass to `check`. So, use that `baseState`. Also, the question of whether those streams are subscribed has effectively been left up to chance: if `eg.plusReduxState` *happens* to have a `subscriptions` entry for stream1 or stream2 (i.e., one where the stream_id matches), then we render a stream header as "subscribed"; otherwise not [1]. `eg.plusReduxState` currently has two `subscriptions` entries, both with random stream_ids. Most of the time they differ from stream1 and stream2 (effectively making those streams "unsubscribed"), but we saw a flake in CI for zulip#5290 where they must've collided. Settle the question by saying the streams are actually subscribed, which is the common case. [1] If "subscribed", the background color is the stream's color (#123456 in current example data); otherwise, the fallback hsl(0, 0%, 80%). And the text color is `foregroundColorFromBackground` of that.
On principle; not because there's anything in these particular fields that we really want. The principle is that we strictly want to add to the "standard example data" that `plusReduxState` exists to offer; we have no reason to erase or corrupt it.
The previous stream object was in an awkward in-between position: its ID happened to match the `stream1` and `stream1`'s subscription in the state (`baseState`) that the `check` function used as a default. But the stream's name differed in an arbitrary and unimportant way. (Both stream objects are "nonrandom" enough for current purposes.) So, just use `stream1`.
db2dc4a
to
51b582f
Compare
Thanks for the review!
Done. |
See #5225 (comment).
Thanks to Greg's #5272, which pulled out a
getBackgroundData
that this uses.