2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
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 12:47:54 +01:00
|
|
|
const {rewiremock, zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2021-02-21 15:38:51 +01:00
|
|
|
const $ = require("../zjsunit/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-03-06 17:37:51 +01:00
|
|
|
const upload_widget = rewiremock("../../static/js/upload_widget").with({});
|
2021-02-10 04:53:22 +01:00
|
|
|
const settings_emoji = zrequire("settings_emoji");
|
2020-07-24 00:02:31 +02:00
|
|
|
|
|
|
|
run_test("build_emoji_upload_widget", () => {
|
|
|
|
let build_widget_stub = false;
|
2021-02-23 14:37:26 +01:00
|
|
|
upload_widget.build_widget = (
|
2020-07-24 00:02:31 +02:00
|
|
|
get_file_input,
|
|
|
|
file_name_field,
|
|
|
|
input_error,
|
|
|
|
clear_button,
|
|
|
|
upload_button,
|
2021-02-23 14:37:26 +01:00
|
|
|
) => {
|
2020-07-24 00:02:31 +02:00
|
|
|
assert.deepEqual(get_file_input(), $("#emoji_file_input"));
|
|
|
|
assert.deepEqual(file_name_field, $("#emoji-file-name"));
|
|
|
|
assert.deepEqual(input_error, $("#emoji_file_input_error"));
|
|
|
|
assert.deepEqual(clear_button, $("#emoji_image_clear_button"));
|
|
|
|
assert.deepEqual(upload_button, $("#emoji_upload_button"));
|
|
|
|
build_widget_stub = true;
|
|
|
|
};
|
|
|
|
settings_emoji.build_emoji_upload_widget();
|
|
|
|
assert(build_widget_stub);
|
|
|
|
});
|