Commit Graph

3984 Commits

Author SHA1 Message Date
Abhijeet Prasad Bodas 206fe1ef3b node tests: Introduce message_store.create_mock_message() helper.
Previously, it was tedious to create actual message
objects in message_store for use in node tests.
This was mainly because, `add_message_metadata`
in message_store has many dependencies and
validation checks. Since it was difficult to create
actual message objects, many tests just mocked
the `message_store.get()` method to return the desired
message.

This commit adds a new helper method (`create_mock_message`)
to message_store, for use in node tests. This just stores
the object passed to it in the `stores_messages` map,
without any validation. We do not add any
default fields to the message object before saving
it from this helper, because doing so would decrease
the utility of this helper, and, if a test
depends on some field having a particular value,
then it would be better to just pass the field: value
pair from the test itself, for readability, rather
than relying on the helper to add the field for us.

This helper allows us to write deeper tests.

This commit also replaces some instances of mocking
`message_store.get()` to use this new helper method.
2021-03-18 15:55:39 -07:00
Steve Howell 728905d4bc node tests: Clean pm_conversations more simply. 2021-03-18 16:37:20 -04:00
Steve Howell b2be16c4d0 node tests: Use clean BuddyList instance in tests.
As part of this, we inline one function call rather
than changing it to have buddy_list be passed in.
2021-03-18 16:37:20 -04:00
YashRE42 2b03a74d97 channel: Add while_reloading test cases for 100% coverage.
The branches that depended on reload_state were introduced after a
refactor in 'presence' and never had relevant test cases added.
2021-03-18 10:09:22 -07:00
Anders Kaseorg 3ef6f6e2e2 js: Convert static/js/blueslip.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-17 08:47:15 -04:00
Anders Kaseorg b0ceaa1ea0 node_tests: Replace override(blueslip) with blueslip.expect.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-17 08:47:15 -04:00
100RABHpy 039dd256a1 markdown: Fix a bug in query_and_reply.
Fixes #17466
This commit will change encoding logic. Initial logic
was not encoding parenthesis, and this creates conflicts
with the markdown link format. To resolve this while encoding,
we're now replacing parenthesis with ".28" and ".29."

There is no need to change decoding logic because before
decoding any URL, we first convert all the “.” to “%.”

optimization: No need to replace parenthesis in popovers.js.
2021-03-16 16:40:37 -07:00
Steve Howell 5192dab31d node tests: Add explicit stub_templates calls. 2021-03-16 14:53:52 -04:00
Steve Howell 93ba7c7c02 node tests: Isolate message mutations for recent_topics. 2021-03-16 14:53:52 -04:00
Steve Howell 2a80c23484 node tests: Add test wrapper to recent_topics. 2021-03-16 14:53:52 -04:00
Steve Howell c05007b427 node tests: Use more overrides in composebox_typeahead. 2021-03-16 14:53:52 -04:00
Steve Howell 15d99f87fb node tests: Clear more data for typeahead_helper.
We also use a more realistic method of setting
recipient counts, and we make the pm count test
a bit more explicit.
2021-03-16 09:04:26 -04:00
Steve Howell 0523f96a1b node tests: Add test() wrapper for markdown tests. 2021-03-16 09:04:26 -04:00
Steve Howell 4d59fb1063 node tests: Set compose state for compose_actions tests. 2021-03-16 09:04:26 -04:00
Steve Howell 157ab156e7 node tests: Use override for current_msg_list. 2021-03-16 09:04:26 -04:00
Steve Howell 433d42e723 node tests: Add whiny_get() helper. 2021-03-16 09:04:26 -04:00
Steve Howell 764b83b890 node tests: Remove stub_channel_get().
A few years ago I introduced the anti-pattern
of automatically calling success functions within
channel.get stubs.  It's better to just capture
the success function and call it explicitly.

