Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('md_history.history_toolbar_test', function() { | 5 cr.define('md_history.history_toolbar_test', function() { |
| 6 // Array of test history data. | 6 // Array of test history data. |
| 7 var TEST_HISTORY_RESULTS = [ | 7 var TEST_HISTORY_RESULTS = [ |
| 8 { | 8 { |
| 9 "dateRelativeDay": "Today - Wednesday, December 9, 2015", | 9 "dateRelativeDay": "Today - Wednesday, December 9, 2015", |
| 10 "title": "Google", | |
| 10 "url": "https://www.google.com" | 11 "url": "https://www.google.com" |
| 11 } | 12 } |
| 12 ]; | 13 ]; |
| 13 | 14 |
| 14 function registerTests() { | 15 function registerTests() { |
| 15 suite('history-toolbar', function() { | 16 suite('history-toolbar', function() { |
| 16 var element; | 17 var element; |
| 17 var toolbar; | 18 var toolbar; |
| 18 | 19 |
| 19 suiteSetup(function() { | 20 suiteSetup(function() { |
| 20 element = $('history-card-manager'); | 21 element = $('history-card-manager'); |
| 21 toolbar = $('toolbar'); | 22 toolbar = $('toolbar'); |
| 22 }); | 23 }); |
| 23 | 24 |
| 24 test('selecting checkbox causes toolbar to change', function(done) { | 25 test('selecting checkbox causes toolbar to change', function(done) { |
| 25 element.addNewResults(TEST_HISTORY_RESULTS); | 26 element.addNewResults(TEST_HISTORY_RESULTS, ''); |
| 26 | 27 |
| 27 flush(function() { | 28 flush(function() { |
| 28 var item = element.$$('history-card').$$('history-item'); | 29 var item = element.$$('history-card').$$('history-item'); |
| 29 MockInteractions.tap(item.$.checkbox); | 30 MockInteractions.tap(item.$.checkbox); |
| 30 | 31 |
| 31 // Ensure that when an item is selected that the count held by the | 32 // Ensure that when an item is selected that the count held by the |
| 32 // toolbar increases. | 33 // toolbar increases. |
| 33 assertEquals(1, toolbar.count); | 34 assertEquals(1, toolbar.count); |
| 34 // Ensure that the toolbar boolean states that at least one item is | 35 // Ensure that the toolbar boolean states that at least one item is |
| 35 // selected. | 36 // selected. |
| 36 assertTrue(toolbar.itemsSelected_); | 37 assertTrue(toolbar.itemsSelected_); |
| 37 | 38 |
| 38 MockInteractions.tap(item.$.checkbox); | 39 MockInteractions.tap(item.$.checkbox); |
| 39 | 40 |
| 40 // Ensure that when an item is deselected the count held by the | 41 // Ensure that when an item is deselected the count held by the |
| 41 // toolbar decreases. | 42 // toolbar decreases. |
| 42 assertEquals(0, toolbar.count); | 43 assertEquals(0, toolbar.count); |
| 43 // Ensure that the toolbar boolean states that no items are selected. | 44 // Ensure that the toolbar boolean states that no items are selected. |
| 44 assertFalse(toolbar.itemsSelected_); | 45 assertFalse(toolbar.itemsSelected_); |
| 45 | 46 |
| 46 done(); | 47 done(); |
| 47 }); | 48 }); |
| 48 }); | 49 }); |
| 49 | 50 |
| 51 test('search term gathered correctly from toolbar', function(done) { | |
| 52 registerMessageCallback('queryHistory', this, function (info) { | |
| 53 assertEquals(info[0], 'Test'); | |
| 54 done(); | |
| 55 }); | |
| 56 | |
| 57 toolbar.onSearchTermSearch('Test'); | |
| 58 }); | |
| 59 | |
| 60 test('search results display with correct title', function(done) { | |
|
tsergeant
2016/02/08 22:59:01
Chris and I had a chat about these tests the other
hsampson
2016/02/09 02:17:51
Done.
| |
| 61 element.addNewResults(TEST_HISTORY_RESULTS, 'Google'); | |
| 62 | |
| 63 flush(function() { | |
| 64 var heading = | |
| 65 element.$$('history-card').$$('#date-accessed').textContent; | |
| 66 var title = element.$$('history-card').$$('history-item').$.title; | |
| 67 | |
| 68 var index = heading.indexOf('Found 1 search result for \'Google\'.'); | |
| 69 | |
| 70 assertTrue(index != -1); | |
| 71 assertEquals(title.innerHTML, '<b>Google</b>'); | |
| 72 done(); | |
| 73 }); | |
| 74 }); | |
| 75 | |
| 76 test('correct display message when no history available', function(done) { | |
| 77 element.addNewResults([], ''); | |
| 78 | |
| 79 flush(function() { | |
| 80 var message = element.$$('#no-results').textContent; | |
| 81 var index = message.indexOf('No history entries found.'); | |
| 82 | |
| 83 assertTrue(index != -1); | |
| 84 done(); | |
| 85 }) | |
| 86 }); | |
| 87 | |
| 88 test('correct display message when no search results returned', | |
| 89 function(done) { | |
| 90 element.addNewResults([], 'Test'); | |
| 91 | |
| 92 flush(function() { | |
| 93 var message = element.$$('#no-results').textContent; | |
| 94 var index = message.indexOf('No search results found.'); | |
| 95 | |
| 96 assertTrue(index != -1); | |
| 97 done(); | |
| 98 }) | |
| 99 }); | |
| 100 | |
| 50 teardown(function() { | 101 teardown(function() { |
| 102 element.historyDataByDay_ = []; | |
| 51 toolbar.count = 0; | 103 toolbar.count = 0; |
| 52 }); | 104 }); |
| 53 }); | 105 }); |
| 54 } | 106 } |
| 55 return { | 107 return { |
| 56 registerTests: registerTests | 108 registerTests: registerTests |
| 57 }; | 109 }; |
| 58 }); | 110 }); |
| OLD | NEW |