mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-19 08:26:23 -07:00
Update JS board events test
This commit is contained in:
parent
1704bbe959
commit
22eff8d1d7
1 changed files with 10 additions and 11 deletions
|
@ -9,43 +9,42 @@ import { applyBBCode, handleKeydown } from "../ts/boardevents";
|
|||
|
||||
document.documentElement.innerHTML = simpleHTML;
|
||||
|
||||
function doBBCode(keycode: number, text: string, start: number, end: number) {
|
||||
function doBBCode(key:string, text: string, start: number, end: number) {
|
||||
const $ta = $<HTMLTextAreaElement>("<textarea/>");
|
||||
$ta.text(text);
|
||||
const e = $.Event("keydown");
|
||||
e.ctrlKey = true;
|
||||
$ta[0].selectionStart = start;
|
||||
$ta[0].selectionEnd = end;
|
||||
e.keyCode = keycode;
|
||||
e.which = keycode;
|
||||
e.key = key;
|
||||
$ta.first().trigger(e);
|
||||
applyBBCode(e as JQuery.KeyDownEvent);
|
||||
return $ta.text();
|
||||
}
|
||||
|
||||
test("Tests BBCode events", () => {
|
||||
let text = doBBCode(66, "bold", 0, 4);
|
||||
let text = doBBCode("b", "bold", 0, 4);
|
||||
expect(text).toEqual("[b]bold[/b]");
|
||||
text += "italics";
|
||||
text = doBBCode(73, text, text.length - 7, text.length);
|
||||
text = doBBCode("i", text, text.length - 7, text.length);
|
||||
expect(text).toEqual("[b]bold[/b][i]italics[/i]");
|
||||
|
||||
text = doBBCode(82, "strike" + text, 0, 6);
|
||||
text = doBBCode("r", "strike" + text, 0, 6);
|
||||
expect(text).toEqual("[s]strike[/s][b]bold[/b][i]italics[/i]");
|
||||
|
||||
text = doBBCode(83, text, 0, 13);
|
||||
text = doBBCode("s", text, 0, 13);
|
||||
expect(text).toEqual("[?][s]strike[/s][/?][b]bold[/b][i]italics[/i]");
|
||||
|
||||
text = doBBCode(85, text, text.length, text.length);
|
||||
text = doBBCode("u", text, text.length, text.length);
|
||||
expect(text).toEqual("[?][s]strike[/s][/?][b]bold[/b][i]italics[/i][u][/u]");
|
||||
|
||||
const invalidKeyCode = doBBCode(0, text, 0, 1); // passes an invalid keycode to applyBBCode, no change
|
||||
const invalidKeyCode = doBBCode("x", text, 0, 1); // passes an invalid keycode to applyBBCode, no change
|
||||
expect(invalidKeyCode).toEqual(text);
|
||||
});
|
||||
|
||||
test("Tests proper form submission via JS", () => {
|
||||
const $form = $("form#postform");
|
||||
const text = doBBCode(83, "text", 0, 4);
|
||||
const text = doBBCode("s", "text", 0, 4);
|
||||
$form.find("textarea#postmsg").text(text);
|
||||
let submitted = false;
|
||||
$form.on("submit", () => {
|
||||
|
@ -54,7 +53,7 @@ test("Tests proper form submission via JS", () => {
|
|||
});
|
||||
const e = $.Event("keydown");
|
||||
e.ctrlKey = true;
|
||||
e.keyCode = 10;
|
||||
e.key = "Enter";
|
||||
$form.find("textarea#postmsg").first().trigger(e);
|
||||
handleKeydown(e as JQuery.KeyDownEvent);
|
||||
expect(submitted).toBeTruthy();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue