Commit Graph

3602 Commits

Author SHA1 Message Date
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
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
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
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
0d770c32cc node tests: Explicitly call make_stub.
This commit replaces all `with_stub` calls and
explicitly calls `make_stub` instead.
The `with_stub` helper does not add much clarity
hence we now use scoped stub objects instead.

This de-indents some blocks where scoping isn't
required, for example when there is a single
stub object inside a `run_test` function.

With this change, we also need to explicitly
assert `num_calls`.
2021-02-13 06:48:59 -05:00
Steve Howell
183c51ba51 node tutorial: Add make_stub example. 2021-02-12 12:11:23 -05:00
Steve Howell
a5a5863bde node tutorial: Use override in helpers. 2021-02-12 12:11:23 -05:00
Steve Howell
69ddf68f4d node tutorial: Inline setup.
This code didn't make sense to run inside its own
run_test wrapper.
2021-02-12 12:11:23 -05:00
Steve Howell
118a212af8 node tutorial: Add with_field example. 2021-02-12 12:11:23 -05:00
Steve Howell
7672e7dd7b node tutorial: Use override() more.
This is just a better practice.
2021-02-12 12:11:23 -05:00
Steve Howell
ba7e49c20e node tutorial: Use set_global for overlays. 2021-02-12 12:11:23 -05:00
Steve Howell
70fb1c225b minor: Clarify that message_store is a deep test.
I believe the original message_store example used
to stub some things here, but the part of the tutorial
that pertains to stubbing is further down.
2021-02-12 12:11:23 -05:00
Steve Howell
c0874462dc node tests: Rename general.js to tutorial.js. 2021-02-12 12:11:23 -05:00
Steve Howell
90730a18d9 node tests: Simplify stream_events.
These are still kind of a mess.

The old code combined the worst of both worlds:

    - we had one monolithic test
    - we called the events multiple times,
      verifying a different stub each time

Now I make the tests more granular.

We could actually re-combine the tests, but
in a nicer way, so that we just set
up multiple stubs and verify that all stubs
get correctly invoked.
2021-02-11 11:29:21 -05:00
Steve Howell
fcf5a66aeb node tests: Move streams tests to dispatch_subs.
There is also some code cleanup here--in dispatch_subs,
we don't stub stream_data, so it's easier to write
deeper tests that actually validate the data changes.
2021-02-11 11:29:21 -05:00
Steve Howell
90ca1ded13 node tests: Split up dispatch tests. 2021-02-11 11:29:21 -05:00