Also, we now have override(), so it's easy to
inline these types of things in a safe way.
2021-03-16 09:04:26 -04:00
Steve Howell 6b0ceeb3b0 node tests: Remove stub_selected_message. 2021-03-16 09:04:26 -04:00
Steve Howell c06dedf670 node tests: Add test() wrapper for filter tests. 2021-03-16 09:04:26 -04:00
Steve Howell 4f2170994a node tests: Move functions higher up in file. 2021-03-16 09:04:26 -04:00
Steve Howell e9e8bcd26e node tests: Add popovers.clear_for_testing(). 2021-03-16 09:04:26 -04:00
Steve Howell 9c9d381890 node tests: Add test() for composebox_typeahead. 2021-03-16 09:04:26 -04:00
Steve Howell 2093bc96f4 node tests: Extract get_results() helper. 2021-03-16 09:04:26 -04:00
Abhijeet Prasad Bodas 9223dced3b refactor: Rename filter to linkifier in frontend code and docs.
This only leaves `page_params.realm_filters`, which
will be changed in further commits along with the
API change.
2021-03-15 11:19:59 -07:00
Steve Howell 9a6cb441e1 node tests: Remove misleading subscribed fields.
The stream_data.create_streams() helper ignores
these booleans, so they are just confusing for
debugging purposes.
2021-03-15 13:05:49 -04:00
Steve Howell 0dc597bceb node tests: Move data setup higher in the file. 2021-03-15 13:05:49 -04:00
Steve Howell ece986bd10 node tests: Clear data for sort_recipients. 2021-03-15 13:05:49 -04:00
Steve Howell af292d550f node tests: Clean up render tests for typeahead_helper. 2021-03-15 13:05:49 -04:00
Steve Howell 3b75674b08 node tests: Localize all_obj consts. 2021-03-15 13:05:49 -04:00
Steve Howell d7d357f61e node tests: Add test_all() wrapper for widgetize.
I also move around a couple set_global/mock_esm
calls.
2021-03-15 13:05:49 -04:00
Steve Howell 09bad82131 node tests: Add test() wrapper for typing_data. 2021-03-15 13:05:49 -04:00
Steve Howell deaf633b04 node tests: Call initialize_state() earlier.
This makes the test re-runnable.
2021-03-15 13:05:49 -04:00
Steve Howell 198c67a9bd node tests: Split up tutorial into smaller examples.
I didn't bother to keep the very last test from
tutorial, which has some complications related
to clearing stream_list data and was kind of
overkill.
2021-03-15 10:46:00 -04:00
Nikhil Maske f5544e36ed markdown: Add fa-clock icon before markdown timestamps.
These sigils will help make it easier to see that this is a special
Zulip syntax feature, not just something the other user typed, which
might help set the expectation that we're showing the time in the
user's timezone.

Tweaked by tabbott to improve variable/template naming.
2021-03-14 22:57:01 -07:00
Steve Howell bbe12a3967 node tests: Ensure clean data for timerender tests.
We explicitly initialize things that future tests
could possibly mutate.
2021-03-14 11:38:21 -04:00
Steve Howell 7bb861303a node tests: Add test() wrapper to compose_actions.
I also do s/Bob/Steve/ in a test to avoid any
confusion about intra-test leaks.

