Commit Graph

391 Commits

Author SHA1 Message Date
Anders Kaseorg a682530fd4 node_tests: Enforce 100% coverage for test files.
This makes it easier to find obsolete parts of the tests that should
be cleaned up.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-04-10 19:31:56 -04:00
Anders Kaseorg 8aed6321bd node_tests: Make localStorage mock common.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-04-10 19:31:56 -04: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 c09bca34b8 frontend_tests: Fix unicorn/text-encoding-identifier-case.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-03-01 23:09:46 -08: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 c6b372b471 js: Simplify indexing arrays from the end with Array#at.
https://github.com/tc39/proposal-relative-indexing-method

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-01-24 09:58:54 -08:00
Anders Kaseorg 0b03628324 js: Shorten Object.prototype.hasOwnProperty.call to Object.hasOwn.
https://github.com/tc39/proposal-accessible-object-hasownproperty

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-01-24 09:57:09 -08:00
Anders Kaseorg 5d01c377f7 zjsunit: Restore necessary ternary conditions.
This reverts part of commit d4c681a937
(#20764).

The ternary conditions are necessary because __Rewire__ can be (and in
fact is) used to patch non-exported variables.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-01-13 14:27:40 -05:00
Steve Howell d4c681a937 zjsunit: Remove unnecessary tertiary conditions. 2022-01-12 13:32:34 -05:00
Steve Howell 047a119d46 zjsunit: Prevent mocking functions with with_field_rewire. 2022-01-10 17:54:29 -08:00
Steve Howell e9640ceb16 zjsunit: Add with_function_call_disallowed_rewire.
Note that we had to fix one place where we were referring
to muted_topics instead of muted_users by accident.
2022-01-10 17:54:29 -08:00
Steve Howell dcffa17e29 test-js-with-node: Simplify failures for --coverage.
When you use nyc, its code instrumentation transforms
the code so that line numbers and columns no longer
make sense, and the long stack trace is likely to cause
more confusion than convenience.

We want to encourage a workflow where you debug your
node tests using the normal (and much quicker mode)
before running `--coverage`.
2022-01-08 10:10:57 -05:00
Anders Kaseorg e17ba5260a zjsunit: Split deprecated __Rewire__ functionality out of with_field.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-01-08 10:01:27 -05: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
Anders Kaseorg cf2649eb85 zjsunit: Pass an object to the with_overrides callback.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-01-08 10:01:27 -05:00
Steve Howell 0574d951e4 node tests: Use set_find_results in stream_edit test. 2021-12-30 11:36:52 -08:00
YashRE42 937d398f4e minor: Fix typo in zjquery_element.js - "zjquery" was "zjuery". 2021-11-02 10:27:15 -07:00
Anders Kaseorg afa47b9ae3 node_tests: Mock window.location with JSDOM.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-10-14 12:47:43 -07:00
Dinesh 40470b938b node_tests: Import templates.js only once for all tests.
Reverts 55b2b1c with a better fix.

Closes: #19934
2021-10-13 09:49:32 -07:00
Dinesh 55b2b1c25d node_tests: Refresh templates.js import for every test.
Translation handlebars helpers were not getting changed when we
mock static/js/i18n.ts and then unmock it in a different test.

We mock i18n.ts for every test except node_tests/i18n.js.
So, running any code that calls the registered handlebar
helpers related to translations before running i18n test
will run the helper functions registered with mocked i18n module.
The subsequent tests too would use those functions registered
with mocked i18n module.

This causes the i18n test to fail as we expect the registered
helpers to use actual i18n.ts instead of a mock if we have
code that would call the registered translation helpers in
tests that run before i18n.
2021-10-07 16:32:07 -07:00
Sahil Batra 06f46cc146 settings: Add live update code for realm-level defaults settings.
This commit adds code for live-updating the realm-level default
settings page which contains only display settings as of now.

This commit also adds realm_user_settings_defaults object to
zpage_params so that we can write the tests.
2021-09-15 09:56:33 -07:00
Sahil Batra 998d710275 frontend: Add new user_settings module for user's settings.
We add a new user_settings module similar to page_params
module in frontend and use it to access user's personal
settings instead of page_params.
2021-08-01 15:30:17 -07:00
Steve Howell 2149a46270 zjquery: Tell dev about set_find_results. 2021-07-05 08:36:47 -04:00
Steve Howell 906a75ac00 zjsunit: Provide helpful messaging for mocking templates.
I also remove a conditional here that's not necessary. For
anything that's obviously a template in static/templates,
we now create a stub implementation that behaves according
to whether we're stubbed or being included as a partial.
2021-07-03 10:15:31 -04: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
Tim Abbott 71d5d64086 node_tests: Use module_path as local variable name. 2021-06-22 10:21:07 -07:00
Anders Kaseorg 6dbe03c54b zjsunit: Undo mock_cjs abstraction violation.
There is still no need for mock_template to reach into the internals
of mock_cjs.  Make it a normal caller of mock_cjs.

This is basically the same as 60f5a00c09
(#18804), because the same abstraction violation was since
reintroduced in the same way.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-06-22 10:19:56 -07: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 3d1aae6253 zjsunit: Optionally exercise template code.
If you call mock_template(fn, true), we will
call the actual template code and pass it to your
stub for verification.

We make this opt-in to prevent false positives
on template line coverage.

We special-case our handling of static/js/templates.js,
since it's important that all of our tests have
the Zulip-specific handlers for Handlebars pre-registered.

This runs in roughly the same amount of time as the
previous commit.
2021-06-15 12:33:26 -04:00
Steve Howell 41ed06c1f3 zjsunit: Move template module logic into load().
Unlike our normal mocks, we want mock_template
to call the actual code as well as the stub.

This preps us for the next commit.
2021-06-15 12:33:26 -04:00
Anders Kaseorg a9320accdc zjsunit: Remove unnecessary Handlebars wrapper function.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-06-14 12:20:56 -07:00
Steve Howell 398cdbd922 zjsunit: Remove stub_templates helper.
We now use mock_template everywhere.
2021-06-14 12:05:10 -04:00
Steve Howell 107c0d480a zjsunit: Improve errors for non-invoked templates. 2021-06-14 12:05:10 -04:00
Abhijeet Prasad Bodas 09f8a8ec2b zjsunit: Clear require cache also for templates.
This is necessary for the new `mock_template` helper added in
97ad6b6b62 to work correctly without
leaks, since it uses `mock_cjs` under the hood.

This logic was added in 216493aae8.
2021-06-14 09:17:50 -04:00
Steve Howell 103c4c3995 zjquery: Split out zjquery_element.js.
The new file is an easier place to point developers
for the most typical questions about zjquery's
capabilities.
2021-06-12 12:21:44 -04:00
Anders Kaseorg 60f5a00c09 zjsunit: Undo mock_cjs abstraction violation.
There is no need for mock_template to reach into the internals of
mock_cjs.  Make it a normal caller of mock_cjs.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-06-11 13:25:40 -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
Anders Kaseorg 40880aa496 node_tests: Use assert.equal.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-06-08 10:16:53 -07:00
Steve Howell 94ffef4de9 zjquery: Eliminate css() helper.
We use css() pretty rarely in our codebase, and
it can sometimes be used mistakenly, when a better
alternative is to toggle a class for external css.

It's hard to support the full API in zjquery, so
we just punt and tell folks to create their own
stubs.

Most of the existing tests that were "fixed" here
weren't actually verifying the behavior of the css()
calls, and for those I just create no-op stubs.

In a few places I verify that css() was called as
expected.
2021-06-04 20:08:19 -07:00
Steve Howell 1c4cdf8250 zjsunit: Add __jquery to objects.
This makes it a bit easier to decipher issues
with assert.deepEqual() failing. And we can
use it for introspection.
2021-05-26 08:00:35 -04:00
Steve Howell 7a3ba26c78 zjquery: Support $(...)[i] syntax. 2021-05-18 18:34:17 -04:00
Anders Kaseorg 923d67ecba node_tests: Fix example jQuery mock in comment.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-04-23 11:16:42 -07:00
Anders Kaseorg d8a36d0702 i18n: Remove i18next.
Fixes #17890.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-04-13 17:41:10 -07:00
Anders Kaseorg 4b4cea90a3 i18n: Initialize FormatJS.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-04-13 17:41:10 -07:00
Steve Howell 902e0f7e95 node tests: Clear page_params at start of run_test. 2021-04-03 15:03:00 -04: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 bb1b2048bd js: Convert static/js/i18n.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-26 10:17:56 -07:00