Files
zulip/frontend_tests/node_tests/spoilers.js
Steve Howell 64c7eb67eb zjquery: Make zjquery a singleton.
We no longer export make_zjquery().

We now instead have a singleton zjquery instance
that we attach to global.$ in index.js.

We call $.clear_all_elements() before each module.
(We will soon get even more aggressive about doing
it in run_test.)

Test functions can still override $ with set_global.
A good example of this is copy_and_paste using the
real jquery module.

We no longer exempt $ as a global variable, so
test modules that use the zjquery $ need to do:

    const $ = require("../zjsunit/zjquery");
2021-02-21 17:34:55 -05:00

40 lines
1.3 KiB
JavaScript

"use strict";
const {strict: assert} = require("assert");
const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
const spoilers = zrequire("spoilers");
// This function is taken from rendered_markdown.js and slightly modified.
const $array = (array) => {
const each = (func) => {
for (const [index, elem] of array.entries()) {
func.call(this, index, elem);
}
};
return {each};
};
const get_spoiler_elem = (title) => {
const block = $.create(`block-${title}`);
const header = $.create(`header-${title}`);
const content = $.create(`content-${title}`);
header.text(title);
block.set_find_results(".spoiler-header", header);
block.set_find_results(".spoiler-content", content);
return block;
};
run_test("hide spoilers in notifications", () => {
const root = $.create("root element");
const spoiler_1 = get_spoiler_elem("this is the title");
const spoiler_2 = get_spoiler_elem("");
root.set_find_results(".spoiler-block", $array([spoiler_1, spoiler_2]));
spoilers.hide_spoilers_in_notification(root);
assert.equal(spoiler_1.find(".spoiler-header").text(), "this is the title (…)");
assert.equal(spoiler_2.find(".spoiler-header").text(), "(…)");
});