Commit Graph

146 Commits

Author SHA1 Message Date
Vishnu Ks a46b2386b6 billing: Add node tests for helpers.js. 2019-05-30 10:34:56 -07:00
Puneeth Chaganti 85b8be0ace zjquery: Add length attribute to wrapped elements. 2019-05-29 23:01:54 -07:00
Puneeth Chaganti be527905ca zjquery: Add closest() method. 2019-05-29 23:01:54 -07:00
Steve Howell 6b39d6004e zjquery: Use Proxy to detect undefined stubs.
We now use a Proxy to wrap zjquery elements, so
that we can detect callers trying to invoke methods
(or access attributes) that do not exist.  We try
to give useful error messages in those cases.

The main impact here is that we force lots of tests
to explicitly stub `length`.

Also, we can't do equality checks on zjquery
objects any more due to the proxy object, but the
easy workaround is to compare selectors.  (This
is generally an unnecessary technique, anyway.)

The proxy wrapper is fairly straightforward, and
we just have a few special cases for things like
"inspect" that happen when you try to print out
objects.
2019-05-20 11:28:32 -07:00
Steve Howell 6e1a67015f minor: Remove obsolete add_child method. 2019-04-18 14:01:57 -07:00
Steve Howell 6dbff03b9b zjquery: Improve on/off handling for events.
We no longer store handlers as an array of functions,
and instead we assume that code will only ever set up
one handler per sel/event or sel/event/child.  This is
almost always a sane policy for the app itself.

We also try to improve error handling when devs write
incorrect tests.

The only tests that required changes here are the
activity tests, which were a little careless about how
data got reset between tests.
2019-04-18 12:05:51 -07:00
Thomas Ip a2872c107e typescript: Move TS files into JS directory.
This is just a code reorganization to avoid making it difficult to
find things as we migrate more file to TypeScript.
2019-03-25 12:11:37 -07:00
Thomas Ip 7d050ab0cf typescript: Migrate dict.js to typescript. 2019-03-21 10:48:44 -07:00
Thomas Ip a290333325 typescript: Register ts-node to run TS modules in frontend tests. 2019-03-21 10:47:27 -07:00
Tim Abbott 0c6175f27e lint: Enforce semicolon spacing in eslint.
We only had a few exceptions to this rule; the zjquery one was actually a bug.
2019-01-05 15:31:30 -08:00
Tim Abbott bdb3da4504 eslint: Add key-spacing linter rule.
Apparently, we didn't have one of these, and thus had a moderate
number of generally very old violations in the codebase.  Fix this and
clear the ones that exist..
2018-12-18 10:41:06 -08:00
Tim Abbott b2939cdf19 lint: Fix comma spacing in node tests.
I apparently failed to check the tests codebase before merging the
last linter commit.  Oops.
2018-12-07 13:14:28 -08:00
Cynthia Lin 736388b4df user groups: Improve styling of user groups in admin view. 2018-08-13 16:13:49 -07:00
Shubham Padia 1f553a41d0 search: Higlight `#searchbox` on focus.
Adds box-shadow to `#searchbox` when either `#search_query` or any
of the pills have focus. Uses jquery instead of pure css as the
`:focus` event occurs on `#search_query`, while we want to add
box-shadow to `#searchbox`. This could have been done with
`:focus-within` CSS selector, but it is not supported in IE or Opera.

`#search_query` already had an onfocus/focusout listener, adding
listeners to `#searchbox.pills` for those events wouldn't have worked
as you don't want the focusout event to fire when the focus shifts
from input to pill.

Also adds `focusin`, `focusout` and `css()` to zjquery. `css` is
same as `val`, except it returns an empty object in case of no value
instead of an empty string. I don't think `css()` is valid syntax
in actual jquery.
2018-07-23 11:29:10 -07:00
Steve Howell eeac8cfa41 zjquery: Show multiple handlers in demo code.
This also makes the error messaging for true
duplicates a bit more specific.
2018-07-18 08:25:15 -04:00
Rohitt Vashishtha e14dbecdd1 zblueslip: Store more_info and stack as well in the logs.
Now, the get_test_logs() returns an array of objects instead
of an array of strings as follows:

[{
  message: "something",
  more_info: {},
  stack: {},
}]
2018-07-10 16:22:52 -04:00
Rohitt Vashishtha 17bdb8e984 zblueslip: Add exception_msg and wrap_function functions.
This commit brings zblueslip on par with blueslip.
2018-07-10 16:22:52 -04:00
Shubham Dhama 53cd1be294 zjquery: Add `clear_all_elements` to remove all cached elements.
The reason to add this api is that many times some elements are
already used/cached and then their value interfere/exists in
other tests which gives false results.
2018-07-06 11:30:12 -04:00
Shubham Dhama 98e6b287b5 zjquery: Implement empty function for when there is no argument. 2018-07-03 08:48:49 -04:00
Shubham Dhama 80a2d5bc59 eslint: Enable `conditionalAssign` config of no-trailing-spaces rule. 2018-06-11 07:51:24 -04:00
Shubham Dhama dcb6254a4e eslint: Enable `no-extra-parens` rule.
Following sub-configuration is disabled:
                "nestedBinaryExpressions": false,
2018-06-11 07:51:24 -04:00
Shubham Dhama 8852ed588a style: Remove redundant brackets from typeof operator. 2018-06-05 09:22:26 -07:00
Shubham Dhama cc03f9fb8f eslint: Enable space-infix-ops rule.
More about rule at  https://eslint.org/docs/rules/space-infix-ops
2018-06-05 00:47:35 +05:30
Shubham Dhama c6738889a9 eslint: Add and enable `space-unary-ops` rule.
Info about rule at https://eslint.org/docs/rules/space-unary-ops.
2018-06-05 00:47:35 +05:30
Tim Abbott c8db7b7dd7 node: Provide a default window object for the node tests.
This is preparation for our migration of our JS pipeline to webpack,
which includes as part of the process a hack of exporting globals via
the window object.
2018-05-31 14:55:28 -07:00
Tim Abbott d9347dea3e i18n: Remove now-unused ensure_i18n function. 2018-05-30 09:13:48 -07:00
Steve Howell 84c9be45af node tests: Remove requirement to test all templates.
We have less urgency to test all templates now.  The
most common error is probably unbalanced tags, and our
python-based template checker catches those problems
pretty well.

It's still possible to create bad templates, of course,
but the node tests have never been super deep at finding
semantic errors.
2018-05-24 09:30:22 -07:00
Shubham Dhama d1da4116ef node tests: Add `removeClass` to `stub_out_jquery`. 2018-05-23 15:29:34 -07:00
Priyank Patel 778742a189 jsdom: Upgrade jsdom to v11.10.0.
This also updates node_tests to use new constructor which is uppercase,
and some properties that are changed to be more clear now, like
jsdom().defaultView which is meant to the window object is now called window.

Ref: https://github.com/jsdom/jsdom/blob/master/Changelog.md
2018-05-20 11:11:03 -07:00
Steve Howell 02a0ad8e2e node tests: Exempt widgets from needing template tests. 2018-05-16 15:13:33 -07:00
Steve Howell 42435db492 Add run_test helper for individual tests.
This run_test helper sets up a convention that allows
us to give really short tracebacks for errors, and
eventually we can have more control over running
individual tests.  (The latter goal has some
complications, since we often intentionally leak
setup in tests.)
2018-05-15 08:24:44 -07:00
Steve Howell 0289794e5d zjsunit: Give shorter tracebacks for failures. 2018-05-15 08:24:44 -07:00
Tim Abbott ed299feb00 lint: Check eslint indentation for casper tests.
Now we just limit this rule for the node tests themselves.
2018-05-06 19:35:18 -07:00
Rohitt Vashishtha f51e151e62 zblueslip: Convert node_tests/markdown.js to zblueslip.
Also allows comparing in zblueslip using toString() for cases like
comparing an `Error('hello')` object and a `'hello'`.
2018-05-03 16:27:05 -07:00
Steve Howell fb712027bf buddy list: Fix and simplify up/down navigation.
This introduces a generic class called list_cursor to handle the
main details of navigating the buddy list and wires it into
activity.js.  It replaces some fairly complicated code that
was coupled to stream_list and used lots of jQuery.

