| OLD | NEW |
| (Empty) | |
| 1 <!-- |
| 2 Copyright 2017 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 <html lang="en"> |
| 9 <head> |
| 10 <meta charset="utf-8"> |
| 11 <meta name="viewport" content="width=device-width, minimum-scale=1, initial-
scale=1, user-scalable=yes"> |
| 12 |
| 13 <title>config-set test</title> |
| 14 |
| 15 <script src="../../bower_components/webcomponentsjs/webcomponents-lite.js"><
/script> |
| 16 <script src="../../bower_components/web-component-tester/browser.js"></scrip
t> |
| 17 |
| 18 <link rel="import" href="../../src/config-ui/config-set.html"> |
| 19 </head> |
| 20 <body> |
| 21 |
| 22 <test-fixture id="valid-project-with-config-files"> |
| 23 <template> |
| 24 <config-set category="projects" |
| 25 name="valid-project-with-config-files"></config-set> |
| 26 </template> |
| 27 </test-fixture> |
| 28 |
| 29 <test-fixture id="invalid-project-without-config-files"> |
| 30 <template> |
| 31 <config-set category="projects" |
| 32 name="invalid-project-without-config-files"></config-set> |
| 33 </template> |
| 34 </test-fixture> |
| 35 |
| 36 <script> |
| 37 suite('Valid project with config files', function() { |
| 38 |
| 39 var ajax; |
| 40 var request; |
| 41 var server; |
| 42 var responseHeaders = { |
| 43 json: { 'Content-Type': 'application/json' } |
| 44 }; |
| 45 var config_set; |
| 46 |
| 47 setup(function() { |
| 48 server = sinon.fakeServer.create(); |
| 49 var param = { |
| 50 event : { |
| 51 detail: { |
| 52 response: { |
| 53 config_sets: [{ |
| 54 files: [{path: "OWNERS"}, {path: "README.md"}], |
| 55 location: "https://test.com/valid-project-with-config-files"
, |
| 56 last_import_attempt: {success: true} |
| 57 }] |
| 58 } |
| 59 } |
| 60 } |
| 61 }; |
| 62 server.respondWith( |
| 63 'GET', |
| 64 /\/_ah\/api\/config\/v1\/config-sets\?config_set=([a-z\-]+)%2F([a-z\
-]+)&include_files=true&include_last_import_attempt=true/, |
| 65 [ |
| 66 200, |
| 67 responseHeaders.json, |
| 68 JSON.stringify(param) |
| 69 ] |
| 70 ); |
| 71 config_set = fixture('valid-project-with-config-files'); |
| 72 ajax = Polymer.dom(config_set.root).querySelector('iron-ajax'); |
| 73 }); |
| 74 |
| 75 teardown(function() { |
| 76 server.restore(); |
| 77 }); |
| 78 |
| 79 test('has correct category', function() { |
| 80 assert.equal(config_set.category, 'projects'); |
| 81 }); |
| 82 |
| 83 test('has correct name', function() { |
| 84 assert.equal(config_set.name, 'valid-project-with-config-files'); |
| 85 }); |
| 86 |
| 87 test('sets isLoading by default', function() { |
| 88 assert.equal(config_set.isLoading, true); |
| 89 }); |
| 90 |
| 91 test('gets iron-ajax response', function () { |
| 92 request = ajax.generateRequest(); |
| 93 server.respond(); |
| 94 expect(request.response).to.be.ok; |
| 95 expect(request.response).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 |
| 98 config_set._onGotConfigFiles(request.response.event); |
| 99 assert.equal(config_set.isLoading, false); |
| 100 assert.equal(config_set.files.length, 2); |
| 101 assert.equal(config_set.lastImportAttempt.success, true); |
| 102 assert.equal(config_set.location, |
| 103 "https://test.com/valid-project-with-config-files"); |
| 104 }); |
| 105 |
| 106 }); |
| 107 |
| 108 suite('Inalid project without config files', function() { |
| 109 var ajax; |
| 110 var request; |
| 111 var server; |
| 112 var responseHeaders = { |
| 113 json: { 'Content-Type': 'application/json' } |
| 114 }; |
| 115 var config_set; |
| 116 |
| 117 setup(function() { |
| 118 server = sinon.fakeServer.create(); |
| 119 var param = { |
| 120 event : { |
| 121 detail: { |
| 122 response: { |
| 123 config_sets: [{ |
| 124 location: "https://test.com/invalid-project-without-config-f
iles", |
| 125 last_import_attempt: {success: false} |
| 126 }] |
| 127 } |
| 128 } |
| 129 } |
| 130 }; |
| 131 server.respondWith( |
| 132 'GET', |
| 133 /\/_ah\/api\/config\/v1\/config-sets\?config_set=([a-z\-]+)%2F([a-z\
-]+)&include_files=true&include_last_import_attempt=true/, |
| 134 [ |
| 135 200, |
| 136 responseHeaders.json, |
| 137 JSON.stringify(param) |
| 138 ] |
| 139 ); |
| 140 config_set = fixture('invalid-project-without-config-files'); |
| 141 ajax = Polymer.dom(config_set.root).querySelector('iron-ajax'); |
| 142 }); |
| 143 |
| 144 teardown(function() { |
| 145 server.restore(); |
| 146 }); |
| 147 |
| 148 test('has correct category', function() { |
| 149 assert.equal(config_set.category, 'projects'); |
| 150 }); |
| 151 |
| 152 test('has correct name', function() { |
| 153 assert.equal(config_set.name, 'invalid-project-without-config-files'); |
| 154 }); |
| 155 |
| 156 test('sets isLoading by default', function() { |
| 157 assert.equal(config_set.isLoading, true); |
| 158 }); |
| 159 |
| 160 test('gets iron-ajax response', function () { |
| 161 request = ajax.generateRequest(); |
| 162 server.respond(); |
| 163 expect(request.response).to.be.ok; |
| 164 expect(request.response).to.be.an('object'); |
| 165 expect(request.response.event).to.be.an('object'); |
| 166 // TODO(crbug.com/740768): make the element call on-response handler a
utomatically |
| 167 config_set._onGotConfigFiles(request.response.event); |
| 168 assert.equal(config_set.isLoading, false); |
| 169 assert.equal(config_set.files.length, 0); |
| 170 assert.equal(config_set.lastImportAttempt.success, false); |
| 171 assert.equal(config_set.location, |
| 172 "https://test.com/invalid-project-without-config-files"); |
| 173 }); |
| 174 |
| 175 }); |
| 176 |
| 177 </script> |
| 178 </body> |
| 179 </html> |
| OLD | NEW |