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