In passing I clean up the dubious reply_to
fields.
2021-03-14 11:38:21 -04:00
Steve Howell 9db20afd19 node tests: Clean up stream_events.
* hoist dev_help
* extract narrow_to_frontend()
* use more explicit setup
* add test() wrapper
2021-03-14 10:46:45 -04:00
Steve Howell ce9c31ca6b node tests: Clean up settings_org.
I add a test() wrapper and use override()
more liberally.
2021-03-14 10:46:45 -04:00
Steve Howell f9101c91b5 node tests: Remove needless reset test.
We want to reset in the main test here to ensure
a clean slate, and doing so makes the other
test redundant.
2021-03-14 10:46:45 -04:00
Steve Howell 92e611a787 node tests: Add test() wrapper for lightbox. 2021-03-14 10:46:45 -04:00
Steve Howell 63a0f6b352 node tests: Extract override_random_id. 2021-03-14 08:11:25 -04:00
Steve Howell ae6c435bb4 node tests: Clean up hashchange tests.
* use override
* localize window_stub
* add clear_for_testing() helper
2021-03-14 08:11:25 -04:00
Steve Howell 45c433b346 node tests: Clean up drafts tests.
I add a test() wrapper and clean up some
of the date-related code.
2021-03-14 08:11:25 -04:00
Steve Howell 569a68a057 node tests: Clean up buddy_data tests.
We mostly add the test() wrapper to give
each test a clean slate.
2021-03-14 08:11:25 -04:00
Steve Howell 85bd196bfc node tests: Add test() wrapper to bot_data. 2021-03-14 08:11:25 -04:00
Steve Howell 612f79ea6f node tests: Add env var to components test.
This makes it easier to run the test multiple
times.
2021-03-14 08:11:25 -04:00
Steve Howell c0f2315dd5 node tests: Avoid __Rewire__ in stream_list. 2021-03-13 14:47:49 -05:00
Steve Howell 5f6b0bc831 node tests: Avoid __Rewire__ in stream_edit. 2021-03-13 14:47:49 -05:00
Steve Howell b1d59237b9 node tests: Avoid __Rewire__ call in drafts.. 2021-03-13 14:47:49 -05:00
Steve Howell 4b62f8c90f node tests: Avoid __Rewire__ in compose_actions. 2021-03-13 14:47:49 -05:00
Anders Kaseorg 9275489134 zjsunit: Truncate the stack trace only at run_one_module.
Commit 5bd73ce190 (#17367)
unintentionally truncated more of the traceback rather than less when
there’s more than one Module._compile frame.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-13 14:44:13 -05:00
Steve Howell 9c3f526fae node tests: Explicitly set hash for billing test. 2021-03-13 11:48:50 -05:00
Steve Howell fbd3669461 zjsunit: Do not run $(...) automatically.
We have generally gone away from using $(...)
initialization in modules that we test with
zjsunit, but there are a few remaining special
cases related to our billing and portico
codebases.
2021-03-13 11:48:50 -05:00
Steve Howell bc8647539c code cleanup: Remove obsolete stream_sort code.
I remove an obsolete comment--we use get_streams()
for the `n` key now.

I also remove a guard statement from sort_groups()
that returned `undefined` for empty lists.

That guard statement would break this code:

    const stream_groups = stream_sort.sort_groups(streams, get_search_term());

    if (stream_groups.same_as_before && ...

The calling code prevents the situation anyway:

    const streams = stream_data.subscribed_stream_ids();
    if (streams.length === 0) {
        return;
    }

I modify the "no_subscribed_streams" test to test
the new behavior.  (Even though stream_list currently
short-circuits the call here, that may change in the future.)

I also introduce the test() wrapper to explicitly clear
our data.
2021-03-13 11:48:50 -05:00
Steve Howell 9c4d7b3bd4 node tests: Add test() wrapper for stream_topic_history. 2021-03-13 11:48:50 -05:00
Steve Howell e5669f9087 zjsunit: Extract complain_about_unused_mocks.
This is prep toward allowing individual tests
to fail while continuing to run the test suite.

Most of the steps in namespace.finish() could
be put in a `finally` block, but once a test
fails, there's no reason to complain about
unused mocks, since there are bigger things
to address.
2021-03-13 08:59:06 -05:00
Anders Kaseorg e0f0b7f4a7 puppeteer_lib: Remove jQuery dependency from select_item_via_typeahead.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-13 07:02:00 -05:00
Anders Kaseorg 812adba5a3 puppeteer_lib: Remove jQuery dependency from get_rendered_messages.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-13 07:02:00 -05:00
Anders Kaseorg 73ca1afc53 puppeteer_lib: Remove wait_for_text.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-13 07:02:00 -05:00
Anders Kaseorg 054f8f8151 puppeteer_lib: Remove jQuery dependency from get_text_from_selector.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-13 07:02:00 -05:00
Anders Kaseorg 4434e2c687 puppeteer_lib: Remove jQuery dependency from pm_recipient.set.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-13 07:02:00 -05:00
Steve Howell bfb06c939c node tests: Add test() wrapper for topic_list_data. 2021-03-12 17:52:04 -05:00
Riken Shah 3a386fcf44
puppeteer_tests: Fix invalid/incorrect selector for `waitFor`.
We're trying to wait for the subscriptions overlay to close, so we should actually do that.
2021-03-12 13:26:39 -08:00
Steve Howell a0534b5b03 node tests: Clean up all_topics_in_cache test.
We use override() and clear the message data
explicitly.
2021-03-12 15:29:23 -05:00
Steve Howell 88357579fe node tests: Add test() wrapper for stream_data. 2021-03-12 15:29:23 -05:00
Steve Howell 154daf353b node tests: Add test() wrapper for suggestions. 2021-03-12 15:29:23 -05:00
Steve Howell 9c1e21689b node tests: Use override in search_suggestion. 2021-03-12 15:29:23 -05:00
Riken Shah 812d563bd4 puppeteer_test: Add missing `waitFor` to avoid occasional flakes. 2021-03-12 12:14:37 -08:00
Riken Shah 6421c1d8d9 puppeteer_test/16: Fix "not secure" warning hiding the button.
When typing the password in Firefox,
it shows a "Not Secure" warning which was
hiding the "#get_api_key_button". You can see
the screenshot of it in #17136.

This commit fixes that issue by focusing on the button.
2021-03-12 12:14:37 -08:00
Riken Shah d2980f1042 puppeteer_test/16: Fix `:focus` not working with Firefox.
This commit works around the issue of
`#change_password_modal:focus` not working
for some strange reason with Firefox.
2021-03-12 12:14:37 -08:00
Riken Shah 5e98f80dc3 puppeteer_test: Transform jQuery to puppeteer functions for Firefox.
This commit converts some jQuery code
to builtins puppeteer functions because
it was not working with Firefox.
2021-03-12 12:14:37 -08:00
Anders Kaseorg 37bd04054f zjsunit: Try to document the difference between CJS and ES modules.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-12 11:18:13 -08:00
Anders Kaseorg ea9ca6b7d0 js: Use jQuery as a module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-12 10:08:25 -08:00
Anders Kaseorg ac36d59728 node_tests: Move set_global mock in components before zrequire call.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-12 10:06:34 -08:00
Anders Kaseorg 92a46888f0 node_tests: Mock sortablejs to avoid __Rewire__.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-12 10:06:34 -08:00
Anders Kaseorg 5fc8a12d7b node_tests: Mock clipboard to avoid __Rewire__.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-12 10:06:34 -08:00
Anders Kaseorg 7529491c67 node_tests: Mock @uppy/core to avoid __Rewire__.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-12 10:06:34 -08:00
Anders Kaseorg 5251fa81fb zjsunit: Lift restriction against mocking CJS modules.
Factor out mock_cjs from mock_esm because adding __esModule prevents
mocks for CJS modules from being imported correctly.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-12 10:06:34 -08:00
Anders Kaseorg 876806eb4d zjsunit: Lift restriction against mocking third party modules.
Use fully resolvable request paths because we need to be able to refer
to third party modules, and to increase uniformity and explicitness.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-12 10:06:30 -08:00
Steve Howell 87a3650176 node tests: Clean up recent_senders test.
This introduces the make_stream_message()
helper to avoid all the strange
`messages[0] === message1` confusion.

We also clear data explicitly at the beginning
of the test.

It's still a messy test.
2021-03-12 11:18:44 -05:00
Steve Howell bae508d1c9 node tests: Explicitly set filters for markdown test. 2021-03-12 11:18:44 -05:00
Steve Howell d1d0742e0a node tests: Move test to fenced_code.js. 2021-03-12 11:18:44 -05:00
Steve Howell 6cb255b559 node tests: Use clean data in reaction tests.
A bunch of tests were mutating the same message.
Now they just make their own copy.

I introduce the name "sample_message" for the common
message, but I remove the two bogus reactions, and
the "warning" test now just creates its own
test-specific data.
2021-03-12 11:18:44 -05:00
Steve Howell f5506c78aa node tests: Clear data for presence tests.
I considered using set_info({}, 0) to clear data,
but it has a lot of machinery that could lead
to accidental line coverage and/or extra test
complexity.
2021-03-12 11:18:44 -05:00
Steve Howell bbf529f2a5 node tests: Clear data for pm_list tests. 2021-03-12 11:18:44 -05:00
Steve Howell 67a5fe95dc minor: Remove empty pm_list.initialize().
The commit 3cfc3ca24b
made this function do nothing, but I guess that
we thought we might resurrect the click handler
in the short term.  We never did.
2021-03-12 11:18:44 -05:00
m-e-l-u-h-a-n e781136acd css: Add separate class for typeahead items with no presence circle.
This commit adds a new class for typeahead items that do not need
a presence circle. It is changed to support addition of new items
that do not require presence circle.

There should not be any visual change due to this.
2021-03-12 02:10:21 -08:00
Steve Howell d1e0aa1aa5 node tests: Break up password tests.
This diff is slightly noisy due to hoisting
one helper, but it's hoisted verbatim.
2021-03-12 04:42:37 -05:00
Steve Howell a97cfd06c0 node tests: Clean up muting tests.
* move one test below setup
    * add a test() wrapper to clear mutes
    * split up a test
    * use two different dates for java vs. gossip
    * deterministically sort by date

All these changes make it so that the order of
the tests is a lot less fragile.
2021-03-12 04:42:37 -05:00
Steve Howell 950effbb57 node tests: Add overrides for message_flags. 2021-03-12 04:42:37 -05:00
Steve Howell 71ccb99531 node tests: Clean up pm_conversations.
* Hoist zrequire("people") to the top.
    * Add clear_for_testing() hook.
    * Add initialize_recents() helper.
2021-03-12 04:42:37 -05:00
Steve Howell 7f700b6f5a minor: Use override in people_errors. 2021-03-12 04:42:37 -05:00
Steve Howell 0c2aa1d3e8 node tests: Clean up electron-related code. 2021-03-12 04:42:37 -05:00
Steve Howell 26fed458e6 node tests: Clean up dispatch tests.
These are minor cleanups to make tests more
idempotent.
2021-03-12 04:42:37 -05:00
Steve Howell b13af16ad0 node tests: Tweak test() wrapper.
We do the initialization inside run_test(),
so that if it fails, we see it as happening
within the test.
2021-03-12 04:42:37 -05:00
Steve Howell f5488b98eb node tests: Clean up robust_uri_decode. 2021-03-12 04:42:37 -05:00
Anders Kaseorg 4256567b4a puppeteer_tests: Correct {visible: false} to {hidden: true}.
{visible: false} just redundantly specifies the default behavior,
which is to wait for the selector to be present regardless of
visibility.  We want to wait for these selectors to be hidden.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-11 21:05:54 -08:00
Aman Agrawal e587c029f6 display_settings: Allow user to set default_view.
TextField is used to allow users to set long stream + topic narrow
names in the urls.

We currently restrict users to only set "all_messages" and
"recent_topics" as narrows.

This commit achieves 3 things:
* Removes recent topics as the default view which loads when
  hash is empty.
* Loads default_view when hash is empty.
* Loads default_view on pressing escape key when it is unhandled by
  other present UI elements.

NOTE: After this commit loading zulip with an empty hash will
automatically set hash to default_view.  Ideally, we'd just display
the default view without a hash, but that involves extra complexity.

One exception is when user is trying to load an overlay directly,
i.e. zulip is loaded with an overlay hash. In this case,
we render recent topics is background irrespective of default_view.

We consider this last detail to be a bug not important enough to block
adding this setting.
2021-03-11 18:09:08 -08:00
Steve Howell d74266ac75 zjsunit: Simplify zjquery patching.
This makes it so that we can bypass the Proxy
object in zjquery with less code in namespace.js.
2021-03-11 13:00:30 -05:00
Steve Howell a4ab6065cd node tests: Clear data for peer_data tests. 2021-03-10 07:07:34 -05:00
Steve Howell 1064690999 node tests. Use clean data for unread tests. 2021-03-10 07:07:34 -05:00
Steve Howell 164db57be1 node tests: Clear state in narrow_unread test. 2021-03-10 07:07:34 -05:00
Steve Howell dd7420ff11 minor: Don't export unread_topic_counter.
The only places we called it now use the
helper function.

In passing I move another const to the top
of the file.
2021-03-10 07:07:34 -05:00
Steve Howell 18dcdf1df5 node tests: Clear data for narrow_state tests. 2021-03-10 07:07:34 -05:00
Steve Howell 4621e54059 node tests: Clear data for message_store tests. 2021-03-10 07:07:34 -05:00
Steve Howell c6dc9e9014 refactor: Remove message_store.each helper. 2021-03-10 07:07:34 -05:00
Steve Howell da10d42f8a node tests: Remove unneeded set_global for pointer.
We eliminated the global pointer a while back.

In passing I move the remaining set_global calls
together.
2021-03-10 07:07:34 -05:00
Anders Kaseorg 59e5e9ba35 zjsunit: Move mock clearing to namespace.finish.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-10 07:07:34 -05:00
Anders Kaseorg 1b58f5a700 zjsunit: Remove objs_installed flag.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-10 07:07:34 -05:00
Anders Kaseorg 1689c57cc4 zjsunit: Fix filename resolution in _load hook.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-10 07:07:34 -05:00
Anders Kaseorg f4d38bc39f zjsunit: Add unmock_module function.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-10 07:07:34 -05:00
Anders Kaseorg e18171e1c5 zjsunit: Rename mocked_paths to used_module_mocks.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-10 07:07:34 -05:00
Anders Kaseorg d40bbde51c zjsunit: Remove redundant mock_names set.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-10 07:07:34 -05:00
Anders Kaseorg 3551cc5679 zjsunit: Convert mock_paths object to a Map.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-10 07:07:34 -05:00
Anders Kaseorg 7218a06cab zjsunit: Install Module._load hook in namespace.start.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-10 07:07:34 -05:00
Anders Kaseorg 6540285a9c channel: Sever dependency on reload.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-09 17:43:07 -08:00
Steve Howell b55a77f1cd node tests: Avoid test leaks in filter.
We want to be careful about MIT code, as it leads
to more lax checks in the filter code.

And then we just use with_field in a couple places
and clear subscriptions.
2021-03-08 14:03:39 -05:00
Steve Howell b2efb2e7b2 node tests: Localize MockDate.set call for echo test. 2021-03-08 14:03:39 -05:00
Steve Howell 0e4bf2cf53 node tests: Avoid test leaks for people. 2021-03-08 13:06:52 -05:00
Steve Howell 8c6469314b node tests: Avoid intra-test leaks in buddy_data. 2021-03-08 10:45:17 -05:00
Steve Howell f6f251671a node tests: Avoid intra-test leaks for alert_words. 2021-03-08 10:45:17 -05:00
Steve Howell ab34f63ad5 node tests: Clear pending channel requests. 2021-03-08 10:45:17 -05:00
sahil839 9a432b0c3b events: Remove name field from update subscription events.
This commit removes name field from update subscription
events, as it is not used by any of the clients, and use
stream_id in the events code instead.
2021-03-07 22:03:24 -08:00
Steve Howell 9c8fa3930f node tests: Eliminate many __Rewire__ calls.
For most functions that we were using __Rewire__ for,
it's better to just use the override helper, which
use __Rewire__ under the hood, but also resets
the reference at the end of run_tests.

Another nice thing about override() is that it reports
when you never actually needed the mock, and this
commit fixes the instances found here.

I didn't replace every call to __Rewire__. The
remaining ones fall under these categories:

    * I looked for ") =>" in my code sweep,
      so I missed stuff like "noop" helpers.

    * Sometimes we directly update something
      in a module that's not a function. This
      is generally evil, and we should use setters.

    * Some tests have setup() helpers or similar
      that complicated this code sweep, so I
      simply punted.

    * Somes modules rely on intra-test leaks. We
      should fix those, but I just punted for the
      main code sweep.
2021-03-07 11:19:33 -05:00
Steve Howell 8ab5475b37 zjsunit: Allow multiple overrides again.
I now let folks override the same target multiple
times inside of `with_overrides` (and then indirectly
inside of `run_test`.)

I may re-impose this restriction in the future, since
most violations are due to code smells, but there are
a few legitimate use cases for this, and the code
can handle it, plus I want to remove some other
ugliness first.
2021-03-07 11:19:33 -05:00
Steve Howell eea78df688 node tests: Clean up mock_module calls.
This is a deceptively ugly diff.  It makes
the actual code way more tidy.

I basically inlined some calls to mock_module
and put some statements in lexical order.
2021-03-07 09:35:58 -05:00
Steve Howell 7cf62cd6b1 node tests: Avoid __Rewire__ for clipboard API. 2021-03-06 14:33:30 -05:00
Steve Howell f54f7cfc33 node tests: Introduce mock_module helper. 2021-03-06 13:15:04 -05:00
Steve Howell 167fda142c node tests: Remove __esModule cruft.
We just set __esModule in our rewiremock helper.
2021-03-06 12:36:07 -05:00
Steve Howell 30c7108955 zjsunit: Remove rewiremock dependency.
We now just use a module._load hook to inject
stubs into our code.

For conversion purposes I temporarily maintain
the API of rewiremock, apart from the enable/disable
pieces, but I will make a better wrapper in an
upcoming commit.

We can detect when rewiremock is called after
zrequire now, and I fix all the violations in
this commit, mostly by using override.

We can also detect when a mock is needlessly
created, and I fix all the violations in this
commit.

The one minor nuisance that this commit introduces
is that you can only stub out modules in the Zulip
source tree, which is now static/js.  This should
not really be a problem--there are usually better
techniques to deal with third party depenencies.
In the prior commit I show a typical workaround,
which is to create a one-line wrapper in your
test code.  It's often the case that you can simply
use override(), as well.

In passing I kill off `reset_modules`, and I
eliminated the second argument to zrequire,
which dates back to pre-es6 days.
2021-03-06 11:10:57 -05:00
Steve Howell 8006c29748 node tests: Extract create_sortable for testing. 2021-03-06 11:10:57 -05:00
Steve Howell e81bf846a9 node tests: Remove ui_init test.
I created this test in Jan 2019 with
6b7a4f8611.

At the time I created this we were still migrating modules
over from using the $(() => {...}) style of initialization,
so the test served a purpose as an easy smoke test that we
weren't doing something really stupid in
ui_init.initialize().

Now that that migration is complete, the test's warts start
to outweigh its benefits.  Because it's just a smoke test,
we get credit for artificial line coverage where we're
exercising code without actually verifying anything other
than that it runs without crashing.

There are still possibilities for bugs within
ui_init.initialize() where we initialize modules in the
wrong sequence, but I am not confident that the node test
would catch them with any more likelihood (or clarity) than
either the puppeteer tests or czo bug reports.

And then on top of that, the zjquery setup in the node test
is hard to maintain. It's also hard to verify that some
of the setup isn't cruft.

If you want to see how much of a maintenance headache this
has been in recent times, just look at how many of the
recent commits have been related to things like es6
migrations or code cleanup sweeps.

We should just kill it.
2021-03-06 05:43:39 -05:00
Steve Howell 5b2d48aedb node test: Extract compose_video tests. 2021-03-05 18:33:01 -05:00
Josh Gilley de74d2fd7c settings: Use HTML table for "Alert Words" for better icon alignment.
"Alert Words" is one of Zulip's oldest settings UI elements, and as a
result is buggy.  This commit converts it to use our standard
progressive-table-wrapper system used for settings tables, which has
the side effect of fixing a bug that mad ethe tables look pretty bad
if one adds a very long word.

Fixes #17172.
2021-03-05 14:38:56 -08:00
Steve Howell ff09d8af03 node tests: Test empty string for input_pill. 2021-03-05 12:57:20 -05:00
Steve Howell f6edaaab96 node tests: Test upload.feature_check directly. 2021-03-05 12:57:20 -05:00
Steve Howell 779f56d411 node tests: Add test for compose_state. 2021-03-05 12:57:20 -05:00
Steve Howell 886e419731 node tests: Directly test how we add/remove rtl class. 2021-03-05 12:57:20 -05:00
Anders Kaseorg 62532777b1 server_events: Replace deprecated $.now alias.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-04 18:07:47 -08:00
m-e-l-u-h-a-n f4a111e314 compose: Add user presence circles in mention and pm typeahead.
This commit addresses the problem of user's status visibility to
some extent. It adds presence circles, like we have in buddy_list to the
typeahead suggestions that are given for mentioning users in messages.

Tweaked by tabbott to adjust vertical alignment of group mentions as well.

Testing for the changes is done manually in the developement server,
and also by updating frontend tests to address these changes.

Fixes: #17138
2021-03-04 17:06:02 -08:00
Riken Shah d12257e2c1 puppeteer_test: Add missing `await` checking compose content.
assert_compose_box_content should always be called with await.
2021-03-04 09:41:49 -08:00
Riken Shah b23cd2b7d4 puppeteer_test: Skip tests that require file upload for Firefox.
Right now Firefox does not support file upload with puppeteer.
2021-03-04 09:41:24 -08:00
Riken Shah dc5095bad9 puppeteer_test: Add `waitForNavigation` when reloading.
This commit ensures that it waits until the
page is reloaded which avoids uncertain
flake.
2021-03-04 09:40:14 -08:00
Riken Shah de96aeb822 puppeteer_test: Fix `page.url()` for Firefox.
This commit works around an issue with Puppeteer tests on Firefox
where `page.url()` does not show the URL fragment, by adding a
temporary function that solves the issue.
2021-03-04 09:40:14 -08:00
Riken Shah a6c1f02df0 puppeteer_test: Add `is_firefox` option to enable/disable some tests.
This commit introduces the `is_firefox`
option in CommonUtils to identify if a browser
is Firefox or not.

This helps us to avoid calling some tests
that is yet not compatible with Firefox.
2021-03-03 22:04:16 -08:00
Riken Shah 6676aa2f90 puppeteer_test: Change browser default viewport to allow Firefox.
When we run puppeteer with Firefox,
the `--window-size` option does not work,
which makes the bottom part of
the page cut off.

This commit fixes this issue
by setting the screen default viewport
to the maximum size of the window.
2021-03-03 22:01:36 -08:00
Steve Howell b1a871f2e0 node tests: Avoid reset_module for recent_topics. 2021-03-03 07:08:51 -05:00
Anders Kaseorg cce3257f2c zjsunit: Remove babel-plugin-lazy-require.
There are no more require() calls in tested modules.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-02 17:06:35 -08:00
Anders Kaseorg 099e8fb00e js: Convert static/js/settings_profile_fields.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-02 17:06:35 -08:00
Anders Kaseorg 7ec8b8980f js: Convert static/js/dropdown_list_widget.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-02 17:06:35 -08:00