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