2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2020-11-30 23:46:45 +01:00
|
|
|
|
2024-11-13 07:05:32 +01:00
|
|
|
const {zrequire} = require("./lib/namespace.cjs");
|
|
|
|
const {run_test, noop} = require("./lib/test.cjs");
|
|
|
|
const $ = require("./lib/zjquery.cjs");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
const spoilers = zrequire("spoilers");
|
2020-07-15 02:08:01 +02:00
|
|
|
|
2024-01-03 08:02:47 +01:00
|
|
|
// This function is taken from rendered_markdown.ts and slightly modified.
|
2020-07-15 02:08:01 +02:00
|
|
|
const $array = (array) => {
|
|
|
|
const each = (func) => {
|
2022-01-25 11:36:19 +01:00
|
|
|
for (const [index, $elem] of array.entries()) {
|
|
|
|
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) => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $block = $.create(`block-${title}`);
|
|
|
|
const $header = $.create(`header-${title}`);
|
|
|
|
const $content = $.create(`content-${title}`);
|
2023-12-14 23:51:33 +01:00
|
|
|
$content.remove = noop;
|
2022-01-25 11:36:19 +01:00
|
|
|
$header.text(title);
|
|
|
|
$block.set_find_results(".spoiler-header", $header);
|
|
|
|
$block.set_find_results(".spoiler-content", $content);
|
|
|
|
return $block;
|
2020-07-15 02:08:01 +02:00
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("hide spoilers in notifications", () => {
|
2022-01-25 11:36:19 +01:00
|
|
|
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(), "(…)");
|
2020-07-15 02:08:01 +02:00
|
|
|
});
|