2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2020-12-01 00:02:16 +01:00
|
|
|
const {set_global, zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2020-12-01 00:12:33 +01:00
|
|
|
const {make_zjquery} = require("../zjsunit/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2020-12-01 00:12:33 +01:00
|
|
|
set_global("$", make_zjquery());
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("spoilers");
|
2020-07-15 02:08:01 +02:00
|
|
|
|
|
|
|
// This function is taken from rendered_markdown.js and slightly modified.
|
|
|
|
const $array = (array) => {
|
|
|
|
const each = (func) => {
|
2021-01-22 22:29:08 +01:00
|
|
|
for (const [index, elem] of array.entries()) {
|
2020-07-15 02:08:01 +02:00
|
|
|
func.call(this, index, elem);
|
2021-01-22 22:29:08 +01:00
|
|
|
}
|
2020-07-15 02:08:01 +02:00
|
|
|
};
|
|
|
|
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);
|
2020-07-15 01:29:15 +02:00
|
|
|
block.set_find_results(".spoiler-header", header);
|
|
|
|
block.set_find_results(".spoiler-content", content);
|
2020-07-15 02:08:01 +02:00
|
|
|
return block;
|
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
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]));
|
2020-07-15 02:08:01 +02:00
|
|
|
spoilers.hide_spoilers_in_notification(root);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(spoiler_1.find(".spoiler-header").text(), "this is the title (…)");
|
|
|
|
assert.equal(spoiler_2.find(".spoiler-header").text(), "(…)");
|
2020-07-15 02:08:01 +02:00
|
|
|
});
|