| <!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-view.html"> |
| |
| <test-fixture id="basic"> |
| <template is="dom-template"> |
| <gr-checks-view |
| change="[[change]]" |
| revision="[[revision]]" |
| get-checks="[[getChecks]]" |
| is-configured="[[isConfigured]]" |
| retry-check="[[retryCheck]]"> |
| </gr-checks-view> |
| </template> |
| </test-fixture> |
| |
| <script> |
| const CHECK1 = { |
| 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", |
| }; |
| const REVISION = { |
| "kind": "REWORK", |
| "_number": 3, |
| "created": "2018-05-15 21:56:13.000000000", |
| "uploader": { |
| "_account_id": 1000000, |
| }, |
| "ref": "refs/changes/00/1000/1", |
| "commit": { |
| "parents": [], |
| "subject": "added test file", |
| "message": "added test file\n\nChange-Id: I8df212a28ae23cc239afd10ee4f506887e03ab70\n", |
| "commit": "1c9a1dfd38ea51dc7880f3ddf669100710f0c91b" |
| }, |
| }; |
| |
| suite('gr-checks-view tests', () => { |
| let element; |
| let sandbox; |
| let getChecksSpy; |
| let getChecksResolve; |
| let retryCheckSpy; |
| let isConfiguredSpy; |
| let isConfiguredResolve; |
| |
| setup((done) => { |
| sandbox = sinon.sandbox.create(); |
| |
| getChecksSpy = sinon.stub(); |
| const getChecksPromise = new Promise((resolve, reject) => { |
| getChecksResolve = resolve; |
| }); |
| getChecksSpy.returns(getChecksPromise); |
| |
| isConfiguredSpy = sinon.stub(); |
| const isConfiguredPromise = new Promise((resolve, reject) => { |
| isConfiguredResolve = resolve; |
| }); |
| isConfiguredSpy.returns(isConfiguredPromise); |
| |
| retryCheckSpy = sinon.stub(); |
| retryCheckSpy.returns(Promise.resolve()); |
| |
| element = fixture('basic', { |
| retryCheck: retryCheckSpy, |
| getChecks: getChecksSpy, |
| isConfigured: isConfiguredSpy, |
| change: { |
| 'project': 'test-repository', |
| 'revisions': { |
| 'first-sha': "test-revision", |
| 'second-sha': REVISION, |
| } |
| }, |
| revision: REVISION, |
| }); |
| flush(done); |
| }); |
| |
| teardown(() => { sandbox.restore(); }); |
| |
| test('renders loading', () => { |
| assert.equal(element.textContent.trim(), 'Loading...'); |
| }); |
| |
| test('queries the checks', () => { |
| assert.isTrue(getChecksSpy.called); |
| assert.isTrue(getChecksSpy.calledWith('test-repository', 'second-sha')); |
| }); |
| |
| suite('no checks returned', () => { |
| setup((done) => { |
| getChecksResolve([]); |
| flush(done); |
| }); |
| |
| test('it calls to check if the checks are configured', () => { |
| assert.isTrue(isConfiguredSpy.called); |
| assert.isTrue(isConfiguredSpy.calledWith('test-repository')); |
| }); |
| |
| suite('not configured', () => { |
| setup((done) => { |
| isConfiguredResolve(false); |
| flush(done); |
| }); |
| |
| test('renders checks not configured', () => { |
| const header = element.$$('h2'); |
| assert.equal(header.textContent.trim(), 'Code review checks not configured'); |
| }); |
| }); |
| |
| suite('no checks ran', () => { |
| setup((done) => { |
| isConfiguredResolve(true); |
| flush(done); |
| }); |
| |
| test('renders checks not configured', () => { |
| const header = element.$$('h2'); |
| assert.equal(header.textContent.trim(), 'No checks ran for this code review'); |
| }); |
| }); |
| }); |
| |
| suite('with checks', () => { |
| setup(done => { |
| getChecksResolve([CHECK1, CHECK1, CHECK1]); |
| flush(done); |
| }); |
| |
| test('it calls to check if the checks are configured', () => { |
| assert.isFalse(isConfiguredSpy.called); |
| }); |
| |
| test('renders the header', () => { |
| const header = element.$$('header > h3'); |
| assert.equal(header.textContent.trim(), 'Latest checks for Patchset 3'); |
| }); |
| |
| test('renders a table of all the checks', () => { |
| const tbody = element.$$('table > tbody'); |
| assert.lengthOf(tbody.querySelectorAll('gr-checks-item'), 3) |
| }); |
| }); |
| }); |
| </script> |