Commit 357317fe authored by Sebastien ANDRE's avatar Sebastien ANDRE Committed by Patrick Barroca
Browse files

hotline: #131892: treeselect asynchrone with regex

parent 2a7af482
- ticket #131892 : Administration : Correction du composant de recherche de paniers dans les configurations de boites
\ No newline at end of file
/**
* Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
QUnit.module('treeselect');
var datas = [{
"id": "paniers_by_users",
"label": "Paniers",
"categories": {
"1020": {
"id": "cart-owner-id-1020",
"label": "Administrateur",
"categories": [],
"items": [
{
"id": 111,
"label": "201111-jeunesse",
"options": {
"ico": "/public/admin/images/picto/paniers_16.png"
}
},
{
"id": 112,
"label": "201111-ados",
"options": {
"ico": "/public/admin/images/picto/paniers_16.png"
}
},
{
"id": 113,
"label": "201111-adultes",
"options": {
"ico": "/public/admin/images/picto/paniers_16.png"
}
},
{
"id": 114,
"label": "201222-jeunesse",
"options": {
"ico": "/public/admin/images/picto/paniers_16.png"
}
},
{
"id": 115,
"label": "201222-ados",
"options": {
"ico": "/public/admin/images/picto/paniers_16.png"
}
},
{
"id": 116,
"label": "201222-adultes",
"options": {
"ico": "/public/admin/images/picto/paniers_16.png"
}
},
{
"id": 117,
"label": "201222-cdc",
"options": {
"ico": "/public/admin/images/picto/paniers_16.png"
}
}
],
"options": {
"ico": "/public/admin/images/picto/abonnes.gif",
"removeCheckbox": true
}
}
},
"items": [],
"options": {
"multipleSelection": false
}
}];
function pack_ids(ids) {
return $.map(ids, function(d) { return d.id; }).join('-');
};
function call_treeselect() {
$('.treeselect.id_catalogue')
.treeselect({ datas: datas })
.treeselect('selectItems', [])
.treeselect('selectCategories', [])
.treeselect('toggleVisibility', true)
.treeselect('disableMultipleSelection');
$("form").submit(function() {
$(".treeselect").each(function(index) {
var node = $(this);
node.treeselect("readSelection",
function(items, categories) {
node.siblings("input:hidden:nth-child(2)").val(pack_ids(categories));
node.siblings("input:hidden:nth-child(3)").val(pack_ids(items));
});
});
});
};
function init_and_search(value) {
call_treeselect();
$('.ui-treeselect-search').find('input[type=textfield]').val(value);
$('.ui-treeselect-search').find('input[type=textfield]').trigger($.Event('keyup', { keyCode: 0 }));
return $('.ui-treeselect-category').find('li:visible');
}
test('Search "biq" will display no item', function() {
var visibles = init_and_search('biq');
equal(visibles.length, 0);
});
test('Search "2011" will display 3 items', function() {
var visibles = init_and_search('2011');
equal(visibles.length, 3);
equal(visibles[0].textContent, '201111-jeunesse');
equal(visibles[1].textContent, '201111-ados');
equal(visibles[2].textContent, '201111-adultes');
});
test('Search "2012" will display 4 items', function() {
var visibles = init_and_search('2012');
equal(visibles.length, 4);
equal(visibles[0].textContent, '201222-jeunesse');
equal(visibles[1].textContent, '201222-ados');
equal(visibles[2].textContent, '201222-adultes');
equal(visibles[3].textContent, '201222-cdc');
});
test('Search "ados" will display 2 items', function() {
var visibles = init_and_search('ados');
equal(visibles.length, 2);
equal(visibles[0].textContent, '201111-ados');
equal(visibles[1].textContent, '201222-ados');
});
test('Search"cdc" will display 1 item', function() {
var visibles = init_and_search('cdc');
equal(visibles.length, 1);
equal(visibles[0].textContent, '201222-cdc');
});
<!DOCTYPE html>
<!--
/**
* Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-->
<html>
<head>
<meta charset="utf-8">
<title>QUnit tests</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script type="text/javascript" src="../jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../jquery-ui-1.12.1/jquery-ui.min.js"></script>
<script src="treeselect.js"></script>
<script src="http://code.jquery.com/qunit/qunit-1.13.0.js"></script>
<script src="test.js"></script>
<form>
<div class="treeselect id_catalogue ui-widget ui-helper-reset"></div>
</form>
</body>
</html>
...@@ -467,27 +467,26 @@ ...@@ -467,27 +467,26 @@
return; return;
} }
accentsTidy = function(s){ accentsTidy = function (s) {
var r=s.toLowerCase(); var r = s.toLowerCase();
r = r.replace(new RegExp("[àáâãäå]", 'g'),"a"); r = r.replace(new RegExp("[àáâãäå]", 'g'), "a");
r = r.replace(new RegExp("æ", 'g'),"ae"); r = r.replace(new RegExp("æ", 'g'), "ae");
r = r.replace(new RegExp("ç", 'g'),"c"); r = r.replace(new RegExp("ç", 'g'), "c");
r = r.replace(new RegExp("[èéêë]", 'g'),"e"); r = r.replace(new RegExp("[èéêë]", 'g'), "e");
r = r.replace(new RegExp("[ìíîï]", 'g'),"i"); r = r.replace(new RegExp("[ìíîï]", 'g'), "i");
r = r.replace(new RegExp("ñ", 'g'),"n"); r = r.replace(new RegExp("ñ", 'g'), "n");
r = r.replace(new RegExp("[òóôõö]", 'g'),"o"); r = r.replace(new RegExp("[òóôõö]", 'g'), "o");
r = r.replace(new RegExp("œ", 'g'),"oe"); r = r.replace(new RegExp("œ", 'g'), "oe");
r = r.replace(new RegExp("[ùúûü]", 'g'),"u"); r = r.replace(new RegExp("[ùúûü]", 'g'), "u");
r = r.replace(new RegExp("[ýÿ]", 'g'),"y"); return r.replace(new RegExp("[ýÿ]", 'g'), "y");
return r;
}; };
searchText = accentsTidy(searchText); searchText = accentsTidy(searchText);
var re = new RegExp('\\b' + searchText, 'gi');
var matches = this.itemsTree.find('li, h3').filter(function() { var matches = this.itemsTree.find('li, h3').filter(function() {
return re.test(accentsTidy($(this).text())); return accentsTidy($(this).text()).indexOf(searchText) > -1;
}); });
this._highlightItems(matches); this._highlightItems(matches);
matches.parents(".ui-accordion-content").show(); matches.parents(".ui-accordion-content").show();
}, },
......
...@@ -96,6 +96,7 @@ require_once 'tests/library/Class/WebService/SIGB/TestingService.php'; ...@@ -96,6 +96,7 @@ require_once 'tests/library/Class/WebService/SIGB/TestingService.php';
require_once 'tests/fixtures/RessourcesNumeriquesFixtures.php'; require_once 'tests/fixtures/RessourcesNumeriquesFixtures.php';
require_once 'tests/fixtures/MockedClasses.php'; require_once 'tests/fixtures/MockedClasses.php';
require_once 'tests/application/modules/telephone/controllers/TelephoneAbstractControllerTestCase.php'; require_once 'tests/application/modules/telephone/controllers/TelephoneAbstractControllerTestCase.php';
require_once 'tests/js/PhantomJsTest.php';
register_shutdown_function(function(){ register_shutdown_function(function(){
TestSpeedTrap::printSpeedTrappedTests(); TestSpeedTrap::printSpeedTrappedTests();
......
<?php <?php
/** /**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
* *
* BOKEH is free software; you can redistribute it and/or modify * BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
...@@ -20,12 +20,6 @@ ...@@ -20,12 +20,6 @@
*/ */
class AuthorityPickerTest extends PHPUnit_Framework_TestCase { class AuthorityPickerTest extends PhantomJsTest {
protected $_test_path = 'public/opac/js/authority_picker/tests.html';
/** @test */
public function searchInputJStestShouldSuccess() {
exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/opac/js/authority_picker/tests.html', $output, $result);
$this->assertEquals(0, $result, implode("\n", $output));
}
} }
?>
\ No newline at end of file
<?php <?php
/** /**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
* *
* BOKEH is free software; you can redistribute it and/or modify * BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
...@@ -16,15 +16,10 @@ ...@@ -16,15 +16,10 @@
* *
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software * along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
class CustomFieldsReportTest extends PHPUnit_Framework_TestCase { class CustomFieldsReportTest extends PhantomJsTest {
/** @test */ protected $_test_path = 'public/admin/js/custom-fields/tests/custom_fields.html';
public function customFieldsReportMethodsJStestShouldSuccess() {
exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/admin/js/custom-fields/tests/custom_fields.html', $output, $result);
$this->assertEquals(0, $result, implode("\n", $output));
}
} }
?>
\ No newline at end of file
<?php <?php
/** /**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
* *
* BOKEH is free software; you can redistribute it and/or modify * BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
...@@ -20,11 +20,6 @@ ...@@ -20,11 +20,6 @@
*/ */
class MultiInputTest extends PHPUnit_Framework_TestCase { class MultiInputTest extends PhantomJsTest {
protected $_test_path = 'public/admin/js/multi_inputs/tests.html';
/** @test */ }
public function multiInputJstestShouldSuccess() {
exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/admin/js/multi_inputs/tests.html', $output, $result);
$this->assertEquals(0, $result, implode("\n", $output));
}
}
\ No newline at end of file
<?php <?php
/** /**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
* *
* BOKEH is free software; you can redistribute it and/or modify * BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
...@@ -20,11 +20,6 @@ ...@@ -20,11 +20,6 @@
*/ */
class MultiSelectionTest extends PHPUnit_Framework_TestCase { class MultiSelectionTest extends PhantomJsTest {
protected $_test_path = 'public/admin/js/multi_selection/tests.html';
/** @test */ }
public function multiSelectJstestShouldSuccess() {
exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/admin/js/multi_selection/tests.html', $output, $result);
$this->assertEquals(0, $result, implode("\n", $output));
}
}
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
abstract class PhantomJsTest extends PHPUnit_Framework_TestCase {
/** array or string */
protected $_test_path;
public function testPaths() {
if (!$this->_test_path)
return [];
if (!is_array($this->_test_path))
$this->_test_path = [$this->_test_path];
return array_map(function($path) { return [$path]; },
$this->_test_path);
}
/**
* @test
* @dataProvider testPaths
**/
public function jsTestShouldSucceed($path) {
exec('phantomjs '
. ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js '
. escapeshellarg(ROOT_PATH . $path),
$output,
$result);
$this->assertEquals(0, $result, implode("\n", $output));
}
}
<?php <?php
/** /**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
* *
* BOKEH is free software; you can redistribute it and/or modify * BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
...@@ -16,17 +16,10 @@ ...@@ -16,17 +16,10 @@
* *
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software * along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
class SearchAutocomplete extends PHPUnit_Framework_TestCase { class SearchAutocomplete extends PhantomJsTest {
protected $_test_path = 'public/opac/java/search_autocomplete/tests/search_autocomplete.html';
/** @test */
public function searchAutocompleteJStestShouldSuccess() {
exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/opac/java/search_autocomplete/tests/search_autocomplete.html', $output, $result);
$this->assertEquals(0, $result, implode("\n", $output));
}
} }
?>
\ No newline at end of file
<?php <?php
/** /**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
* *
* BOKEH is free software; you can redistribute it and/or modify * BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
...@@ -20,12 +20,6 @@ ...@@ -20,12 +20,6 @@
*/ */
class SearchInputTest extends PHPUnit_Framework_TestCase { class SearchInputTest extends PhantomJsTest {
protected $_test_path = 'public/opac/java/search_input/tests/search_input.html';
/** @test */
public function searchInputJStestShouldSuccess() {
exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/opac/java/search_input/tests/search_input.html', $output, $result);
$this->assertEquals(0, $result, implode("\n", $output));
}
} }
?>
\ No newline at end of file
<?php <?php
/** /**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
* *
* BOKEH is free software; you can redistribute it and/or modify * BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
...@@ -20,26 +20,8 @@ ...@@ -20,26 +20,8 @@
*/ */
class SliderNavigationTest extends PHPUnit_Framework_TestCase { class SliderNavigationTest extends PhantomJsTest {
protected $_test_path = ['public/opac/java/slider_navigation/tests/news_slider.html',
/** @test */ 'public/opac/java/slider_navigation/tests/agenda_slider.html',
public function newsSliderJStestShouldSuccess() { 'public/opac/java/slider_navigation/tests/preview_slider.html'];
exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/opac/java/slider_navigation/tests/news_slider.html', $output, $result);
$this->assertEquals(0, $result, implode("\n", $output));
}
/** @test */
public function agendaSliderJStestShouldSuccess() {
exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/opac/java/slider_navigation/tests/agenda_slider.html', $output, $result);
$this->assertEquals(0, $result, implode("\n", $output));
}
/** @test */
public function sliderWithPreviewJSTestShouldSucced() {
exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/opac/java/slider_navigation/tests/preview_slider.html', $output, $result);
$this->assertEquals(0, $result, implode("\n", $output));
}
} }
?>
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class TreeSelectTest extends PhantomJsTest {
protected $_test_path = 'public/admin/js/treeselect/tests.html';
}
<?php <?php
/** /**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
* *
* BOKEH is free software; you can redistribute it and/or modify * BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
...@@ -20,10 +20,6 @@ ...@@ -20,10 +20,6 @@
*/ */
class UserSelectionTest extends PHPUnit_Framework_TestCase { class UserSelectionTest extends PhantomJsTest {
/** @test */ protected $_test_path = 'public/admin/js/user_selection/tests.html';
public function userSelectionTestShouldSuccess() { }
exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/admin/js/user_selection/tests.html', $output, $result);