blob: e9ce40128fce1b531c8e036bf9e81727c29a7a12 [file] [log] [blame]
brohlfsdd9ebb62019-03-28 10:23:08 +01001<!DOCTYPE html>
2<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
Tao Zhou737bb532020-04-17 17:24:05 +02003<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>
brohlfsdd9ebb62019-03-28 10:23:08 +01006
7<title>gr-checks-item</title>
brohlfsdd9ebb62019-03-28 10:23:08 +01008
9<test-fixture id="basic">
Tao Zhou737bb532020-04-17 17:24:05 +020010 <template>
11 <gr-checks-item></gr-checks-item>
brohlfsdd9ebb62019-03-28 10:23:08 +010012 </template>
13</test-fixture>
14
Tao Zhou737bb532020-04-17 17:24:05 +020015<script type="module">
16 import '../test/common-test-setup.js';
17 import './gr-checks-item.js';
Dhruv Srivastavab36d37d2020-02-28 21:42:32 +010018 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 Zhou737bb532020-04-17 17:24:05 +020029 suite('gr-checks-item tests', () => {
brohlfsdd9ebb62019-03-28 10:23:08 +010030 let element;
31 let sandbox;
brohlfsdd9ebb62019-03-28 10:23:08 +010032 let retryCheckSpy;
33
Dhruv Srivastava5a86ef72019-12-09 20:10:26 +010034 setup(done => {
brohlfsdd9ebb62019-03-28 10:23:08 +010035 sandbox = sinon.sandbox.create();
brohlfsdd9ebb62019-03-28 10:23:08 +010036 retryCheckSpy = sinon.stub();
37 retryCheckSpy.returns(Promise.resolve());
38
Tao Zhou737bb532020-04-17 17:24:05 +020039 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 };
brohlfsdd9ebb62019-03-28 10:23:08 +010047 flush(done);
48 });
49
50 teardown(() => { sandbox.restore(); });
51
brohlfsdd9ebb62019-03-28 10:23:08 +010052 test('renders the status', () => {
Dhruv Srivastavab36d37d2020-02-28 21:42:32 +010053 const idx = CHECKS_ITEM.STATUS;
Tao Zhou737bb532020-04-17 17:24:05 +020054 const status = element.shadowRoot
55 .querySelector(`td:nth-of-type(${idx}) > gr-checks-status`);
56 assert.isOk(status);
brohlfsdd9ebb62019-03-28 10:23:08 +010057 });
58
Dhruv Srivastava25d549d2020-02-06 11:13:53 +010059 test('renders the start time', () => {
60 assert.equal(element._startTime, '2019-02-06T22:25:19.269Z');
brohlfsdd9ebb62019-03-28 10:23:08 +010061 });
62
63 suite('duration', () => {
64 test('renders the run duration', () => {
Dhruv Srivastavab36d37d2020-02-28 21:42:32 +010065 const idx = CHECKS_ITEM.DURATION;
Tao Zhou737bb532020-04-17 17:24:05 +020066 const name = element.$$(`td:nth-of-type(${idx})`);
67 assert.equal(name.textContent.trim(), '25 sec');
brohlfsdd9ebb62019-03-28 10:23:08 +010068 });
69
70 test('renders 0 sec when the start and end time are the same', () => {
71 element.check = {
72 checkId: 'test-check-id',
Dhruv Srivastavaa0e66322019-07-04 15:59:36 +020073 url: 'http://example.com/test-log-url',
Dhruv Srivastava5a86ef72019-12-09 20:10:26 +010074 started: '2019-02-06T22:25:19.269Z',
75 finished: '2019-02-06T22:25:19.269Z',
brohlfsdd9ebb62019-03-28 10:23:08 +010076 };
Dhruv Srivastavab36d37d2020-02-28 21:42:32 +010077 const idx = CHECKS_ITEM.DURATION;
Tao Zhou737bb532020-04-17 17:24:05 +020078 const name = element.shadowRoot
79 .querySelector(`td:nth-of-type(${idx})`);
80 assert.equal(name.textContent.trim(), '0 sec');
brohlfsdd9ebb62019-03-28 10:23:08 +010081 });
82 });
83
84 test('renders a link to the log', () => {
Dhruv Srivastavab36d37d2020-02-28 21:42:32 +010085 const idx = CHECKS_ITEM.DETAILS;
Tao Zhou737bb532020-04-17 17:24:05 +020086 const logLink = element.shadowRoot
87 .querySelector(`td:nth-of-type(${idx}) > a`);
Dhruv Srivastava5a86ef72019-12-09 20:10:26 +010088 assert.equal(logLink.getAttribute('href'),
89 'http://example.com/test-log-url');
Dhruv Srivastava387e1262020-02-28 11:01:16 +010090 assert.equal(logLink.textContent.trim(), 'Details');
brohlfsdd9ebb62019-03-28 10:23:08 +010091 });
brohlfsdd9ebb62019-03-28 10:23:08 +010092 });
93</script>