| <!DOCTYPE html> |
| <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> |
| <script src="/bower_components/webcomponentsjs/webcomponents-lite.min.js"></script> |
| <script src="/bower_components/web-component-tester/browser.js"></script> |
| |
| <link rel="import" href="/bower_components/polymer/polymer.html"> |
| |
| <title>gr-checkers-list-view</title> |
| <link rel="import" href="gr-checkers-list.html"> |
| |
| <test-fixture id="basic"> |
| <template is="dom-template"> |
| <gr-checkers-list |
| plugin-rest-api="[[pluginRestApi]]" |
| > |
| </gr-checkers-list> |
| </template> |
| </test-fixture> |
| |
| <script> |
| const CHECKERS = [ |
| { |
| "uuid":"C:D", |
| "name":"A", |
| "description":"B", |
| "repository":"Backend", |
| "status":"ENABLED", |
| "blocking":[ |
| |
| ], |
| "query":"status:open", |
| "created":"2019-07-25 13:08:43.000000000", |
| "updated":"2019-07-25 13:08:43.000000000" |
| }, |
| { |
| "uuid":"aa:bb", |
| "name":"n1", |
| "description":"d1", |
| "repository":"All-Users", |
| "status":"ENABLED", |
| "blocking":[ |
| |
| ], |
| "query":"status:open", |
| "created":"2019-07-29 13:07:17.000000000", |
| "updated":"2019-07-29 13:07:17.000000000" |
| }, |
| { |
| "uuid":"adsf:asdasdas", |
| "name":"ds", |
| "description":"s", |
| "repository":"Scripts", |
| "status":"ENABLED", |
| "blocking":[ |
| |
| ], |
| "query":"status:open", |
| "created":"2019-07-29 13:28:09.000000000", |
| "updated":"2019-07-29 13:28:09.000000000" |
| }, |
| { |
| "uuid":"ijkl:mnop", |
| "name":"abcd", |
| "description":"efgh", |
| "repository":"All-Projects", |
| "status":"ENABLED", |
| "blocking":[ |
| |
| ], |
| "query":"status:open", |
| "created":"2019-07-29 09:33:25.000000000", |
| "updated":"2019-07-29 09:33:25.000000000" |
| }, |
| { |
| "uuid":"ngfnf:mhghgnhghn", |
| "name":"nbvfg", |
| "description":"fjhgj", |
| "repository":"All-Users", |
| "status":"ENABLED", |
| "blocking":[ |
| |
| ], |
| "query":"status:open", |
| "created":"2019-08-06 14:21:34.000000000", |
| "updated":"2019-08-06 14:21:34.000000000" |
| }, |
| { |
| "uuid":"sdfsdf--:sdfsdf333", |
| "name":"sdfsdf", |
| "description":"sdfsdfsd", |
| "repository":"Scripts", |
| "status":"ENABLED", |
| "blocking":[ |
| |
| ], |
| "query":"status:open", |
| "created":"2019-07-30 13:00:19.000000000", |
| "updated":"2019-07-30 13:00:19.000000000" |
| }, |
| { |
| "uuid":"test:checker1", |
| "name":"Unit Tests", |
| "description":"Random description that should be improved at some point", |
| "repository":"Backend", |
| "status":"ENABLED", |
| "blocking":[ |
| |
| ], |
| "query":"status:open", |
| "created":"2019-07-22 13:16:52.000000000", |
| "updated":"2019-07-22 14:21:14.000000000" |
| }, |
| { |
| "uuid":"test:checker2", |
| "name":"Code Style", |
| "repository":"Backend", |
| "status":"ENABLED", |
| "blocking":[ |
| |
| ], |
| "query":"status:open", |
| "created":"2019-07-22 13:26:56.000000000", |
| "updated":"2019-07-22 13:26:56.000000000" |
| }, |
| { |
| "uuid":"xddf:sdfsdfsdf", |
| "name":"sdfsdf", |
| "description":"sdfsdf", |
| "repository":"Scripts", |
| "status":"ENABLED", |
| "blocking":[ |
| |
| ], |
| "query":"status:open", |
| "created":"2019-07-29 14:11:59.000000000", |
| "updated":"2019-07-29 14:11:59.000000000" |
| }, |
| { |
| "uuid":"zxczxc:bnvnbvnbvn", |
| "name":"zxc", |
| "description":"zxc", |
| "repository":"Scripts", |
| "status":"ENABLED", |
| "blocking":[ |
| |
| ], |
| "query":"status:open", |
| "created":"2019-07-29 14:00:24.000000000", |
| "updated":"2019-07-29 14:00:24.000000000" |
| }, |
| { |
| "uuid":"zxczxc:sdfsdf", |
| "name":"zxc", |
| "description":"zxc", |
| "repository":"Scripts", |
| "status":"ENABLED", |
| "blocking":[ |
| |
| ], |
| "query":"status:open", |
| "created":"2019-07-29 13:30:47.000000000", |
| "updated":"2019-07-29 13:30:47.000000000" |
| } |
| ]; |
| </script> |
| |
| <script> |
| |
| suite('gr-checkers-list tests', () => { |
| let element; |
| let sandbox; |
| let fetchJSONSpy, fetchJSONPromise, fetchJSONResolve; |
| |
| setup((done) => { |
| sandbox = sinon.sandbox.create(); |
| |
| fetchJSONSpy = sinon.stub(); |
| const fetchJSONPromise = new Promise((resolve, reject) => { |
| fetchJSONResolve = resolve; |
| }) |
| fetchJSONSpy.returns(fetchJSONPromise) |
| |
| const pluginRestApi = { |
| fetchJSON: fetchJSONSpy, |
| }; |
| |
| element = fixture('basic', { |
| pluginRestApi |
| }); |
| flush(done); |
| }); |
| |
| teardown(() => { sandbox.restore(); }); |
| |
| test('renders checker list table headings', () => { |
| const checkersList = element.$$('table') |
| const headings = checkersList.firstElementChild.firstElementChild. |
| children; |
| const expectedHeadings = ["Checker Name", "Repository", "Status", |
| "Required", "Checker Description", "Edit"]; |
| for (let i = 0;i < headings.length;i++) { |
| assert(headings[i].innerText === expectedHeadings[i]); |
| } |
| }); |
| |
| test('create checker button renders', () => { |
| assert(element.querySelector('#createNewContainer')); |
| const button = element.querySelector('#createNewContainer') |
| .querySelector('gr-button'); |
| assert(button); |
| assert(button.innerText === 'Create New'); |
| }); |
| |
| suite('with checkers', () => { |
| setup((done) => { |
| fetchJSONResolve(CHECKERS); |
| flush(done); |
| }) |
| test('renders correct number of checkers', () => { |
| const checkers = element.$$('table > tbody:nth-child(2)') |
| .querySelectorAll('tr'); |
| assert(checkers.length === CHECKERS.length); |
| }) |
| test('renders correct checkers', () => { |
| const checkers = element.$$('table > tbody:nth-child(2)') |
| .querySelectorAll('tr'); |
| for (let i = 0;i < checkers.length;i++) { |
| const checkerDetails = checkers[i].querySelectorAll('td'); |
| assert(CHECKERS[i].name === checkerDetails[0].innerText); |
| assert(CHECKERS[i].repository === checkerDetails[1].innerText); |
| const status = CHECKERS[i].status || "NO"; |
| assert(status === checkerDetails[2].innerText); |
| const checkerRequired = (CHECKERS[i].blocking && |
| CHECKERS[i].blocking.length > 0) |
| ? "YES": "NO"; |
| assert(checkerRequired === checkerDetails[3].innerText); |
| const description = CHECKERS[i].description || ''; |
| assert(description === checkerDetails[4].innerText); |
| } |
| }) |
| }); |
| |
| }); |
| </script> |