Commit Graph

3520 Commits

Author SHA1 Message Date
Anders Kaseorg 0ca543396a zjsunit: Use clear_zulip_refs as the main way to undo zrequire.
Move clear_zulip_refs into restore, and rewrite it without lodash.  We
no longer need the requires array, and zrequire is now nothing more
than a wrapper around require.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-22 10:53:49 -08:00
Anders Kaseorg 7011f0911d node_tests: Fix misspelled pm_conversation global.
It’s pm_conversations.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-22 10:17:03 -08:00
Steve Howell ff3175f8a2 lightbox: Export method for testing purposes.
We weren't exercising this method in any
meaningful way during the tests, and when
do add coverage, we probably want to just
test it directly.

We also kill off stub_selector(), which was
never well-documented.
2021-02-22 12:38:07 -05:00
Steve Howell aed5b65525 node tests: Avoid use of stub_selector.
We will eliminate this soon.
2021-02-22 12:38:07 -05:00
Steve Howell d62ef78e9c node tests: Avoid stub_selector() in activity tests. 2021-02-22 12:38:07 -05:00
Steve Howell 42c2c9fb2d zjquery: Avoid array-related hacks.
Callers can either explicitly pass in children,
stub out $(...)[0] as needed, or just
circumvent jQuery complications with override.

Note the reactions test was broken before,
since $(...)[0] was always returning the same
stub.
2021-02-22 12:38:07 -05:00
Aman Agrawal 2b8921bf67 zjquery: Tell user why using tags as selector is invalid.
Like using $('input') is too broad a selector and shouldn't
be used in the codebase. With this error messages, contributors
can easily understand that now.
2021-02-22 10:24:59 -05:00
Aman Agrawal 269457c58b zjquery: Extract func to verify selector. 2021-02-22 10:24:59 -05:00
Steve Howell 914533c8bc zjsunit: Prevent common mistakes with overrides.
We only allow you to replace functions with functions,
unless you have used set_global() or are dealing
with $ from zjquery.
2021-02-22 10:04:29 -05:00
Steve Howell 5caee967d3 zjquery: Remove bogus after/before functions. 2021-02-22 10:04:29 -05:00
Steve Howell 132e67cb28 zjquery: Prohibit extensions to $.fn.
We make an exception for the popovers code.

Luckily it's pretty rare that we extend $.fn
in our real code.
2021-02-22 10:04:29 -05:00
Steve Howell 89ab76920f zjquery: Prevent direct patches to $.
We prohibit code from making direct patches to
$ unless you use override().
2021-02-22 10:04:29 -05:00
Steve Howell b40d8d5790 node tests: Inline setup for settings_bots.
I also use override in more places, and I add
$.validator to zjquery.

In passing I clean up some IIFEs that aren't
really needed.
2021-02-22 10:04:29 -05:00
Steve Howell 38e3aa490f node tests: Use override for $.post. 2021-02-22 10:04:29 -05:00
Steve Howell 623500bae1 node tests: Avoid zjquery for channel tests.
We create our own stub for $.ajax.
2021-02-22 10:04:29 -05:00
Steve Howell 0ffbea8650 node tests: Break up channel tests. 2021-02-22 10:04:29 -05:00
Steve Howell ffe1043bcc zjsunit: Remove stub_out_jquery.
We now either use zjquery or do whatever gross
things we need to do to work past document.trigger(...)
calls or $.now calls explicitly in the tests.
2021-02-21 17:34:55 -05:00
Steve Howell 64c7eb67eb zjquery: Make zjquery a singleton.
We no longer export make_zjquery().

We now instead have a singleton zjquery instance
that we attach to global.$ in index.js.

We call $.clear_all_elements() before each module.
(We will soon get even more aggressive about doing
it in run_test.)

Test functions can still override $ with set_global.
A good example of this is copy_and_paste using the
real jquery module.

We no longer exempt $ as a global variable, so
test modules that use the zjquery $ need to do:

    const $ = require("../zjsunit/zjquery");
2021-02-21 17:34:55 -05:00
Steve Howell 2e3406f0b8 node tests: Eliminate "silent" option for zjquery.
The "silent" option was kind of evil, as it had
$(...).find(...) passing back "self" instead of a stub.

Now we just use $(...).set_find_results(...) or
override(...) to simulate/bypass drawing code.

