123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753 |
- QUnit.test("form elements check", assert => {
- $('#forms').append('<hr><h1>form elements check 1</h1><form id="form1"></form>')
- var el = $('#form1')
- new App.ControllerForm({
- el: el,
- model: {
- "configure_attributes": [
- {
- "name": "tree_select",
- "display": "tree_select",
- "tag": "tree_select",
- "null": true,
- "translate": true,
- "options": [
- {
- "value": "aa",
- "name": "yes",
- "children": [
- {
- "value": "aa::aaa",
- "name": "yes1",
- },
- {
- "value": "aa::aab",
- "name": "yes2",
- },
- {
- "value": "aa::aac",
- "name": "yes3",
- },
- ]
- },
- {
- "value": "bb",
- "name": "bb (comment)",
- "children": [
- {
- "value": "bb::bba",
- "name": "yes11",
- },
- {
- "value": "bb::bbb",
- "name": "yes22",
- },
- {
- "value": "bb::bbc",
- "name": "yes33",
- },
- ]
- },
- ],
- }
- ]
- },
- autofocus: true
- });
- assert.equal(el.find('[name="tree_select"]').val(), '', 'check tree_select value');
- assert.equal(el.find('[name="tree_select"]').closest('.searchableSelect').find('.js-input').val(), '', 'check tree_select .js-input value');
- var params = App.ControllerForm.params(el)
- var test_params = {
- tree_select: ''
- }
- assert.deepEqual(params, test_params, 'form param check')
- $('#forms').append('<hr><h1>form elements check 2</h1><form id="form2"></form>')
- var el = $('#form2')
- new App.ControllerForm({
- el: el,
- model: {
- "configure_attributes": [
- {
- "name": "tree_select",
- "display": "tree_select",
- "tag": "tree_select",
- "null": true,
- "translate": true,
- "value": "aa",
- "options": [
- {
- "value": "aa",
- "name": "yes",
- "children": [
- {
- "value": "aa::aaa",
- "name": "yes1",
- },
- {
- "value": "aa::aab",
- "name": "yes2",
- },
- {
- "value": "aa::aac",
- "name": "yes3",
- },
- ]
- },
- {
- "value": "bb",
- "name": "bb (comment)",
- "children": [
- {
- "value": "bb::bba",
- "name": "yes11",
- },
- {
- "value": "bb::bbb",
- "name": "yes22",
- },
- {
- "value": "bb::bbc",
- "name": "yes33",
- },
- ]
- },
- ],
- }
- ]
- },
- autofocus: true
- });
- assert.equal(el.find('[name="tree_select"]').val(), 'aa', 'check tree_select value');
- assert.equal(el.find('[name="tree_select"]').closest('.searchableSelect').find('.js-input').val(), 'yes', 'check tree_select .js-input value');
- var params = App.ControllerForm.params(el)
- var test_params = {
- tree_select: 'aa'
- }
- assert.deepEqual(params, test_params, 'form param check')
- $('#forms').append('<hr><h1>form elements check 3</h1><form id="form3"></form>')
- var el = $('#form3')
- new App.ControllerForm({
- el: el,
- model: {
- "configure_attributes": [
- {
- "name": "tree_select",
- "display": "tree_select",
- "tag": "tree_select",
- "null": true,
- "translate": true,
- "value": "aa::aab",
- "options": [
- {
- "value": "aa",
- "name": "yes",
- "children": [
- {
- "value": "aa::aaa",
- "name": "yes1",
- },
- {
- "value": "aa::aab",
- "name": "yes2",
- },
- {
- "value": "aa::aac",
- "name": "yes3",
- },
- ]
- },
- {
- "value": "bb",
- "name": "bb (comment)",
- "children": [
- {
- "value": "bb::bba",
- "name": "yes11",
- },
- {
- "value": "bb::bbb",
- "name": "yes22",
- },
- {
- "value": "bb::bbc",
- "name": "yes33",
- },
- ]
- },
- ],
- }
- ]
- },
- autofocus: true
- });
- assert.equal(el.find('[name="tree_select"]').val(), 'aa::aab', 'check tree_select value');
- assert.equal(el.find('[name="tree_select"]').closest('.searchableSelect').find('.js-input').val(), 'yes2', 'check tree_select .js-input value');
- assert.equal(el.find('[name="tree_select"]').closest('.searchableSelect').find('.js-input').attr('title'), 'yes › yes2', 'check tree_select .js-input tooltip');
- var params = App.ControllerForm.params(el)
- var test_params = {
- tree_select: 'aa::aab'
- }
- assert.deepEqual(params, test_params, 'form param check')
- $('#forms').append('<hr><h1>form elements check 4</h1><form id="form4"></form>')
- var el = $('#form4')
- new App.ControllerForm({
- el: el,
- model: {
- "configure_attributes": [
- {
- "name": "tree_select_search",
- "display": "tree_select_search",
- "tag": "tree_select_search",
- "null": true,
- "translate": true,
- "multiple": true,
- "value": ['aa::aab', 'bb', 'aa::aac::33'],
- "options": [
- {
- "value": "aa",
- "name": "yes",
- "children": [
- {
- "value": "aa::aaa",
- "name": "yes1",
- },
- {
- "value": "aa::aab",
- "name": "yes2",
- },
- {
- "value": "aa::aac",
- "name": "yes3",
- "children": [
- {
- "value": "aa::aaa::11",
- "name": "11",
- },
- {
- "value": "aa::aa1::22",
- "name": "22",
- },
- {
- "value": "aa::aac::33",
- "name": "33",
- },
- ]
- },
- ]
- },
- {
- "value": "bb",
- "name": "bb (comment)",
- "children": [
- {
- "value": "bb::bba",
- "name": "yes11",
- },
- {
- "value": "bb::bbb",
- "name": "yes22",
- },
- {
- "value": "bb::bbc",
- "name": "yes33",
- },
- ]
- },
- ],
- }
- ]
- },
- autofocus: true
- });
- var params = App.ControllerForm.params(el)
- var test_params = {
- tree_select_search: ['aa::aab', 'bb', 'aa::aac::33'],
- tree_select_search_completion: ""
- }
- assert.deepEqual(params, test_params, 'form param check')
- $('#forms').append('<hr><h1>form elements check / tree_select multiple / 3 selected</h1><form id="form6"></form>')
- var el = $('#form6')
- new App.ControllerForm({
- el: el,
- model: {
- "configure_attributes": [
- {
- "name": "tree_select",
- "display": "tree_select",
- "tag": "tree_select",
- "null": true,
- "multiple": true,
- "translate": true,
- "value": ['aa::aab', 'bb', 'aa::aac::33'],
- "options": [
- {
- "value": "aa",
- "name": "yes",
- "children": [
- {
- "value": "aa::aaa",
- "name": "yes1",
- },
- {
- "value": "aa::aab",
- "name": "yes2",
- },
- {
- "value": "aa::aac",
- "name": "yes3",
- "children": [
- {
- "value": "aa::aaa::11",
- "name": "11",
- },
- {
- "value": "aa::aa1::22",
- "name": "22",
- },
- {
- "value": "aa::aac::33",
- "name": "33",
- },
- ]
- },
- ]
- },
- {
- "value": "bb",
- "name": "bb (comment)",
- "children": [
- {
- "value": "bb::bba",
- "name": "yes11",
- },
- {
- "value": "bb::bbb",
- "name": "yes22",
- },
- {
- "value": "bb::bbc",
- "name": "yes33",
- },
- ]
- },
- ],
- }
- ]
- },
- autofocus: true
- });
- var params = App.ControllerForm.params(el)
- var test_params = {
- tree_select: ['aa::aab', 'bb', 'aa::aac::33'],
- tree_select_completion: "",
- }
- assert.deepEqual(params, test_params, 'form param check')
- $('#forms').append('<hr><h1>form elements check / tree_select multiple / 1 selected</h1><form id="form7"></form>')
- var el = $('#form7')
- new App.ControllerForm({
- el: el,
- model: {
- "configure_attributes": [
- {
- "name": "tree_select",
- "display": "tree_select",
- "tag": "tree_select",
- "null": true,
- "multiple": true,
- "translate": true,
- "value": ['aa::aab'],
- "options": [
- {
- "value": "aa",
- "name": "yes",
- "children": [
- {
- "value": "aa::aaa",
- "name": "yes1",
- },
- {
- "value": "aa::aab",
- "name": "yes2",
- },
- {
- "value": "aa::aac",
- "name": "yes3",
- "children": [
- {
- "value": "aa::aaa::11",
- "name": "11",
- },
- {
- "value": "aa::aa1::22",
- "name": "22",
- },
- {
- "value": "aa::aac::33",
- "name": "33",
- },
- ]
- },
- ]
- },
- {
- "value": "bb",
- "name": "bb (comment)",
- "children": [
- {
- "value": "bb::bba",
- "name": "yes11",
- },
- {
- "value": "bb::bbb",
- "name": "yes22",
- },
- {
- "value": "bb::bbc",
- "name": "yes33",
- },
- ]
- },
- ],
- }
- ]
- },
- autofocus: true
- });
- var params = App.ControllerForm.params(el)
- var test_params = {
- tree_select: ['aa::aab'],
- tree_select_completion: "",
- }
- assert.deepEqual(params, test_params, 'form param check')
- });
- QUnit.test("ui elements check", assert => {
- attribute = {
- "name": "tree_select_search",
- "display": "tree_select_search",
- "tag": "tree_select_search",
- "null": true,
- "translate": true,
- "value": ['bb::bba', 'bb::bbb'],
- "multiple": true,
- "options": [
- {
- "value": "aa",
- "name": "yes",
- "children": [
- {
- "value": "aa::aaa",
- "name": "yes1",
- },
- {
- "value": "aa::aab",
- "name": "yes2",
- },
- ]
- },
- {
- "value": "bb",
- "name": "bb (comment)",
- "children": [
- {
- "value": "bb::bba",
- "name": "yes11",
- },
- {
- "value": "bb::bbb",
- "name": "yes22",
- },
- ]
- },
- ],
- };
- options = [
- {
- "value": "aa",
- "name": "yes",
- "children": [
- {
- "value": "aa::aaa",
- "name": "yes1",
- },
- {
- "value": "aa::aab",
- "name": "yes2",
- },
- ]
- },
- {
- "value": "bb",
- "name": "bb (comment)",
- "children": [
- {
- "value": "bb::bba",
- "name": "yes11",
- },
- {
- "value": "bb::bbb",
- "name": "yes22",
- },
- ]
- }
- ]
- element = App.UiElement.tree_select_search.render(attribute)
- assert.deepEqual(attribute.options, options, 'options tree_select_search')
- attribute.name = 'tree_select'
- attribute.display = 'tree_select'
- attribute.tag = 'tree_select'
- element = App.UiElement.tree_select.render(attribute)
- assert.deepEqual(attribute.options, options, 'options tree_select')
- });
- QUnit.test("searchable_select submenu and option list check", assert => {
- var done = assert.async()
- $('#forms').append('<hr><h1>form elements check 5</h1><form id="form5"></form>')
- var el = $('#form5')
- new App.ControllerForm({
- el: el,
- model: {
- "configure_attributes": [
- {
- "name": "tree_select",
- "display": "tree_select",
- "tag": "tree_select",
- "null": true,
- "translate": true,
- "value": "bb",
- "options": [
- {
- "value": "a\\a",
- "name": "a\\a",
- "children": [
- {
- "value": "a\\a::aaa",
- "name": "aaa",
- },
- {
- "value": "a\\a::aab",
- "name": "aab",
- },
- {
- "value": "a\\a::aac",
- "name": "aac",
- },
- ]
- },
- {
- "value": "bb",
- "name": "bb",
- "children": [
- {
- "value": "bb::bba",
- "name": "bba",
- },
- {
- "value": "bb::bbb",
- "name": "bbb",
- },
- {
- "value": "bb::bbc",
- "name": "bbc",
- },
- ]
- },
- ],
- }
- ]
- },
- autofocus: true
- });
- el.find("[name=\"tree_select\"].js-shadow + .js-input").trigger('click')
- el.find(".searchableSelect .js-optionsList [data-value=\"a\\\\a\"] .searchableSelect-option-arrow").mouseenter().trigger('click')
- el.find(".searchableSelect .js-optionsSubmenu [data-value=\"a\\\\a::aab\"] .searchableSelect-option-text").mouseenter().trigger('click')
- el.find("[name=\"tree_select\"].js-shadow + .js-input").trigger('click')
- var params = App.ControllerForm.params(el)
- var test_params = {
- tree_select: 'a\\a::aab'
- }
- var optionsSubmenu = el.find(".searchableSelect [data-parent-value=\"a\\\\a\"].js-optionsSubmenu")
- var optionsList = el.find(".searchableSelect .js-optionsList")
- setTimeout( () => {
- assert.deepEqual(params, test_params, 'form param check')
- assert.equal(optionsSubmenu.is('[hidden]'), false, 'options submenu menu not hidden')
- assert.equal(optionsList.is('[hidden]'), true, 'options list is hidden')
- done()
- }, 300)
- });
- QUnit.test("[Core Workflow] Remove option does not work with tree select node that has sub-options #4407", assert => {
- $('#forms').append('<hr><h1>Remove option does not work with tree select node that has sub-options #4407 form8</h1><form id="form8"></form>')
- var el = $('#form8')
- attribute = {
- "name": "ts4407",
- "display": "ts4407",
- "tag": "tree_select",
- "null": true,
- "nulloption": true,
- "translate": true,
- "filter": ["aa", "bb::aaa", "dd::aaa::bbb"],
- "options": [
- {
- "value": "aa",
- "name": "aa yes",
- "children": [
- {
- "value": "aa::aaa",
- "name": "aa yes1",
- },
- {
- "value": "aa::aab",
- "name": "aa yes2",
- },
- ]
- },
- {
- "value": "bb",
- "name": "bb yes",
- "children": [
- {
- "value": "bb::aaa",
- "name": "bb yes1",
- },
- {
- "value": "bb::aab",
- "name": "bb yes2",
- },
- ]
- },
- {
- "value": "cc",
- "name": "cc yes",
- "children": [
- {
- "value": "cc::aaa",
- "name": "cc yes1",
- },
- {
- "value": "cc::aab",
- "name": "cc yes2",
- },
- ]
- },
- {
- "value": "dd",
- "name": "dd yes",
- "children": [
- {
- "value": "dd::aaa",
- "name": "dd yes1",
- "children": [
- {
- "value": "dd::aaa::bbb",
- "name": "dd yes2",
- },
- ]
- },
- ]
- }
- ],
- }
- element = App.UiElement.tree_select.render(attribute)
- // children are removed
- assert.equal(false, element.find("[data-value='aa::aaa']").length > 0)
- // one child removed, one child allowed
- assert.equal(true, element.find("[data-value='bb::aaa'] span.searchableSelect-option-text:not(.is-inactive)").length > 0)
- assert.equal(false, element.find("[data-value='bb::aab']").length > 0)
- assert.equal(true, element.find("[data-value='bb'] span.searchableSelect-option-text.is-inactive").length > 0)
- // parent and childs removed
- assert.equal(false, element.find("[data-value='cc']").length > 0)
- assert.equal(false, element.find("[data-value='cc::aaa']").length > 0)
- assert.equal(false, element.find("[data-value='cc::aab']").length > 0)
- // level 3 child allowed
- assert.equal(true, element.find("[data-value='dd'] span.searchableSelect-option-text.is-inactive").length > 0)
- assert.equal(true, element.find("[data-value='dd::aaa'] span.searchableSelect-option-text.is-inactive").length > 0)
- assert.equal(true, element.find("[data-value='dd::aaa::bbb'] span.searchableSelect-option-text:not(.is-inactive)").length > 0)
- attribute.value = 'aa'
- element = App.UiElement.tree_select.render(attribute)
- assert.equal('aa yes', element.find(".js-input").val())
- attribute.value = 'aa::aaa'
- element = App.UiElement.tree_select.render(attribute)
- assert.equal('-', element.find(".js-input").val())
- attribute.tag = 'multi_tree_select'
- attribute.multiple = true
- attribute.value = ['aa']
- element = App.UiElement.tree_select.render(attribute)
- assert.equal(true, element.find(".token[data-value='aa']").length > 0)
- attribute.value = ['aa::aaa']
- element = App.UiElement.tree_select.render(attribute)
- assert.equal(false, element.find(".token[data-value='aa::aaa']").length > 0)
- el.append(element)
- });
- QUnit.test("Escaping of values works just fine", assert => {
- $('#forms').append('<hr><h1>Escaping of values works just fine form9</h1><form id="form9"></form>')
- var el = $('#form9')
- attribute = {
- "name": "multi_tree_select",
- "display": "multi_tree_select",
- "tag": "multi_tree_select",
- "null": true,
- "nulloption": true,
- "translate": true,
- "multiple": true,
- "options": [
- {
- "value": "aa",
- "name": "aa yes",
- "children": [
- {
- "value": 'aa::aaa "test"',
- "name": "aa yes with quote",
- },
- {
- "value": "aa::aab",
- "name": "aa yes2",
- },
- ]
- },
- ],
- }
- attribute.value = ['aa::aaa "test"']
- element = App.UiElement.tree_select.render(attribute)
- escaped_selector = jQuery.escapeSelector('aa::aaa "test"')
- assert.equal(true, element.find(".token[data-value=" + escaped_selector + "]").length > 0)
- element.find('.js-remove').trigger('click')
- assert.equal(false, element.find(".token[data-value=" + escaped_selector + "]").length > 0)
- el.append(element)
- });
|