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 = {
17 $(context).find('.simpletest-group').once('simpletest-group-collapse').each(function () {
18 const $group = $(this);
19 const $image = $group.find('.simpletest-image');
21 .html(drupalSettings.simpleTest.images[0])
23 const $tests = $group.nextUntil('.simpletest-group');
24 const expand = !$group.hasClass('expanded');
25 $group.toggleClass('expanded', expand);
26 $tests.toggleClass('js-hide', !expand);
27 $image.html(drupalSettings.simpleTest.images[+expand]);
34 * Toggles test checkboxes to match the group checkbox.
36 * @type {Drupal~behavior}
38 * @prop {Drupal~behaviorAttach} attach
39 * Attaches behavior for selecting all tests in a group.
41 Drupal.behaviors.simpleTestSelectAll = {
43 $(context).find('.simpletest-group').once('simpletest-group-select-all').each(function () {
44 const $group = $(this);
45 const $cell = $group.find('.simpletest-group-select-all');
46 const $groupCheckbox = $(`<input type="checkbox" id="${$cell.attr('id')}-group-select-all" class="form-checkbox" />`);
47 const $testCheckboxes = $group.nextUntil('.simpletest-group').find('input[type=checkbox]');
48 $cell.append($groupCheckbox);
50 // Toggle the test checkboxes when the group checkbox is toggled.
51 $groupCheckbox.on('change', function () {
52 const checked = $(this).prop('checked');
53 $testCheckboxes.prop('checked', checked);
56 // Update the group checkbox when a test checkbox is toggled.
57 function updateGroupCheckbox() {
58 let allChecked = true;
59 $testCheckboxes.each(function () {
60 if (!$(this).prop('checked')) {
65 $groupCheckbox.prop('checked', allChecked);
68 $testCheckboxes.on('change', updateGroupCheckbox);
74 * Filters the test list table by a text input search string.
76 * Text search input: input.table-filter-text
77 * Target table: input.table-filter-text[data-table]
78 * Source text: .table-filter-text-source
80 * @type {Drupal~behavior}
82 * @prop {Drupal~behaviorAttach} attach
83 * Attaches the filter behavior to the text input element.
85 Drupal.behaviors.simpletestTableFilterByText = {
87 const $input = $('input.table-filter-text').once('table-filter-text');
88 const $table = $($input.attr('data-table'));
92 function filterTestList(e) {
93 const query = $(e.target).val().toLowerCase();
95 function showTestRow(index, row) {
97 const $sources = $row.find('.table-filter-text-source');
98 const textMatch = $sources.text().toLowerCase().indexOf(query) !== -1;
99 $row.closest('tr').toggle(textMatch);
102 // Filter if the length of the query is at least 3 characters.
103 if (query.length >= 3) {
104 // Indicate that a search has been performed, and hide the
105 // "select all" checkbox.
107 $('#simpletest-form-table thead th.select-all input').hide();
109 $rows.each(showTestRow);
111 // Restore to the original state if any searching has occurred.
114 $('#simpletest-form-table thead th.select-all input').show();
115 // Restore all rows to their original display state.
116 $rows.css('display', '');
121 $rows = $table.find('tbody tr');
122 $input.trigger('focus').on('keyup', Drupal.debounce(filterTestList, 200));
126 }(jQuery, Drupal, drupalSettings));