| 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"> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 var request; | 40 var request; |
| 41 var server; | 41 var server; |
| 42 var responseHeaders = { | 42 var responseHeaders = { |
| 43 json: { 'Content-Type': 'application/json' } | 43 json: { 'Content-Type': 'application/json' } |
| 44 }; | 44 }; |
| 45 var config_set; | 45 var config_set; |
| 46 | 46 |
| 47 setup(function() { | 47 setup(function() { |
| 48 server = sinon.fakeServer.create(); | 48 server = sinon.fakeServer.create(); |
| 49 var param = { | 49 var param = { |
| 50 event : { | 50 config_sets: [{ |
| 51 detail: { | 51 files: [{path: "OWNERS"}, {path: "README.md"}], |
| 52 response: { | 52 location: "https://test.com/valid-project-with-config-files", |
| 53 config_sets: [{ | 53 last_import_attempt: {success: true} |
| 54 files: [{path: "OWNERS"}, {path: "README.md"}], | 54 }] |
| 55 location: "https://test.com/valid-project-with-config-files"
, | |
| 56 last_import_attempt: {success: true} | |
| 57 }] | |
| 58 } | |
| 59 } | |
| 60 } | |
| 61 }; | 55 }; |
| 62 server.respondWith( | 56 server.respondWith( |
| 63 'GET', | 57 'GET', |
| 64 /\/_ah\/api\/config\/v1\/config-sets\?config_set=([a-z\-]+)\/([a-z\-
]+)&include_files=true&include_last_import_attempt=true/, | 58 /\/_ah\/api\/config\/v1\/config-sets\?config_set=([a-z\-]+)\/([a-z\-
]+)&include_files=true&include_last_import_attempt=true/, |
| 65 [ | 59 [ |
| 66 200, | 60 200, |
| 67 responseHeaders.json, | 61 responseHeaders.json, |
| 68 JSON.stringify(param) | 62 JSON.stringify(param) |
| 69 ] | 63 ] |
| 70 ); | 64 ); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 81 }); | 75 }); |
| 82 | 76 |
| 83 test('has correct name', function() { | 77 test('has correct name', function() { |
| 84 assert.equal(config_set.name, 'valid-project-with-config-files'); | 78 assert.equal(config_set.name, 'valid-project-with-config-files'); |
| 85 }); | 79 }); |
| 86 | 80 |
| 87 test('sets isLoading by default', function() { | 81 test('sets isLoading by default', function() { |
| 88 assert.equal(config_set.isLoading, true); | 82 assert.equal(config_set.isLoading, true); |
| 89 }); | 83 }); |
| 90 | 84 |
| 91 test('gets iron-ajax response', function () { | 85 test('gets iron-ajax response', function (done) { |
| 92 request = ajax.generateRequest(); | 86 request = ajax.generateRequest(); |
| 93 server.respond(); | 87 server.respond(); |
| 94 expect(request.status).to.be.equal(200); | 88 assert.equal(request.status, 200); |
| 95 expect(request.response).to.be.an('object'); | 89 assert.isObject(request.response); |
| 96 expect(request.response.event).to.be.an('object'); | 90 config_set.addEventListener('processedConfigFiles', function() { |
| 97 // TODO(crbug.com/740768): make the element call on-response handler a
utomatically | 91 assert.equal(config_set.isLoading, false); |
| 98 config_set._onGotConfigFiles(request.response.event); | 92 assert.equal(config_set.files.length, 2); |
| 99 assert.equal(config_set.isLoading, false); | 93 assert.equal(config_set.lastImportAttempt.success, true); |
| 100 assert.equal(config_set.files.length, 2); | 94 assert.equal(config_set.location, |
| 101 assert.equal(config_set.lastImportAttempt.success, true); | 95 "https://test.com/valid-project-with-config-files"); |
| 102 assert.equal(config_set.location, | 96 done(); |
| 103 "https://test.com/valid-project-with-config-files"); | 97 }.bind(config_set)); |
| 104 }); | 98 }); |
| 105 }); | 99 }); |
| 106 | 100 |
| 107 suite('Inalid project without config files', function() { | 101 suite('Inalid project without config files', function() { |
| 108 var ajax; | 102 var ajax; |
| 109 var request; | 103 var request; |
| 110 var server; | 104 var server; |
| 111 var responseHeaders = { | 105 var responseHeaders = { |
| 112 json: { 'Content-Type': 'application/json' } | 106 json: { 'Content-Type': 'application/json' } |
| 113 }; | 107 }; |
| 114 var config_set; | 108 var config_set; |
| 115 | 109 |
| 116 setup(function() { | 110 setup(function() { |
| 117 server = sinon.fakeServer.create(); | 111 server = sinon.fakeServer.create(); |
| 118 var param = { | 112 var param = { |
| 119 event : { | 113 config_sets: [{ |
| 120 detail: { | 114 location: "https://test.com/invalid-project-without-config-files", |
| 121 response: { | 115 last_import_attempt: {success: false} |
| 122 config_sets: [{ | 116 }] |
| 123 location: "https://test.com/invalid-project-without-config-f
iles", | |
| 124 last_import_attempt: {success: false} | |
| 125 }] | |
| 126 } | |
| 127 } | |
| 128 } | |
| 129 }; | 117 }; |
| 130 server.respondWith( | 118 server.respondWith( |
| 131 'GET', | 119 'GET', |
| 132 /\/_ah\/api\/config\/v1\/config-sets\?config_set=([a-z\-]+)\/([a-z\-
]+)&include_files=true&include_last_import_attempt=true/, | 120 /\/_ah\/api\/config\/v1\/config-sets\?config_set=([a-z\-]+)\/([a-z\-
]+)&include_files=true&include_last_import_attempt=true/, |
| 133 [ | 121 [ |
| 134 200, | 122 200, |
| 135 responseHeaders.json, | 123 responseHeaders.json, |
| 136 JSON.stringify(param) | 124 JSON.stringify(param) |
| 137 ] | 125 ] |
| 138 ); | 126 ); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 149 }); | 137 }); |
| 150 | 138 |
| 151 test('has correct name', function() { | 139 test('has correct name', function() { |
| 152 assert.equal(config_set.name, 'invalid-project-without-config-files'); | 140 assert.equal(config_set.name, 'invalid-project-without-config-files'); |
| 153 }); | 141 }); |
| 154 | 142 |
| 155 test('sets isLoading by default', function() { | 143 test('sets isLoading by default', function() { |
| 156 assert.equal(config_set.isLoading, true); | 144 assert.equal(config_set.isLoading, true); |
| 157 }); | 145 }); |
| 158 | 146 |
| 159 test('gets iron-ajax response', function () { | 147 test('gets iron-ajax response', function (done) { |
| 160 request = ajax.generateRequest(); | 148 request = ajax.generateRequest(); |
| 161 server.respond(); | 149 server.respond(); |
| 162 expect(request.status).to.be.equal(200); | 150 assert.equal(request.status, 200); |
| 163 expect(request.response).to.be.an('object'); | 151 assert.isObject(request.response); |
| 164 expect(request.response.event).to.be.an('object'); | 152 config_set.addEventListener('processedConfigFiles', function() { |
| 165 // TODO(crbug.com/740768): make the element call on-response handler a
utomatically | 153 assert.equal(config_set.isLoading, false); |
| 166 config_set._onGotConfigFiles(request.response.event); | 154 assert.equal(config_set.files.length, 0); |
| 167 assert.equal(config_set.isLoading, false); | 155 assert.equal(config_set.lastImportAttempt.success, false); |
| 168 assert.equal(config_set.files.length, 0); | 156 assert.equal(config_set.location, |
| 169 assert.equal(config_set.lastImportAttempt.success, false); | 157 "https://test.com/invalid-project-without-config-files"); |
| 170 assert.equal(config_set.location, | 158 done(); |
| 171 "https://test.com/invalid-project-without-config-files"); | 159 }.bind(config_set)); |
| 172 }); | 160 }); |
| 173 }); | 161 }); |
| 174 | 162 |
| 175 suite('Successful force refresh', function() { | 163 suite('Successful force refresh', function() { |
| 176 var ajax; | 164 var ajax; |
| 177 var request; | 165 var request; |
| 178 var server; | 166 var server; |
| 179 var responseHeaders = { | 167 var responseHeaders = { |
| 180 json: { 'Content-Type': 'application/json' } | 168 json: { 'Content-Type': 'application/json' } |
| 181 }; | 169 }; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 194 ] | 182 ] |
| 195 ); | 183 ); |
| 196 config_set = fixture('valid-project-with-config-files'); | 184 config_set = fixture('valid-project-with-config-files'); |
| 197 ajax = Polymer.dom(config_set.root).querySelector('#refreshConfigs'); | 185 ajax = Polymer.dom(config_set.root).querySelector('#refreshConfigs'); |
| 198 }); | 186 }); |
| 199 | 187 |
| 200 teardown(function() { | 188 teardown(function() { |
| 201 server.restore(); | 189 server.restore(); |
| 202 }); | 190 }); |
| 203 | 191 |
| 204 test('refreshes config set properly', function () { | 192 test('refreshes config set properly', function (done) { |
| 205 request = ajax.generateRequest(); | 193 request = ajax.generateRequest(); |
| 206 server.respond(); | 194 server.respond(); |
| 207 expect(request.status).to.be.equal(204); | 195 assert.equal(request.status, 204); |
| 208 // TODO(crbug.com/740768): make the element call on-response handler a
utomatically | 196 config_set.addEventListener('refreshComplete', function() { |
| 209 config_set._onCompleteRefresh(); | 197 assert.equal(config_set.isRefreshing, false); |
| 210 assert.equal(config_set.isRefreshing, false); | 198 assert.equal(config_set.refreshMessage, "Refresh successful."); |
| 211 assert.equal(config_set.refreshMessage, "Refresh successful."); | 199 done(); |
| 200 }.bind(config_set)); |
| 212 }); | 201 }); |
| 213 }); | 202 }); |
| 214 | 203 |
| 215 suite('Unsuccessful force refresh', function() { | 204 suite('Unsuccessful force refresh', function() { |
| 216 var ajax; | 205 var ajax; |
| 217 var request; | 206 var request; |
| 218 var server; | 207 var server; |
| 219 var responseHeaders = { | 208 var responseHeaders = { |
| 220 json: { 'Content-Type': 'application/json' } | 209 json: { 'Content-Type': 'application/json' } |
| 221 }; | 210 }; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 244 ] | 233 ] |
| 245 ); | 234 ); |
| 246 config_set = fixture('valid-project-with-config-files'); | 235 config_set = fixture('valid-project-with-config-files'); |
| 247 ajax = Polymer.dom(config_set.root).querySelector('#refreshConfigs'); | 236 ajax = Polymer.dom(config_set.root).querySelector('#refreshConfigs'); |
| 248 }); | 237 }); |
| 249 | 238 |
| 250 teardown(function() { | 239 teardown(function() { |
| 251 server.restore(); | 240 server.restore(); |
| 252 }); | 241 }); |
| 253 | 242 |
| 254 test('refreshes config set properly', function () { | 243 test('refreshes config set properly', function (done) { |
| 255 request = ajax.generateRequest(); | 244 request = ajax.generateRequest(); |
| 256 server.respond(); | 245 server.respond(); |
| 257 expect(request.status).to.be.equal(404); | 246 assert.equal(request.status, 404); |
| 258 // TODO(crbug.com/740768): make the element call on-response handler a
utomatically | 247 config_set.addEventListener('refreshError', function() { |
| 259 config_set._onRefreshError(); | 248 assert.equal(config_set.isRefreshing, false); |
| 260 assert.equal(config_set.isRefreshing, false); | 249 assert.equal(config_set.refreshMessage, "Error: Files could not be r
efreshed."); |
| 261 assert.equal(config_set.refreshMessage, "Error: Files could not be ref
reshed."); | 250 done(); |
| 251 }.bind(config_set)); |
| 262 }); | 252 }); |
| 263 }); | 253 }); |
| 264 </script> | 254 </script> |
| 265 </body> | 255 </body> |
| 266 </html> | 256 </html> |
| OLD | NEW |