(It turns out hash_util didn't even need this option.)
2021-02-21 15:11:31 -05:00
Steve Howell 706e2baf7e node_test: Avoid make_zjquery.
We just use $.clear_all_elements() now.
2021-02-21 15:11:31 -05:00
Steve Howell 9938811759 node tests: Avoid $ override for compose test.
We just use zjquery now.
2021-02-21 15:11:31 -05:00
Steve Howell 895179e8f6 node tests: Make setup for ui_init more local. 2021-02-21 15:11:31 -05:00
Steve Howell b72575d98b node tests: Fix zjquery leaks in stream_list. 2021-02-21 15:11:31 -05:00
Steve Howell 496932bfc6 node tests: Share setup helpers for stream_list. 2021-02-21 15:11:31 -05:00
Steve Howell d207d71753 node tests: Make setup for stream_edit more local. 2021-02-21 15:11:31 -05:00
Steve Howell 3829ab0ea9 node tests: Fix zjquery leaks for popovers. 2021-02-21 15:11:31 -05:00
Steve Howell fc29ee02c8 node tests: Fix zjquery leaks in compose_actions. 2021-02-21 15:11:31 -05:00
Steve Howell 2fc8e134f5 node tests: Fix zjquery leaks in common. 2021-02-21 15:11:31 -05:00
Steve Howell 569b12439d node tests: Fix zjquery leaks in alert_words_ui. 2021-02-21 15:11:31 -05:00
Steve Howell 0124264a9e node tests: Prevent zjquery leaks in activity tests. 2021-02-20 17:33:51 -05:00
Steve Howell faa1d0d96d node tests: Fix zjquery leaks in buddy_list test. 2021-02-20 12:00:24 -05:00
Steve Howell 5bd73ce190 zjsunit: Show more of the traceback.
We still reduce a lot of clutter, but this
shows wrappers around `run_test` now.
2021-02-20 12:00:24 -05:00
Steve Howell 490894475e node tests: Prevent zjquery leaks in pm_list.
We weren't leaking anything, but this change
prevents future leaks.
2021-02-20 10:29:30 -05:00
Steve Howell d34723987f node tests: Make sure we try to find container in pm_list. 2021-02-20 10:29:30 -05:00
Steve Howell 7e4d784888 node tests: Use override/with_field in pm_list. 2021-02-20 10:29:30 -05:00
Steve Howell 7c408bc525 node tests: Use override in buddy tests. 2021-02-19 10:06:44 -05:00
Steve Howell fed1eaf7d7 minor: Inline filter_table in subs.js.
The old structure of having a two-line wrapper was
mostly driven by testing concerns.  Now I just
have a single function with the optional argument.
2021-02-18 13:38:16 -08:00
Steve Howell 374d2ff3e2 stream settings: Fix tooltips for stream counts.
The tooltips for the left panel of stream settings
have been broken since November 2018 due to my
commit 8f915da2ca.

The code prior to 2018 was restoring tooltips
right inside the loop where we were detaching
the row from the DOM to put it back into the
DOM at another place.  And then I tried to
just add them in bulk, forgetting that I was
in the middle of all the DOM manipulation (and
hence my selector for the loop was a noop).

Also, I don't think we've ever had them for live
events that add streams.  (I fixed that too.)

It's not clear to me that this code is actually
necessary, as we get hover help without
calling $(...).tooltip(...) properly.

This is probably why we didn't notice any
breakage when we merged my 2018 commit.
2021-02-18 13:38:16 -08:00
Steve Howell b4ab662442 puppeteer: Make subscribe/unsubscribe test more robust.
We generally want to avoid clicking on DOM elements
that may not actually be visible due to the prior
operation.  Instead, we can just find the visible
element after each step.

I also introduce a couple helper functions to
de-clutter the click/unclick/click steps, and I do
a couple extra clicks for good measure.

You can verify that the test will fail if you
add an early return to update_check_button_for_sub.
2021-02-18 11:05:46 -05:00
Steve Howell 34b429dfd5 node tests: Simplify subs tests for filtering.
This is prep for future simplifications to the
real code.
2021-02-16 13:11:10 -08:00
Steve Howell dad90fe770 node tests: Extract locals for stream names.
This just makes the next diff smaller.  It makes
sense on its own to just flatten the code.
2021-02-16 13:11:10 -08:00
Steve Howell 0e4ba368e0 node tests: Remove tooltips logic in subs test.
The zjquery setup here isn't worth the complexity here.

The function being tested just does a simple jQuery
loop.
2021-02-16 13:11:10 -08:00
Steve Howell 62e272ce27 stream settings: Remove obsolete scrolling code.
We just want to reset the scrollbar here, which
we still do via ui.reset_scrollbar.

You don't want to preserve scroll position if
you are filtering or re-sorting.
2021-02-16 13:11:10 -08:00
Steve Howell 9862156158 stream settings: Clean up functions to redraw left panel.
We have long had this annoying two-pass way of building the
DOM that I am trying to eliminate.

The function names that I introduce here describe the current
situation more accurately.

In passing I make it so that we only throttle redraws when
users are actually typing.  Using a throttled redraw when
you click on the sort icons is at best unnecessary, and it
may actually aggravate double clicks.
2021-02-16 13:11:10 -08:00
Abhijeet Prasad Bodas 674a5fef54 node tests: Split draft_model for add/edit/delete cases.
This splits the one big `run_test` block into
add/edit/delete parts, for better clarity.

This also removes the `with_field` calls and
uses the override style instead, which is
preferred because it makes sure the stubbed
function is actually called.
2021-02-14 09:13:24 -05:00
Abhijeet Prasad Bodas 8cc0b435e5 node tests: Remove unecessary with_field call in pm_list.
After eeee6edf41, `is_all_privates`
isn't called from the `update_private_messages`
path, and doesn't need to be stubbed.
2021-02-14 09:13:24 -05:00
Abhijeet Prasad Bodas 6c6def2dcc node tests: Prefer override over with_field.
This commit replaces `with_field` calls to
use the override style instead.
`override` is preferred since it makes sure
the stubbed function is actually called,
while `with_field` doesn't, which makes it
hard to spot dead code.
2021-02-14 09:13:24 -05:00
Steve Howell 2ad879cdda node tests: Use override in echo.js. 2021-02-13 12:48:15 -08:00
Steve Howell 9698fec008 node tests: Use override for snapshot_message.
Using override ensures that the real code actually
calls the stubs here.

The one-line map() helper avoids some ugliness
from "prettify".
2021-02-13 08:50:10 -05:00
Abhijeet Prasad Bodas c183076a91 minor: Suggest with_field instead of override for non-functions. 2021-02-13 07:28:26 -05:00