3 * Simpletest behaviors.
6 (function($, Drupal, drupalSettings) {
8 * Collapses table rows followed by group rows on the test listing page.
10 * @type {Drupal~behavior}
12 * @prop {Drupal~behaviorAttach} attach
13 * Attach collapse behavior on the test listing page.
15 Drupal.behaviors.simpleTestGroupCollapse = {
18 .find('.simpletest-group')
19 .once('simpletest-group-collapse')
21 const $group = $(this);
22 const $image = $group.find('.simpletest-image');
23 $image.html(drupalSettings.simpleTest.images[0]).on('click', () => {
24 const $tests = $group.nextUntil('.simpletest-group');
25 const expand = !$group.hasClass('expanded');
26 $group.toggleClass('expanded', expand);
27 $tests.toggleClass('js-hide', !expand);
28 $image.html(drupalSettings.simpleTest.images[+expand]);
35 * Toggles test checkboxes to match the group checkbox.
37 * @type {Drupal~behavior}
39 * @prop {Drupal~behaviorAttach} attach
40 * Attaches behavior for selecting all tests in a group.
42 Drupal.behaviors.simpleTestSelectAll = {
45 .find('.simpletest-group')
46 .once('simpletest-group-select-all')
48 const $group = $(this);
49 const $cell = $group.find('.simpletest-group-select-all');
50 const $groupCheckbox = $(
51 `<input type="checkbox" id="${$cell.attr(
53 )}-group-select-all" class="form-checkbox" />`,
55 const $testCheckboxes = $group
56 .nextUntil('.simpletest-group')
57 .find('input[type=checkbox]');
58 $cell.append($groupCheckbox);
60 // Toggle the test checkboxes when the group checkbox is toggled.
61 $groupCheckbox.on('change', function() {
62 const checked = $(this).prop('checked');
63 $testCheckboxes.prop('checked', checked);
66 // Update the group checkbox when a test checkbox is toggled.
67 function updateGroupCheckbox() {
68 let allChecked = true;
69 $testCheckboxes.each(function() {
70 if (!$(this).prop('checked')) {
75 $groupCheckbox.prop('checked', allChecked);
78 $testCheckboxes.on('change', updateGroupCheckbox);
84 * Filters the test list table by a text input search string.
86 * Text search input: input.table-filter-text
87 * Target table: input.table-filter-text[data-table]
88 * Source text: .table-filter-text-source
90 * @type {Drupal~behavior}
92 * @prop {Drupal~behaviorAttach} attach
93 * Attaches the filter behavior to the text input element.
95 Drupal.behaviors.simpletestTableFilterByText = {
97 const $input = $('input.table-filter-text').once('table-filter-text');
98 const $table = $($input.attr('data-table'));
100 let searched = false;
102 function filterTestList(e) {
103 const query = $(e.target)
107 function showTestRow(index, row) {
109 const $sources = $row.find('.table-filter-text-source');
114 .indexOf(query) !== -1;
115 $row.closest('tr').toggle(textMatch);
118 // Filter if the length of the query is at least 3 characters.
119 if (query.length >= 3) {
120 // Indicate that a search has been performed, and hide the
121 // "select all" checkbox.
123 $('#simpletest-form-table thead th.select-all input').hide();
125 $rows.each(showTestRow);
127 // Restore to the original state if any searching has occurred.
130 $('#simpletest-form-table thead th.select-all input').show();
131 // Restore all rows to their original display state.
132 $rows.css('display', '');
137 $rows = $table.find('tbody tr');
140 .on('keyup', Drupal.debounce(filterTestList, 200));
144 })(jQuery, Drupal, drupalSettings);