| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('settings_test', function() { |
| 6 var searchManager = settings.getSearchManager(); |
| 7 |
| 8 suite('SearchSettingsTest', function() { |
| 9 setup(function() { |
| 10 PolymerTest.clearBody(); |
| 11 }); |
| 12 |
| 13 /** |
| 14 * Test that the DOM of a node is modified as expected when a search hit |
| 15 * occurs within that node. |
| 16 */ |
| 17 test('normal highlighting', function() { |
| 18 var optionText = 'FooSettingsFoo'; |
| 19 |
| 20 document.body.innerHTML = |
| 21 `<settings-section hidden-by-search> |
| 22 <div id="mydiv">${optionText}</div> |
| 23 </settings-section>`; |
| 24 |
| 25 var section = document.querySelector('settings-section'); |
| 26 var div = document.querySelector('#mydiv'); |
| 27 |
| 28 assertTrue(section.hiddenBySearch); |
| 29 return searchManager.search('settings', section).then(function() { |
| 30 assertFalse(section.hiddenBySearch); |
| 31 |
| 32 var highlightWrapper = div.querySelector('.search-highlight-wrapper'); |
| 33 assertTrue(!!highlightWrapper); |
| 34 |
| 35 var originalContent = highlightWrapper.querySelector( |
| 36 '.search-highlight-original-content'); |
| 37 assertTrue(!!originalContent); |
| 38 assertEquals(optionText, originalContent.textContent); |
| 39 |
| 40 var searchHits = highlightWrapper.querySelectorAll( |
| 41 '.search-highlight-hit'); |
| 42 assertEquals(1, searchHits.length); |
| 43 assertEquals('Settings', searchHits[0].textContent); |
| 44 |
| 45 // Check that original DOM structure is restored when search |
| 46 // highlights are cleared. |
| 47 return searchManager.search('', section); |
| 48 }).then(function() { |
| 49 assertEquals(0, div.children.length); |
| 50 assertEquals(optionText, div.textContent); |
| 51 }); |
| 52 }); |
| 53 |
| 54 /** |
| 55 * Tests that a search hit within a <select> node causes the parent |
| 56 * settings-section to be shown, but the DOM of the <select> is not |
| 57 * modified. |
| 58 */ |
| 59 test('<select> highlighting', function() { |
| 60 document.body.innerHTML = |
| 61 `<settings-section hidden-by-search> |
| 62 <select> |
| 63 <option>Foo</option> |
| 64 <option>Settings</option> |
| 65 <option>Baz</option> |
| 66 </select> |
| 67 </settings-section>`; |
| 68 |
| 69 var section = document.querySelector('settings-section'); |
| 70 var select = section.querySelector('select'); |
| 71 |
| 72 assertTrue(section.hiddenBySearch); |
| 73 return searchManager.search('settings', section).then(function() { |
| 74 assertFalse(section.hiddenBySearch); |
| 75 |
| 76 var highlightWrapper = select.querySelector( |
| 77 '.search-highlight-wrapper'); |
| 78 assertFalse(!!highlightWrapper); |
| 79 |
| 80 // Check that original DOM structure is present even after search |
| 81 // highlights are cleared. |
| 82 return searchManager.search('', section); |
| 83 }).then(function() { |
| 84 var options = select.querySelectorAll('option'); |
| 85 assertEquals(3, options.length); |
| 86 assertEquals('Foo', options[0].textContent); |
| 87 assertEquals('Settings', options[1].textContent); |
| 88 assertEquals('Baz', options[2].textContent); |
| 89 }); |
| 90 }); |
| 91 }); |
| 92 }); |
| OLD | NEW |