| OLD | NEW |
| 1 <!-- | 1 <!-- |
| 2 Copyright 2017 The LUCI Authors. All rights reserved. | 2 Copyright 2017 The LUCI Authors. All rights reserved. |
| 3 Use of this source code is governed under the Apache License, Version 2.0 | 3 Use of this source code is governed under the Apache License, Version 2.0 |
| 4 that can be found in the LICENSE file. | 4 that can be found in the LICENSE file. |
| 5 --> | 5 --> |
| 6 | 6 |
| 7 <!doctype html> | 7 <!doctype html> |
| 8 <html lang="en"> | 8 <html lang="en"> |
| 9 <head> | 9 <head> |
| 10 <meta charset="utf-8"> | 10 <meta charset="utf-8"> |
| 11 <meta name="viewport" content="width=device-width, minimum-scale=1, initial-
scale=1, user-scalable=yes"> | 11 <meta name="viewport" content="width=device-width, minimum-scale=1, initial-
scale=1, user-scalable=yes"> |
| 12 | 12 |
| 13 <title>front-page test</title> | 13 <title>front-page test</title> |
| 14 | 14 |
| 15 <script src="../../bower_components/webcomponentsjs/webcomponents-lite.js"><
/script> | 15 <script src="../../bower_components/webcomponentsjs/webcomponents-lite.js"><
/script> |
| 16 <script src="../../bower_components/web-component-tester/browser.js"></scrip
t> | 16 <script src="../../bower_components/web-component-tester/browser.js"></scrip
t> |
| 17 | 17 |
| 18 <link rel="import" href="../../src/config-ui/front-page.html"> | 18 <link rel="import" href="../../src/config-ui/front-page.html"> |
| 19 </head> | 19 </head> |
| 20 <body> | 20 <body> |
| 21 | 21 |
| 22 <test-fixture id="front-pageTestFixture"> | 22 <test-fixture id="front-pageTestFixture"> |
| 23 <template> | 23 <template> |
| 24 <front-page></front-page> | 24 <front-page></front-page> |
| 25 </template> | 25 </template> |
| 26 </test-fixture> | 26 </test-fixture> |
| 27 | 27 |
| 28 <script> | 28 <script> |
| 29 suite('<front-page>', function() { | 29 |
| 30 // TODO(cwpayton): write tests for the front page element. | 30 suite('Front page with config sets', function() { |
| 31 |
| 32 var ajax; |
| 33 var request; |
| 34 var server; |
| 35 var responseHeaders = { |
| 36 json: { 'Content-Type': 'application/json' } |
| 37 }; |
| 31 var front_page; | 38 var front_page; |
| 32 setup(function() { | 39 setup(function() { |
| 40 server = sinon.fakeServer.create(); |
| 41 var param = { |
| 42 event : { |
| 43 detail: { |
| 44 response: { |
| 45 config_sets: [ |
| 46 { |
| 47 config_set: "valid-project", |
| 48 location: "https://chromium.googlesource.com/valid-project", |
| 49 last_import_attempt: {success: true} |
| 50 },{ |
| 51 config_set: "invalid-project", |
| 52 location: "https://chromium.googlesource.com/invalid-project
", |
| 53 last_import_attempt: {success: false} |
| 54 }] |
| 55 } |
| 56 } |
| 57 } |
| 58 }; |
| 59 server.respondWith( |
| 60 'GET', |
| 61 /\/_ah\/api\/config\/v1\/config-sets\?include_last_import_attempt=tr
ue/, |
| 62 [ |
| 63 200, |
| 64 responseHeaders.json, |
| 65 JSON.stringify(param) |
| 66 ] |
| 67 ); |
| 33 front_page = fixture('front-pageTestFixture'); | 68 front_page = fixture('front-pageTestFixture'); |
| 69 ajax = Polymer.dom(front_page.root).querySelector('iron-ajax'); |
| 34 }); | 70 }); |
| 35 | 71 |
| 72 teardown(function() { |
| 73 server.restore(); |
| 74 }); |
| 75 |
| 76 test('checks the config set list is empty before iron ajax call', |
| 77 function() { |
| 78 assert.equal(front_page.configSetList.length, 0); |
| 79 }); |
| 80 |
| 81 test('checks the search results list is empty before iron ajax call', |
| 82 function() { |
| 83 assert.equal(front_page.searchResults.length, 0); |
| 84 }); |
| 85 |
| 86 test('checks that isLoading property is true by default', function() { |
| 87 assert.equal(front_page.isLoading, true); |
| 88 }); |
| 89 |
| 90 test('gets iron-ajax response', function () { |
| 91 request = ajax.generateRequest(); |
| 92 server.respond(); |
| 93 expect(request.response).to.be.ok; |
| 94 expect(request.response).to.be.an('object'); |
| 95 expect(request.response.event).to.be.an('object'); |
| 96 // TODO(crbug.com/740768): make the element call on-response handler a
utomatically |
| 97 front_page._onGotConfigSets(request.response.event); |
| 98 assert.equal(front_page.isLoading, false); |
| 99 assert.equal(front_page.configSetList.length, 2); |
| 100 assert.deepEqual(front_page.configSetList, |
| 101 front_page.searchResults); |
| 102 assert.equal(front_page.configSetList[0].last_import_attempt.success, |
| 103 true); |
| 104 assert.equal(front_page.configSetList[1].last_import_attempt.success, |
| 105 false); |
| 106 }); |
| 107 |
| 108 test('query does not match any results', function () { |
| 109 request = ajax.generateRequest(); |
| 110 server.respond(); |
| 111 // TODO(crbug.com/740768): make the element call on-response handler a
utomatically |
| 112 front_page._onGotConfigSets(request.response.event); |
| 113 front_page.query = "service"; |
| 114 assert.notEqual(front_page.configSetList, |
| 115 front_page.searchResults); |
| 116 assert.equal(front_page.searchResults.length, 0); |
| 117 }); |
| 118 |
| 119 test('query matches all results', function () { |
| 120 request = ajax.generateRequest(); |
| 121 server.respond(); |
| 122 // TODO(crbug.com/740768): make the element call on-response handler a
utomatically |
| 123 front_page._onGotConfigSets(request.response.event); |
| 124 front_page.query = "project"; |
| 125 assert.deepEqual(front_page.configSetList, |
| 126 front_page.searchResults); |
| 127 assert.equal(front_page.searchResults.length, 2); |
| 128 }); |
| 129 |
| 130 test('query matches one result', function () { |
| 131 request = ajax.generateRequest(); |
| 132 server.respond(); |
| 133 // TODO(crbug.com/740768): make the element call on-response handler a
utomatically |
| 134 front_page._onGotConfigSets(request.response.event); |
| 135 front_page.query = "valid-project"; |
| 136 assert.notEqual(front_page.configSetList, |
| 137 front_page.searchResults); |
| 138 assert.equal(front_page.searchResults[0].config_set, "valid-project"); |
| 139 }); |
| 140 |
| 36 }); | 141 }); |
| 142 |
| 37 </script> | 143 </script> |
| 38 </body> | 144 </body> |
| 39 </html> | 145 </html> |
| OLD | NEW |