Commit Graph

136 Commits

Author SHA1 Message Date
Anders Kaseorg 6aec27e646 js: Fix no-jquery/no-parse-html-literal.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-03-17 13:16:34 -07:00
Anders Kaseorg 5d77381667 node_tests: Add a few missing $ prefixes.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-03-17 13:10:23 -07:00
Anders Kaseorg f84a2c08d5 js: Prefix jQuery object variable names with $.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-03-16 12:52:07 -07:00
Anders Kaseorg b0ce4f1bce docs: Fix many spelling mistakes.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-02-07 18:51:06 -08:00
Anders Kaseorg 64abdc199e zjsunit: Split deprecated __Rewire__ functionality out of override.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-01-08 10:01:27 -05:00
YashRE42 717c4ae603 refactor: Remove duplication from reactions.add_clean_reaction.
In commit 3d86267041 we add logic to
`/shared/emoji.js` which duplicated some of the logic in this
function. Since this isn't desirable, we remove the duplicate logic
here and instead just call `emoji.get_emoji_details_for_rendering`.
2021-11-20 20:57:54 -08:00
YashRE42 71a4985ebc refactor: Remove duplication from reactions.view.insert_new_reaction.
In commit 3d86267041 we add logic to
`/shared/emoji.js` which duplicated some of the logic in this
function. Since this isn't desirable, we remove the duplicate logic
here and instead just call `emoji.get_emoji_details_for_rendering`.
2021-11-20 20:57:54 -08:00
YashRE42 bfc705be8f reactions_tests: Remove misleading emoji_params.realm_emoji.zulip obj.
Previously, this test file had an object that encouraged one to
believe that it is defining a realm_emoji with the name, id = "zulip"
and a custom source url, but this is false.
The "zulip" emoji is a special case that's added to our data
structures by the `/shared/emoji.js` code.
Notice how the test never asserts that the returned url is equal to
the source_url defined, it just asserts that the source url is equal
to "/static/generated/emoji/images/emoji/unicode/zulip.png" (which is
the value defined in `/share/emoji.js`).

Hence, we remove this object and replace any references to it with the
values defined in `/shared/emoji.js`.
2021-11-20 20:57:54 -08:00
Aman Agrawal 31de905955 login_to_access: Rename module to `spectators`.
This allows us to call spectators.login_to_access which
is more clear for what it does.
2021-09-07 09:47:28 -07:00
Aman Agrawal a67cff4964 reactions: Don't process clicks from spectators.
The reaction count goes up locally if we don't have this check.
This is misleading for spectators.
2021-09-06 09:00:16 -07:00
Riken Shah 6c003a7802 refactor: Move emoji details related code to `emoji.js`.
As `reaction.js` and `user_status.js` has similar code to
get emoji details, it makes more sense to extract this as a
single function.
2021-07-28 09:35:00 -07:00
Steve Howell 5e824a6d6d node tests: Only expose mock_template via run_test.
We now only expose mock_template as a helper in run_test.

This has the following advantages:

    * less boilerplate at the top of the file
    * more surgical control with setting exercise_templates
    * no more "f" hack (or render_foo consts)
    * we force devs to explicitly mock the template

See frontend_tests/zjsunit for the substantive changes.

All the changes to the tests are very mechanical in nature.
2021-06-27 23:00:34 -04:00
Steve Howell d5c4495fa5 zjsunit: Wire $ to zjquery by default.
I introduce `mock_jquery` for modules that
want their own mock implementation.
2021-06-16 12:55:53 -04:00
Steve Howell 9e657dd795 node tests: Use {override} in run_test. 2021-06-16 12:55:53 -04:00
Steve Howell ddeb15114d zjsunit: Add mock_template helper.
We want to eliminate stub_templates.
2021-06-11 09:54:25 -04:00
Riken Shah f95c539122 custom_check: Avoid use of assert to avoid confusion with assert.equal.
This commit bans the use of `assert` and replaces it
with `assert.ok` to avoid confusion with `assert.equal`.

Fixes #18687.
2021-06-10 09:15:57 -07:00
Aman Agrawal f701bfff28 reactions: Cleanup dead reactions code. 2021-05-20 14:41:40 -07:00
Anders Kaseorg 42abc1b635 dependencies: Upgrade JavaScript dependencies.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-05-10 18:07:13 -07:00
Anders Kaseorg 544bbd5398 docs: Fix capitalization mistakes.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-05-10 09:57:26 -07:00
Steve Howell 58d5778368 node tests: Explicitly set page_params values. 2021-04-03 15:03:00 -04:00
Anders Kaseorg d43ac7357a js: Move current_msg_list, home_msg_list to ES6 module message_lists.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-29 18:23:47 -07:00
Anders Kaseorg 38ffd47b90 js: Convert static/js/page_params.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-26 10:17:56 -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 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 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 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 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 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
Anders Kaseorg 8191915e57 js: Convert static/js/emoji_picker.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg 7145cb4a0d js: Convert static/js/message_store.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg 09920af211 js: Convert static/js/channel.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg 54c97c4457 node_tests: Consistently move set_global mocks before zrequire calls.
This way, as we convert them to rewiremock, they will become available
before they are imported.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-26 07:55:53 -08:00
Steve Howell 092670b278 node tests: Break out view tests for reactions.
The old test here was overly complicated, and
while it got a lot of line coverage, it wasn't
verifying things very precisely.
2021-02-25 13:42:47 -05:00
Steve Howell a577004842 node tests: Test redundant actions in reactions. 2021-02-25 13:42:47 -05:00
Steve Howell e9c94982e0 node tests: Prevent leaking reactions.view functions. 2021-02-25 13:42:47 -05:00
Steve Howell 20203e1bba node tests: Verify Alice's emojis in test. 2021-02-25 13:42:47 -05:00
Steve Howell 737f60e2b7 minor: Add constant for alice_user_id. 2021-02-25 13:42:47 -05:00
Steve Howell f0d6a0d459 node tests: Use better values for emoji urls. 2021-02-25 13:42:47 -05:00
Steve Howell 623accff68 node tests: Use override for message_store.get. 2021-02-25 13:42:47 -05:00
Steve Howell 983f1d66fd node tests: Break up reactions test. 2021-02-24 11:56:40 -05:00
Steve Howell 0ab3649182 reactions: Simplify code to choose popover target.
We now only assign target once, rather than
assigning it then overwriting it for the
not-sent-by-me use case.

I tried to extract a "selector" here but the linter
complained.

Splitting up the tests here ensures we don't
needlessly do extra work here.  (In the prior
clumsy implementation, the second test that
I split out here would fail due to the lack
of us setting up the jquery stub.)
2021-02-24 11:56:40 -05:00
Steve Howell 1a241cef88 node tests: Use array syntax more aggressively. 2021-02-23 09:15:36 -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
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
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
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
Anders Kaseorg 2f6c9b8d0e zjsunit: Change override API to work with non-global modules.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-11 07:35:28 -05:00
Anders Kaseorg 89aa3155a9 node_tests: Don’t read from most deprecated global variables.
We still need to write to these globals with set_global because the
code being tested reads from them, but the tests themselves should
never need to read from them.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-10 07:40:22 -08:00