"use strict"; const assert = require("node:assert/strict"); const {set_global, with_overrides, zrequire} = require("./lib/namespace.cjs"); const {run_test} = require("./lib/test.cjs"); const navigator = {}; set_global("navigator", navigator); const {initialize_user_settings} = zrequire("user_settings"); const user_settings = {}; initialize_user_settings({user_settings}); /* Note that the test runner automatically registers all of our handlers. */ run_test("and", () => { const args = { last: true, }; const html = require("./templates/and.hbs")(args); assert.equal(html, "

empty and

\n

last and

\n\n"); }); run_test("or", () => { const args = { last: true, }; const html = require("./templates/or.hbs")(args); assert.equal(html, "\n

last or

\n

true or

\n"); }); run_test("map_entries", () => { const html = require("./templates/map_entries.hbs")({ m: new Map([ ["a", "b"], ["c", "d"], ]), }); assert.equal(html, "a:b\nc:d\n"); }); run_test("object_entries", () => { const html = require("./templates/object_entries.hbs")({ o: {a: "b", c: "d"}, }); assert.equal(html, "a:b\nc:d\n"); }); run_test("object_values", () => { const html = require("./templates/object_values.hbs")({ o: {a: "b", c: "d"}, }); assert.equal(html, "b\nd\n"); }); run_test("rendered_markdown", () => { const html = require("./templates/rendered_markdown.hbs")(); const expected_html = 'good\n'; assert.equal(html, expected_html); }); run_test("numberFormat", () => { const args = { number: 1000000, }; const html = require("./templates/numberFormat.hbs")(args); assert.equal(html, "1,000,000\n"); }); run_test("tooltip_hotkey_hints", () => { const args = { hotkey_one: "Ctrl", hotkey_two: "C", }; const html = require("./templates/tooltip_hotkey_hints.hbs")(args); const expected_html = `${args.hotkey_one}${args.hotkey_two}\n`; assert.equal(html, expected_html); }); run_test("popover_hotkey_hints", () => { const args = { hotkey_one: "Ctrl", hotkey_two: "[", }; const html = require("./templates/popover_hotkey_hints.hbs")(args); const expected_html = `${args.hotkey_one}${args.hotkey_two}\n`; assert.equal(html, expected_html); }); run_test("popover_hotkey_hints mac command", () => { const args = { hotkey_one: "Ctrl", hotkey_two: "[", }; with_overrides(({override}) => { override(navigator, "platform", "MacIntel"); const html = require("./templates/popover_hotkey_hints.hbs")(args); const expected_html = '[\n'; assert.equal(html, expected_html); }); }); run_test("popover_hotkey_hints_shift_hotkey", () => { const args = { hotkey_one: "Shift", hotkey_two: "V", }; const html = require("./templates/popover_hotkey_hints.hbs")(args); args.hotkey_one = "⇧"; // adjust_shift_hotkey const expected_html = `${args.hotkey_one}${args.hotkey_two}\n`; assert.equal(html, expected_html); }); run_test("list_each", ({override}) => { assert.equal( require("./templates/list_each.hbs")({stuff: [{name: "x"}, {name: "y"}, {name: "z"}]}), `\ x, y, and z x y z `, ); assert.equal( require("./templates/list_each.hbs")({stuff: []}), `\ empty `, ); override(user_settings, "default_language", "zh-Hans"); assert.equal( require("./templates/list_each.hbs")({stuff: [{name: "水"}, {name: "粥"}, {name: "粥"}]}), `\ 水、粥和粥 水粥粥 `, ); });