| OLD | NEW |
| (Empty) | |
| 1 <!-- |
| 2 Copyright 2016 The LUCI Authors. All rights reserved. |
| 3 Use of this source code is governed under the Apache License, Version 2.0 |
| 4 that can be found in the LICENSE file. |
| 5 |
| 6 --> |
| 7 <!doctype html> |
| 8 |
| 9 <html> |
| 10 <head> |
| 11 <meta charset="utf-8"> |
| 12 <meta name="viewport" content="width=device-width, minimum-scale=1.0, initia
l-scale=1.0, user-scalable=yes"> |
| 13 |
| 14 <script src="../../web-component-tester/browser.js"></script> |
| 15 |
| 16 <link rel="import" href="/res/imp/common/pageable-data-demo.html"> |
| 17 </head> |
| 18 <body> |
| 19 |
| 20 <test-fixture id="pageable-data-fixture"> |
| 21 <template> |
| 22 <pageable-data-demo> |
| 23 </pageable-data-demo> |
| 24 </template> |
| 25 </test-fixture> |
| 26 |
| 27 <script> |
| 28 suite("<pageable-data>", function() { |
| 29 |
| 30 var demo; |
| 31 var pd; |
| 32 |
| 33 setup(function() { |
| 34 server.respondImmediately = true; |
| 35 demo = fixture("pageable-data-fixture"); |
| 36 pd = demo.$.pd; |
| 37 }); |
| 38 |
| 39 test("Has a default label set", function(done) { |
| 40 assert.equal(pd.label, "Show More"); |
| 41 // Because we use Promises to do the xhr request, and Promises are |
| 42 // handled asynchronously, we must always wait for the loading to |
| 43 // be finished. |
| 44 pd.addEventListener("_finishedLoading", function(){ |
| 45 done(); |
| 46 }); |
| 47 }); |
| 48 |
| 49 test("Has a button that reflects the label", function(done) { |
| 50 var button = Polymer.dom(pd.root).querySelector("button"); |
| 51 assert.isOk(button); |
| 52 assert.equal(button.textContent.trim(), "Show More"); |
| 53 assert.isNotOk(button.disabled, "Button should be disabled by default"
); |
| 54 pd.label = "I am a button"; |
| 55 assert.equal(button.textContent.trim(), "I am a button"); |
| 56 assert.isNotOk(button.disabled, "Button should be disabled by default"
); |
| 57 pd.addEventListener("_finishedLoading", function(){ |
| 58 done(); |
| 59 }); |
| 60 }); |
| 61 |
| 62 test("Loads 10 items by default", function(done) { |
| 63 pd.addEventListener("_finishedLoading", function(){ |
| 64 assert.isNotOk(pd.busy); |
| 65 assert.isOk(pd.output); |
| 66 assert.equal(10, pd.output.length); |
| 67 done(); |
| 68 }); |
| 69 }); |
| 70 |
| 71 test("Loads 10 more items on a click", function(done) { |
| 72 var button = Polymer.dom(pd.root).querySelector("button"); |
| 73 |
| 74 var times = 0; |
| 75 pd.addEventListener("_finishedLoading", function(){ |
| 76 times++; |
| 77 if (times == 2) { |
| 78 assert.isNotOk(pd.busy); |
| 79 assert.isOk(pd.output); |
| 80 assert.equal(20, pd.output.length); |
| 81 done(); |
| 82 return; |
| 83 } |
| 84 button.click(); |
| 85 }); |
| 86 }); |
| 87 |
| 88 test("When there are no more items, the button is disabled", function(do
ne) { |
| 89 var button = Polymer.dom(pd.root).querySelector("button"); |
| 90 |
| 91 var times = 0; |
| 92 pd.addEventListener("_finishedLoading", function(){ |
| 93 times++; |
| 94 if (times == 3) { |
| 95 assert.isNotOk(pd.busy); |
| 96 assert.isOk(pd.output); |
| 97 assert.equal(27, pd.output.length); |
| 98 assert.isOk(button.disabled); |
| 99 done(); |
| 100 return; |
| 101 } |
| 102 button.click(); |
| 103 }); |
| 104 }); |
| 105 |
| 106 }); |
| 107 </script> |
| 108 |
| 109 </body> |
| 110 </html> |
| OLD | NEW |