Commit Graph

45 Commits

Author SHA1 Message Date
Anders Kaseorg 9102c5a519 node_tests: Trigger events instead of mocking handler installation.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-21 12:01:26 -07:00
Anders Kaseorg b65d2e063d js: Reformat with Prettier.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg 8046b6477a js: Remove extra consecutive spaces.
Prettier would do this anyway, but it’s separated out for a more
reviewable diff.  Generated by ESLint.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg 883e2fd325 js: Remove inner spacing from object literals.
We’re configuring Prettier with bracketSpacing: false.  Generated by
ESLint.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg a20c12366f js: Use inside variant of IIFE wrappers.
Prettier would do this anyway, but it’s separated out for a more
reviewable diff.  Generated by ESLint.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg f3726db89a js: Normalize strings to double quotes.
Prettier would do this anyway, but it’s separated out for a more
reviewable diff.  Generated by ESLint.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:24 -07:00
Anders Kaseorg e014ea966a eslint: Enable comma-dangle for functions.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:55:51 -07:00
Anders Kaseorg a79322bc94 eslint: Enable prefer-arrow-callback.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:55:50 -07:00
Steve Howell d3aded2ae7 drafts: Rename open_modal -> open_overlay.
We consider the drafts thing to be an overlay,
not a modal, so the old name was confusing.
2020-05-09 10:18:59 -04:00
Steve Howell 09336c9e28 node test: Clean up ad hoc mocks for blueslip. 2020-04-03 12:56:49 -04:00
Steve Howell b994889315 node tests: Just set i18n every time.
Explicitly stubbing i18n in 48 different files
is mostly busy work at this point, and it doesn't
provide much signal, since often it's invoked
only to satisfy transitive dependencies.
2020-02-28 17:11:24 -08:00
Anders Kaseorg 1087fbebfe js: Convert _.clone(a) to { ...a } or a.slice().
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-25 14:26:06 -08:00
Steve Howell 9ab07d1038 util.js: Remove util from window.
We now treat util like a leaf module and
use "require" to import it everywhere it's used.

An earlier version of this commit moved
util into our "shared" library, but we
decided to wait on that.  Once we're ready
to do that, we should only need to do a
simple search/replace on various
require/zrequire statements plus a small
tweak to one of the custom linter checks.

It turns out we don't really need util.js
for our most immediate code-sharing goal,
which is to reuse our markdown code on
mobile.  There's a little bit of cleanup
still remaining to break the dependency,
but it's minor.

The util module still calls the global
blueslip module in one place, but that
code is about to be removed in the next
few commits.

I am pretty confident that once we start
sharing things like the typeahead code
more aggressively, we'll start having
dependencies on util.  The module is barely
more than 300 lines long, so we'll probably
just move the whole thing into shared
rather than break it apart.  Also, we
can continue to nibble away at the
cruftier parts of the module.
2020-02-15 12:20:20 -08:00
Anders Kaseorg 68ddfec78c tests: Convert ls_container from object to Map.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Tim Abbott ea7c6d395f compose_state: Rename compost_state.recipient to be about PMs only.
The compose_state.recipient field was only actually the recipient for
the message if it was a private_message_recipient (in the sense of
other code); we store the stream in compose_state.stream instead.

As a result, the name was quite confusing, resulting in the
possibility of problematic correctness bugs where code assumes this
field has a valid value for stream messages.  Fix this by changing it
to compose_state.private_message_recipient for clarity.
2019-12-02 08:53:55 -08:00
Anders Kaseorg 428956c086 zjsunit: Remove set_global side effect from zrequire.
ES6 and TS modules don’t insert themselves into `window`, so our tests
shouldn’t insert them either.  Since the test `window` behaves like
`global` now, we can rely on legacy modules that do insert themselves
to do it themselves.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-11-13 14:29:17 -08:00
Anders Kaseorg 28f3dfa284 js: Automatically convert var to let and const in most files.
This commit was originally automatically generated using `tools/lint
--only=eslint --fix`.  It was then modified by tabbott to contain only
changes to a set of files that are unlikely to result in significant
merge conflicts with any open pull request, excluding about 20 files.
His plan is to merge the remaining changes with more precise care,
potentially involving merging parts of conflicting pull requests
before running the `eslint --fix` operation.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-11-03 12:42:39 -08:00
Anders Kaseorg fb3fac1d96 zjsunit: Add make_handlebars abstraction.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-07-12 21:11:14 -07:00
Anders Kaseorg a0122abf9a zjsunit: Add stub_templates abstraction.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-07-12 21:11:14 -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 cdce66813e drafts: Fix date-sensitive test.
To test formatting we want a hard coded date, so we
can verify the date arithmetic with stable dates.

To make the test less brittle, we disable the
feature to remove old drafts.

