Skip to content
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

Merged
merged 5 commits into from
Mar 15, 2022

Conversation

chrisbobbe
Copy link
Contributor

See #5225 (comment).

Thanks to Greg's #5272, which pulled out a getBackgroundData that this uses.

@chrisbobbe chrisbobbe requested a review from gnprice March 10, 2022 20:29
@chrisbobbe chrisbobbe changed the title msglist tests [nfc]: Express inputs as Redux state, not background data msglist tests [nfc]: Use Redux state in inputs, not background data Mar 10, 2022
@chrisbobbe
Copy link
Contributor Author

chrisbobbe commented Mar 11, 2022

Looks like a flake in the Jest tests; investigating.

chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request Mar 11, 2022
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.
@chrisbobbe
Copy link
Contributor Author

OK, I think I've fixed the flake with this revision.

Copy link
Member

@gnprice gnprice left a 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 };
Copy link
Member

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.

Copy link
Contributor Author

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),
Copy link
Member

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.

Copy link
Contributor Author

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.

chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request Mar 11, 2022
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.
@chrisbobbe
Copy link
Contributor Author

Thanks for the review! Revision pushed.

@gnprice
Copy link
Member

gnprice commented Mar 14, 2022

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`.
@chrisbobbe chrisbobbe changed the title msglist tests [nfc]: Use Redux state in inputs, not background data msglist tests: Use Redux state in inputs, not background data Mar 15, 2022
@chrisbobbe chrisbobbe merged commit 51b582f into zulip:main Mar 15, 2022
@chrisbobbe chrisbobbe deleted the pr-msglist-test-state branch March 15, 2022 05:22
@chrisbobbe
Copy link
Contributor Author

Thanks for the review!

Please go ahead and merge after resolving those.

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants