Commit Graph

370 Commits

Author SHA1 Message Date
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
Anders Kaseorg 9553f11387 eslint: Forbid CommonJS variables in ES6 modules.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-23 01:42:43 -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
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
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 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 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 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 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 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
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
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 f54f7cfc33 node tests: Introduce mock_module helper. 2021-03-06 13:15:04 -05:00