| 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 21 matching lines...) Expand all Loading... |
| 32 var ajax; | 32 var ajax; |
| 33 var request; | 33 var request; |
| 34 var server; | 34 var server; |
| 35 var responseHeaders = { | 35 var responseHeaders = { |
| 36 json: { 'Content-Type': 'application/json' } | 36 json: { 'Content-Type': 'application/json' } |
| 37 }; | 37 }; |
| 38 var front_page; | 38 var front_page; |
| 39 setup(function() { | 39 setup(function() { |
| 40 server = sinon.fakeServer.create(); | 40 server = sinon.fakeServer.create(); |
| 41 var param = { | 41 var param = { |
| 42 event : { | 42 config_sets: [ |
| 43 detail: { | 43 { |
| 44 response: { | 44 config_set: "valid-project", |
| 45 config_sets: [ | 45 location: "https://chromium.googlesource.com/valid-project", |
| 46 { | 46 last_import_attempt: {success: true} |
| 47 config_set: "valid-project", | 47 },{ |
| 48 location: "https://chromium.googlesource.com/valid-project", | 48 config_set: "invalid-project", |
| 49 last_import_attempt: {success: true} | 49 location: "https://chromium.googlesource.com/invalid-project", |
| 50 },{ | 50 last_import_attempt: {success: false} |
| 51 config_set: "invalid-project", | 51 }] |
| 52 location: "https://chromium.googlesource.com/invalid-project
", | |
| 53 last_import_attempt: {success: false} | |
| 54 }] | |
| 55 } | |
| 56 } | |
| 57 } | |
| 58 }; | 52 }; |
| 59 server.respondWith( | 53 server.respondWith( |
| 60 'GET', | 54 'GET', |
| 61 /\/_ah\/api\/config\/v1\/config-sets\?include_last_import_attempt=tr
ue/, | 55 /\/_ah\/api\/config\/v1\/config-sets\?include_last_import_attempt=tr
ue/, |
| 62 [ | 56 [ |
| 63 200, | 57 200, |
| 64 responseHeaders.json, | 58 responseHeaders.json, |
| 65 JSON.stringify(param) | 59 JSON.stringify(param) |
| 66 ] | 60 ] |
| 67 ); | 61 ); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 80 | 74 |
| 81 test('checks the search results list is empty before iron ajax call', | 75 test('checks the search results list is empty before iron ajax call', |
| 82 function() { | 76 function() { |
| 83 assert.equal(front_page.searchResults.length, 0); | 77 assert.equal(front_page.searchResults.length, 0); |
| 84 }); | 78 }); |
| 85 | 79 |
| 86 test('checks that isLoading property is true by default', function() { | 80 test('checks that isLoading property is true by default', function() { |
| 87 assert.equal(front_page.isLoading, true); | 81 assert.equal(front_page.isLoading, true); |
| 88 }); | 82 }); |
| 89 | 83 |
| 90 test('gets iron-ajax response', function () { | 84 test('gets iron-ajax response', function (done) { |
| 91 request = ajax.generateRequest(); | 85 request = ajax.generateRequest(); |
| 92 server.respond(); | 86 server.respond(); |
| 93 expect(request.status).to.be.equal(200); | 87 assert.equal(request.status, 200); |
| 94 expect(request.response).to.be.an('object'); | 88 assert.isObject(request.response); |
| 95 expect(request.response.event).to.be.an('object'); | 89 front_page.addEventListener('processedConfigSets', function() { |
| 96 // TODO(crbug.com/740768): make the element call on-response handler a
utomatically | 90 assert.equal(front_page.isLoading, false); |
| 97 front_page._onGotConfigSets(request.response.event); | 91 assert.equal(front_page.configSetList.length, 2); |
| 98 assert.equal(front_page.isLoading, false); | 92 var sortedResults = front_page.configSetList.slice(); |
| 99 assert.equal(front_page.configSetList.length, 2); | 93 sortedResults.sort(function(a, b) { |
| 100 var sortedResults = front_page.configSetList.slice(); | 94 return front_page._formatName(a.config_set).localeCompare(front_pa
ge._formatName(b.config_set)); |
| 101 sortedResults.sort(function(a, b) { | 95 }.bind(front_page)); |
| 102 return front_page._formatName(a.config_set).localeCompare(front_page
._formatName(b.config_set)); | 96 assert.deepEqual(sortedResults, |
| 97 front_page.searchResults); |
| 98 assert.equal(front_page.configSetList[0].last_import_attempt.success
, |
| 99 true); |
| 100 assert.equal(front_page.configSetList[1].last_import_attempt.success
, |
| 101 false); |
| 102 done(); |
| 103 }.bind(front_page)); | 103 }.bind(front_page)); |
| 104 assert.deepEqual(sortedResults, | |
| 105 front_page.searchResults); | |
| 106 assert.equal(front_page.configSetList[0].last_import_attempt.success, | |
| 107 true); | |
| 108 assert.equal(front_page.configSetList[1].last_import_attempt.success, | |
| 109 false); | |
| 110 }); | 104 }); |
| 111 | 105 |
| 112 test('query does not match any results', function () { | 106 test('query does not match any results', function (done) { |
| 113 request = ajax.generateRequest(); | 107 request = ajax.generateRequest(); |
| 114 server.respond(); | 108 server.respond(); |
| 115 // TODO(crbug.com/740768): make the element call on-response handler a
utomatically | 109 front_page.addEventListener('processedConfigSets', function() { |
| 116 front_page._onGotConfigSets(request.response.event); | 110 front_page.query = "service"; |
| 117 front_page.query = "service"; | 111 assert.notEqual(front_page.configSetList, |
| 118 assert.notEqual(front_page.configSetList, | 112 front_page.searchResults); |
| 119 front_page.searchResults); | 113 assert.equal(front_page.searchResults.length, 0); |
| 120 assert.equal(front_page.searchResults.length, 0); | 114 done(); |
| 115 }.bind(front_page)); |
| 121 }); | 116 }); |
| 122 | 117 |
| 123 test('query matches all results', function () { | 118 test('query matches all results', function (done) { |
| 124 request = ajax.generateRequest(); | 119 request = ajax.generateRequest(); |
| 125 server.respond(); | 120 server.respond(); |
| 126 // TODO(crbug.com/740768): make the element call on-response handler a
utomatically | 121 front_page.addEventListener('processedConfigSets', function() { |
| 127 front_page._onGotConfigSets(request.response.event); | 122 front_page.query = "project"; |
| 128 front_page.query = "project"; | 123 var sortedResults = front_page.configSetList.slice(); |
| 129 var sortedResults = front_page.configSetList.slice(); | 124 sortedResults.sort(function(a, b) { |
| 130 sortedResults.sort(function(a, b) { | 125 return front_page._formatName(a.config_set).localeCompare(front_pa
ge._formatName(b.config_set)); |
| 131 return front_page._formatName(a.config_set).localeCompare(front_page
._formatName(b.config_set)); | 126 }.bind(front_page)); |
| 127 assert.deepEqual(sortedResults, |
| 128 front_page.searchResults); |
| 129 assert.equal(front_page.searchResults.length, 2); |
| 130 done(); |
| 132 }.bind(front_page)); | 131 }.bind(front_page)); |
| 133 assert.deepEqual(sortedResults, | |
| 134 front_page.searchResults); | |
| 135 assert.equal(front_page.searchResults.length, 2); | |
| 136 }); | 132 }); |
| 137 | 133 |
| 138 test('query matches one result', function () { | 134 test('query matches one result', function (done) { |
| 139 request = ajax.generateRequest(); | 135 request = ajax.generateRequest(); |
| 140 server.respond(); | 136 server.respond(); |
| 141 // TODO(crbug.com/740768): make the element call on-response handler a
utomatically | 137 front_page.addEventListener('processedConfigSets', function() { |
| 142 front_page._onGotConfigSets(request.response.event); | 138 front_page.query = "invalid-project"; |
| 143 front_page.query = "invalid-project"; | 139 assert.notEqual(front_page.configSetList, |
| 144 assert.notEqual(front_page.configSetList, | 140 front_page.searchResults); |
| 145 front_page.searchResults); | 141 assert.equal(front_page.searchResults[0].config_set, "invalid-projec
t"); |
| 146 assert.equal(front_page.searchResults[0].config_set, "invalid-project"
); | 142 done(); |
| 143 }.bind(front_page)); |
| 147 }); | 144 }); |
| 148 }); | 145 }); |
| 149 </script> | 146 </script> |
| 150 </body> | 147 </body> |
| 151 </html> | 148 </html> |
| OLD | NEW |