| 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_card_test', function() { | 5 cr.define('md_history.history_item_test', function() { |
| 6 var TEST_HISTORY_RESULTS = [ |
| 7 {"time": "1000000000"}, |
| 8 {"time": "10000000"}, |
| 9 {"time": "900000"}, |
| 10 {"time": "899999"} |
| 11 ]; |
| 12 |
| 6 function registerTests() { | 13 function registerTests() { |
| 7 suite('history-card', function() { | 14 suite('history-item', function() { |
| 8 var element; | 15 var element; |
| 9 | 16 |
| 10 suiteSetup(function() { | 17 suiteSetup(function() { |
| 11 element = document.createElement('history-card'); | 18 element = $('history-list'); |
| 12 element.historyItems = [ | 19 }); |
| 13 {"time": "1000000000"}, | 20 |
| 14 {"time": "10000000"}, | 21 setup(function() { |
| 15 {"time": "900000"} | 22 element.addNewResults(TEST_HISTORY_RESULTS); |
| 16 ]; | 23 }); |
| 17 }) | |
| 18 | 24 |
| 19 test('basic separator insertion', function(done) { | 25 test('basic separator insertion', function(done) { |
| 20 flush(function() { | 26 flush(function() { |
| 21 // Check that the correct number of time gaps are inserted. | 27 // Check that the correct number of time gaps are inserted. |
| 22 var spacers = | 28 var spacers = |
| 23 Polymer.dom(element.root).querySelectorAll('#time-gap-separator'); | 29 Polymer.dom(element.root).querySelectorAll('#time-gap-separator'); |
| 24 assertEquals(2, spacers.length); | 30 assertEquals(2, spacers.length); |
| 31 |
| 32 var items = |
| 33 Polymer.dom(element.root).querySelectorAll('history-item'); |
| 34 |
| 35 assertTrue(items[0].hasTimeGap); |
| 36 assertTrue(items[1].hasTimeGap); |
| 37 assertFalse(items[2].hasTimeGap); |
| 38 |
| 25 done(); | 39 done(); |
| 26 }); | 40 }); |
| 27 }); | 41 }); |
| 28 | 42 |
| 29 test('separator insertion when items change but item list length stays ' + | 43 teardown(function() { |
| 30 'the same', function(done) { | 44 element.historyData = []; |
| 31 element.set('historyItems', [{"time": "900000"}, | |
| 32 {"time": "900000"}, | |
| 33 {"time": "900000"}]); | |
| 34 | |
| 35 flush(function() { | |
| 36 var items = | |
| 37 Polymer.dom(element.root).querySelectorAll('history-item'); | |
| 38 var spacers = | |
| 39 Polymer.dom(element.root).querySelectorAll('#time-gap-separator'); | |
| 40 | |
| 41 assertEquals('900000', items[0].timestamp_); | |
| 42 assertEquals('900000', items[1].timestamp_); | |
| 43 assertEquals('900000', items[2].timestamp_); | |
| 44 | |
| 45 // Note that the spacers aren't actually removed, are just set to: | |
| 46 // display: none; | |
| 47 for (var i = 0; i < spacers.length; i++) { | |
| 48 assertEquals(spacers[i].style.display, 'none'); | |
| 49 } | |
| 50 done(); | |
| 51 }); | |
| 52 }); | 45 }); |
| 53 }); | 46 }); |
| 54 } | 47 } |
| 55 return { | 48 return { |
| 56 registerTests: registerTests | 49 registerTests: registerTests |
| 57 }; | 50 }; |
| 58 }); | 51 }); |
| OLD | NEW |