The new code interacts with the buddy_list API instead of jQuery
directly.  It also persists the key across redraws, so we don't
lose our place when a focus ping happens or we type more characters.

Note that we no longer cycle to the top when we hit the bottom, or
vice versa.  Cycling can be kind of an anti-feature when you want to
just lay on the arrow keys until they hit the end.

The changes to stream_list.js here do not affect the left sidebar;
they only remove code that was used for the right sidebar.
2018-04-28 11:15:14 -07:00
Steve Howell ebe6144326 node tests: Avoid sneaky throttle/debounce delays.
For all of our current tests, we want to just execute
throttled functions immediately.
2018-04-26 08:42:47 -07:00
Steve Howell 58c67d8cba zjquery: Improve errors when handlers aren't set correctly. 2018-04-26 08:42:47 -07:00
Rohitt Vashishtha bddb6a1a14 zblueslip: Log output for all function calls.
Also adds asserts on blueslip.log() call in node_tests/people_errors.js.
2018-04-23 16:18:35 -07:00
Preston Hansen 76d6c71595 tests: Move zerver/fixtures to zerver/tests/fixtures for clarity.
Fixes #9153.
2018-04-19 21:50:17 -07:00
Rohitt Vashishtha 4738644339 zblueslip: Create zblueslip.js for improved error handling.
Adds a basic API for controlling the allowed error messages and
documents the usage in the form of unit tests, similar to zjquery.

Fixes #8675.
2018-04-19 15:02:00 -04:00
Joshua Pan 09469026c6 zjquery: Allow removeClass() to remove multiple classes simultaneously.
removeClass() now splits class_names by spaces to get multiple
class names. Then removes each individual class name.
2018-04-19 14:56:55 -04:00
Steve Howell 6b44cdb286 zjquery: Extract make_event_store().
This pushes some of the most complex code of zjquery into its own
object.
2018-04-17 17:52:19 -07:00
Steve Howell 10d1c2fafa zjquery: Extract make_new_elem().
There was really no reason for this to be a nested function, since
we weren't closing on any variables.  Flatter is better.  Also, it
is plausible that folks will want more control over creating
individual jQuery elements (but still want this helper).
2018-04-17 17:52:19 -07:00
Steve Howell fca5cec2af node tests: Remove features to output HTML to files.
I don't think anybody ever really used this feature, which I
developed but don't even use myself.  It kind of runs counter
to the minimalist approach of the rest of node tests.

I would eventually like to re-think the template tests altogether.
They're slow, and we could solve that somewhat by replacing
jsdon/jquery with an HTML parser library to verify structural
things.

It's also possible that we can just rely on our template linters
to catch the biggest class of errors (malformed tags) and let
code review do the rest.

And it's also possible that we should make a second attempt to
ramp up tooling on making it easy to verify templates, but it
doesn't have to be part of the node tests.  If we did that, we
would also potentially use tooling for Python-side templates.
2018-04-17 17:52:19 -07:00
Steve Howell 1568df352d zjsunit: Extract read_fixture_data(). 2018-04-17 17:52:19 -07:00
Rohitt Vashishtha 703351288a zjquery: Add replaceWith() and selector.location. 2018-04-13 09:13:50 -07:00
Rohitt Vashishtha 2e7f215f44 zjquery: Add option to silently ignore find() errors. 2018-04-13 09:13:50 -07:00
Steve Howell f56b4b7ec2 zjquery: Simplify validation for $(...).
We flatten the code a bit by removing a check that type is object,
and we replace it later with a check that type is string.

We also no longer allow document-like objects to be wrapped based
on the location-attribute-is-present hack.  Instead, we want the
tests to just set document to 'document-stub'.
2018-04-12 11:37:01 -07:00
Steve Howell 368b37e198 zjquery: Add a selector attribute to our wrapped elements.
We might as well have this for debugging purposes and to simplify
the code that happens when we double-wrap DOM elements.
2018-04-12 11:37:01 -07:00
Steve Howell f78947f2ba zjquery: Fix minor typo in comments.
This typo came from s/impl/self/ at some point :)
2018-04-12 11:37:01 -07:00