3 * Simpletest behaviors.
6 (function ($, Drupal, drupalSettings) {
11 * Collapses table rows followed by group rows on the test listing page.
13 * @type {Drupal~behavior}
15 * @prop {Drupal~behaviorAttach} attach
16 * Attach collapse behavior on the test listing page.
18 Drupal.behaviors.simpleTestGroupCollapse = {
19 attach: function (context) {
20 $(context).find('.simpletest-group').once('simpletest-group-collapse').each(function () {
22 var $image = $group.find('.simpletest-image');
24 .html(drupalSettings.simpleTest.images[0])
25 .on('click', function () {
26 var $tests = $group.nextUntil('.simpletest-group');
27 var expand = !$group.hasClass('expanded');
28 $group.toggleClass('expanded', expand);
29 $tests.toggleClass('js-hide', !expand);
30 $image.html(drupalSettings.simpleTest.images[+expand]);
37 * Toggles test checkboxes to match the group checkbox.
39 * @type {Drupal~behavior}
41 * @prop {Drupal~behaviorAttach} attach
42 * Attaches behavior for selecting all tests in a group.
44 Drupal.behaviors.simpleTestSelectAll = {
45 attach: function (context) {
46 $(context).find('.simpletest-group').once('simpletest-group-select-all').each(function () {
48 var $cell = $group.find('.simpletest-group-select-all');
49 var $groupCheckbox = $('<input type="checkbox" id="' + $cell.attr('id') + '-group-select-all" class="form-checkbox" />');
50 var $testCheckboxes = $group.nextUntil('.simpletest-group').find('input[type=checkbox]');
51 $cell.append($groupCheckbox);
53 // Toggle the test checkboxes when the group checkbox is toggled.
54 $groupCheckbox.on('change', function () {
55 var checked = $(this).prop('checked');
56 $testCheckboxes.prop('checked', checked);
59 // Update the group checkbox when a test checkbox is toggled.
60 function updateGroupCheckbox() {
61 var allChecked = true;
62 $testCheckboxes.each(function () {
63 if (!$(this).prop('checked')) {
68 $groupCheckbox.prop('checked', allChecked);
71 $testCheckboxes.on('change', updateGroupCheckbox);
77 * Filters the test list table by a text input search string.
79 * Text search input: input.table-filter-text
80 * Target table: input.table-filter-text[data-table]
81 * Source text: .table-filter-text-source
83 * @type {Drupal~behavior}
85 * @prop {Drupal~behaviorAttach} attach
86 * Attaches the filter behavior to the text input element.
88 Drupal.behaviors.simpletestTableFilterByText = {
89 attach: function (context) {
90 var $input = $('input.table-filter-text').once('table-filter-text');
91 var $table = $($input.attr('data-table'));
95 function filterTestList(e) {
96 var query = $(e.target).val().toLowerCase();
98 function showTestRow(index, row) {
100 var $sources = $row.find('.table-filter-text-source');
101 var textMatch = $sources.text().toLowerCase().indexOf(query) !== -1;
102 $row.closest('tr').toggle(textMatch);
105 // Filter if the length of the query is at least 3 characters.
106 if (query.length >= 3) {
107 // Indicate that a search has been performed, and hide the
108 // "select all" checkbox.
110 $('#simpletest-form-table thead th.select-all input').hide();
112 $rows.each(showTestRow);
114 // Restore to the original state if any searching has occurred.
117 $('#simpletest-form-table thead th.select-all input').show();
118 // Restore all rows to their original display state.
119 $rows.css('display', '');
124 $rows = $table.find('tbody tr');
125 $input.trigger('focus').on('keyup', Drupal.debounce(filterTestList, 200));
130 })(jQuery, Drupal, drupalSettings);