This was an emergency fix.  We should probably just
remove the last N drafts instead of having the 30-day
limit.  Or we should have a better way to stub the cutoff
date.
2019-02-20 06:49:19 -08:00
Vaibhav 2ca8ec371e drafts: Change foreground for dark background streams in drafts modal.
In drafts modal, dark background streams still had black foreground;
This changes the foreground to white for the same.
2019-02-14 11:32:11 -08:00
Steve Howell c4cd0fe0c1 drafts: Use a reverse-cron sort.
I think it's natural for your eyes get drawn to
the top of the modal, so that's where we should
put the most recent draft.
2019-02-13 16:16:34 -08:00
Steve Howell e22a50a3e3 drafts: Use lists instead of dicts.
We were using a dict to return a sorted list of
formatted drafts, instead of building a list.
2018-12-16 15:46:41 -08:00
Steve Howell c82233c435 drafts: Avoid callback mechanism.
We had an anonymous callback for drafts that was
hard to read.  It's much easier to flatten the code,
give functions actual names, and stub them as needed
in the unit tests.
2018-12-16 15:46:41 -08:00
Steve Howell 35b904b184 subject -> topic: Fix subject in opts.
It's kinda difficult to track down all the interactions
with the opts that go through compose_actions.start(),
but I think I got everything.
2018-12-16 11:26:18 -08:00
Steve Howell 9861cdfeb6 drafts: Use "topic" internally.
We still have to support "subject" for old drafts,
but we write "topic" for new drafts.
2018-12-16 11:26:18 -08:00
Rohitt Vashishtha d7a0bd4a6c subject-to-topic: Add topics to compose_state.js. 2018-11-14 23:24:06 -08:00
Joshua Pan eca4266cde drafts: Don't save drafts with 2 or less characters.
Fixes #10357.
2018-08-22 16:52:18 -07:00
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
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
Tim Abbott 6e149a7594 lint: Add JS indentation eslint rules for node_tests.
The only difference between this as the main project's lint rules is
that we dont have the OuterIIFE setting.
2018-05-06 19:35:18 -07:00
Shubham Dhama 342ec0a544 drafts: Add tests for draft formatting and sorting. 2018-03-14 10:57:11 -07:00
Shubham Dhama 7aeae688e7 compose: Remove draft older than 30 days.
This removes drafts older than 30 days as they become irrelevant
for the user. Those drafts are removed before populating them.

Fixes: #7602.
2018-03-14 10:57:11 -07:00
Tommy Ip 6e22847548 refactor: new message content -> compose textarea. 2017-11-28 12:53:40 -08:00
Steve Howell f6f227d089 node tests: Use zrequire in drafts.js. 2017-11-08 12:24:17 -08:00
Tim Abbott 82b708b721 eslint: Add and enforce space-in-parens lint rule. 2017-10-06 12:36:59 -07:00
Cynthia Lin c87ecf0f63 hotkeys: Prevent drafts overlay from showing while lightbox is open.
Fixes #6757.
2017-10-03 08:36:54 -07:00
Joshua Pan a6efbddd65 node tests: Test drafts_overlay_open(). 2017-06-07 00:02:14 -07:00
Joshua Pan bbc0103183 drafts.js: Create initialize() function. 2017-06-07 00:01:55 -07:00
Steve Howell c999bdf823 compose: Distinguish get_message_type() from composing().
We now only call compose_state.composing() in a boolean context,
where we simply care whether or not the compose box is open.  The
function now also returns true/false.

Callers who need to know the actual message type (e.g. "stream" or
"private") now call compose_state.get_message_type().
2017-04-24 12:42:06 -07:00
Steve Howell 70b7d4c00b Extract compose_state.js.
This is mostly just moving methods out of compose.js.

The variable `is_composing_message`, which isn't a boolean, has
been renamed to `message_type`, and there are new functions
set_message_type() and get_message_type() that wrap it.

This commit removes some shims related to the global variable
`compose_state`; now, `compose_state` is a typical global
variable with a 1:1 relationship with the module by the same
name.

The new module has 100% line coverage, most of it coming
via the tests on compose_actions.js.  (The methods here are
super simple, so it's a good thing that the tests are somewhat
integrated with a higher layer.)
2017-04-18 12:26:58 -07:00
Sampriti Panda 32e76c2c60 drafts: Move snapshot_message from compose to drafts
Previously drafts called compose.snapshot_message which would then
get the message object from compose.create_message_object. This method often
checked for the validity of stream/user recipients which would often cause tracebacks.

The new method in drafts.snapshot message just gets the data from the fields and
stores them in the draft model without any additional checking.
2017-03-30 10:20:37 -07:00
Sampriti Panda 400a2e0ff1 drafts: Fix faulty draft_model addDraft and editDraft tests
The addDraft and editDraft tests were copying objects by reference
which meant the methods weren't tested properly. Due to this, a bug with
stubTimestamp was also discovered where the method wasn't getting stubbed
2017-03-30 10:20:37 -07:00
Sampriti Panda 1929cc5190 Implement persistent drafts functionality
* Created a drafts modal to display/restore/delete drafts
* Created a Draft model to support storing draft data in localstorage
* Removed existing restore-draft functionality
* Added casper and node tests for drafts functionality

Fixes #1717.
2017-02-23 02:58:23 -08:00