brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> |
Tao Zhou | 737bb53 | 2020-04-17 17:24:05 +0200 | [diff] [blame^] | 3 | <script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script> |
| 4 | <script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script> |
| 5 | <script src="../bower_components/web-component-tester/browser.js"></script> |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 6 | |
| 7 | <title>gr-checks-item</title> |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 8 | |
| 9 | <test-fixture id="basic"> |
Tao Zhou | 737bb53 | 2020-04-17 17:24:05 +0200 | [diff] [blame^] | 10 | <template> |
| 11 | <gr-checks-item></gr-checks-item> |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 12 | </template> |
| 13 | </test-fixture> |
| 14 | |
Tao Zhou | 737bb53 | 2020-04-17 17:24:05 +0200 | [diff] [blame^] | 15 | <script type="module"> |
| 16 | import '../test/common-test-setup.js'; |
| 17 | import './gr-checks-item.js'; |
Dhruv Srivastava | b36d37d | 2020-02-28 21:42:32 +0100 | [diff] [blame] | 18 | const CHECKS_ITEM = { |
| 19 | MESSAGE: 1, |
| 20 | NAME: 2, |
| 21 | BLOCKING: 3, |
| 22 | STATUS: 4, |
| 23 | START_TIME: 5, |
| 24 | DURATION: 6, |
| 25 | DETAILS: 7, |
| 26 | RERUN: 8, |
| 27 | DESCRIPTION: 9, |
| 28 | }; |
Tao Zhou | 737bb53 | 2020-04-17 17:24:05 +0200 | [diff] [blame^] | 29 | suite('gr-checks-item tests', () => { |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 30 | let element; |
| 31 | let sandbox; |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 32 | let retryCheckSpy; |
| 33 | |
Dhruv Srivastava | 5a86ef7 | 2019-12-09 20:10:26 +0100 | [diff] [blame] | 34 | setup(done => { |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 35 | sandbox = sinon.sandbox.create(); |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 36 | retryCheckSpy = sinon.stub(); |
| 37 | retryCheckSpy.returns(Promise.resolve()); |
| 38 | |
Tao Zhou | 737bb53 | 2020-04-17 17:24:05 +0200 | [diff] [blame^] | 39 | element = fixture('basic'); |
| 40 | element.retryCheck = retryCheckSpy; |
| 41 | element.check = { |
| 42 | checkId: 'test-check-id', |
| 43 | url: 'http://example.com/test-log-url', |
| 44 | started: '2019-02-06T22:25:19.269Z', |
| 45 | finished: '2019-02-06T22:25:44.574Z', |
| 46 | }; |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 47 | flush(done); |
| 48 | }); |
| 49 | |
| 50 | teardown(() => { sandbox.restore(); }); |
| 51 | |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 52 | test('renders the status', () => { |
Dhruv Srivastava | b36d37d | 2020-02-28 21:42:32 +0100 | [diff] [blame] | 53 | const idx = CHECKS_ITEM.STATUS; |
Tao Zhou | 737bb53 | 2020-04-17 17:24:05 +0200 | [diff] [blame^] | 54 | const status = element.shadowRoot |
| 55 | .querySelector(`td:nth-of-type(${idx}) > gr-checks-status`); |
| 56 | assert.isOk(status); |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 57 | }); |
| 58 | |
Dhruv Srivastava | 25d549d | 2020-02-06 11:13:53 +0100 | [diff] [blame] | 59 | test('renders the start time', () => { |
| 60 | assert.equal(element._startTime, '2019-02-06T22:25:19.269Z'); |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 61 | }); |
| 62 | |
| 63 | suite('duration', () => { |
| 64 | test('renders the run duration', () => { |
Dhruv Srivastava | b36d37d | 2020-02-28 21:42:32 +0100 | [diff] [blame] | 65 | const idx = CHECKS_ITEM.DURATION; |
Tao Zhou | 737bb53 | 2020-04-17 17:24:05 +0200 | [diff] [blame^] | 66 | const name = element.$$(`td:nth-of-type(${idx})`); |
| 67 | assert.equal(name.textContent.trim(), '25 sec'); |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 68 | }); |
| 69 | |
| 70 | test('renders 0 sec when the start and end time are the same', () => { |
| 71 | element.check = { |
| 72 | checkId: 'test-check-id', |
Dhruv Srivastava | a0e6632 | 2019-07-04 15:59:36 +0200 | [diff] [blame] | 73 | url: 'http://example.com/test-log-url', |
Dhruv Srivastava | 5a86ef7 | 2019-12-09 20:10:26 +0100 | [diff] [blame] | 74 | started: '2019-02-06T22:25:19.269Z', |
| 75 | finished: '2019-02-06T22:25:19.269Z', |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 76 | }; |
Dhruv Srivastava | b36d37d | 2020-02-28 21:42:32 +0100 | [diff] [blame] | 77 | const idx = CHECKS_ITEM.DURATION; |
Tao Zhou | 737bb53 | 2020-04-17 17:24:05 +0200 | [diff] [blame^] | 78 | const name = element.shadowRoot |
| 79 | .querySelector(`td:nth-of-type(${idx})`); |
| 80 | assert.equal(name.textContent.trim(), '0 sec'); |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 81 | }); |
| 82 | }); |
| 83 | |
| 84 | test('renders a link to the log', () => { |
Dhruv Srivastava | b36d37d | 2020-02-28 21:42:32 +0100 | [diff] [blame] | 85 | const idx = CHECKS_ITEM.DETAILS; |
Tao Zhou | 737bb53 | 2020-04-17 17:24:05 +0200 | [diff] [blame^] | 86 | const logLink = element.shadowRoot |
| 87 | .querySelector(`td:nth-of-type(${idx}) > a`); |
Dhruv Srivastava | 5a86ef7 | 2019-12-09 20:10:26 +0100 | [diff] [blame] | 88 | assert.equal(logLink.getAttribute('href'), |
| 89 | 'http://example.com/test-log-url'); |
Dhruv Srivastava | 387e126 | 2020-02-28 11:01:16 +0100 | [diff] [blame] | 90 | assert.equal(logLink.textContent.trim(), 'Details'); |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 91 | }); |
brohlfs | dd9ebb6 | 2019-03-28 10:23:08 +0100 | [diff] [blame] | 92 | }); |
| 93 | </script> |