blob: ef133aa1f36901310364bd532dd8a729e6b64f9d [file] [log] [blame]
<!DOCTYPE html>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<script src="imports.js"></script>
<script src="webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="polymer/polymer.html">
<title>gr-checks-item</title>
<link rel="import" href="webcomponent_lib/gr-checks-item.html">
<test-fixture id="basic">
<template is="dom-template">
<gr-checks-item
check="{{check}}"
retry-check="[[retryCheck]]">
</gr-checks-item>
</template>
</test-fixture>
<script>
suite('gr-checks-item tests', () => {
let element;
let sandbox;
let retryCheckSpy;
setup((done) => {
sandbox = sinon.sandbox.create();
retryCheckSpy = sinon.stub();
retryCheckSpy.returns(Promise.resolve());
element = fixture('basic', {
retryCheck: retryCheckSpy,
check: {
checkId: 'test-check-id',
logUrl: 'http://example.com/test-log-url',
startTime: "2019-02-06T22:25:19.269Z",
finishTime: "2019-02-06T22:25:44.574Z",
},
});
flush(done);
});
teardown(() => { sandbox.restore(); });
test('renders the status', () => {
const status = element.$$('td:nth-child(3) > gr-checks-status');
assert.exists(status);
});
test('renders the checking system', () => {
const checkingSystem = element.$$('td:nth-child(4)');
assert.equal(checkingSystem .textContent.trim(), "Check System");
});
test('renders the run date', () => {
const name = element.$$('td:nth-child(5)');
assert.equal(name .textContent.trim(), "2/6/2019");
});
suite('duration', () => {
test('renders the run duration', () => {
const name = element.$$('td:nth-child(6)');
assert.equal(name .textContent.trim(), "25 sec");
});
test('renders 0 sec when the start and end time are the same', () => {
element.check = {
checkId: 'test-check-id',
logUrl: 'http://example.com/test-log-url',
startTime: "2019-02-06T22:25:19.269Z",
finishTime: "2019-02-06T22:25:19.269Z",
};
const name = element.$$('td:nth-child(6)');
assert.equal(name .textContent.trim(), "0 sec");
});
});
test('renders a link to the log', () => {
const logLink = element.$$('td:nth-child(7) > a');
assert.equal(logLink.getAttribute('href'), "http://example.com/test-log-url");
assert.equal(logLink.textContent.trim(), "View log");
});
suite('retryCheck', () => {
let retryCheckLink;
setup(() => {
retryCheckLink = element.$$('td:nth-child(7) > gr-button');
});
test('shows a link to the log url', () => {
assert.equal(retryCheckLink.textContent.trim(), "Re-run");
});
test('clicking on the link calls the retryCheck property', () => {
assert.isFalse(retryCheckSpy.called);
retryCheckLink.click();
assert.isTrue(retryCheckSpy.called);
});
});
});
</script>