From 9c48fb07aa555c89ad3d6cc59b74036ad467e9fa Mon Sep 17 00:00:00 2001 From: Florian Spreckelsen <f.spreckelsen@indiscale.com> Date: Tue, 23 Jul 2024 16:48:51 +0200 Subject: [PATCH] TST: Add unit test for https://gitlab.com/linkahead/linkahead-webui/-/issues/258 --- test/core/js/modules/form_panel.js.js | 47 +++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/test/core/js/modules/form_panel.js.js b/test/core/js/modules/form_panel.js.js index f0cf3433..3a26aee2 100644 --- a/test/core/js/modules/form_panel.js.js +++ b/test/core/js/modules/form_panel.js.js @@ -23,25 +23,24 @@ 'use strict'; QUnit.module("form_panel.js", { - before: function (assert) { + before: function(assert) { }, - after: function (assert) { - } + after: function(assert) {} }); -QUnit.test("availability", function (assert) { +QUnit.test("availability", function(assert) { assert.ok(form_panel.init, "init available"); - assert.ok(form_panel.create_show_form_callback , "version available"); + assert.ok(form_panel.create_show_form_callback, "version available"); }); -QUnit.test("create_show_form_callback ", function (assert) { +QUnit.test("create_show_form_callback ", function(assert) { const title = "Upload CSV File"; // title of the form and text in the toolbox const panel_id = "csv_upload_form_panel"; const server_side_script = "csv_script.py"; const tool_box = "Tools"; // Name of the drop-down menu where the button is added in the navbar const help_text = "something"; - const accepted_files_formats = [ ".csv", "text/tsv", ] // Mime types and file endings. + const accepted_files_formats = [".csv", "text/tsv", ] // Mime types and file endings. const csv_form_config = { script: server_side_script, @@ -80,3 +79,37 @@ QUnit.test("create_show_form_callback ", function (assert) { }); +QUnit.test("autofocus_without_form", function(assert) { + const title = "My not-form title"; + const id = "not_form_id"; + // callback function that creates a "form" without HTML form + // elements. Trivial here, but could be e.g., the file upload + // from LinkAhead WebUI Core Components. + const init_not_form_field = () => { + const container = $(`<div class="row"/>`); + return container[0]; + }; + // This should always work + cb_without_autofocus = form_panel.create_show_form_callback( + id, + title, + undefined, + init_not_form_field, + false + ); + const nav = document.createElement("nav"); + document.body.appendChild(nav); + cb_without_autofocus(); + assert.ok(document.querySelector(`#${id}`), "Callback was called without autofocus."); + $(`#${id}`).remove(); + + cb_with_autofocus = form_panel.create_show_form_callback( + id, + title, + undefined, + init_not_form_field, + true + ); + cb_with_autofocus(); + assert.ok(document.querySelector(`#${id}`), "Callback was called with autofocus, bt still okay."); +}); -- GitLab