In this CL, I am simply forwarding the entire API to gr-diff. In follow-up CLs, I will move the restAPI calls over, but I think it will be easier to understand the changes when all the forwarding is already out of the way. I decided not to touch the styling applied to gr-diff from gr-diff-view and gr-file-list because that currently does not hurt anyone and seems less risky. Bug: Issue 9623 Change-Id: Iacc82198b04b048dd33c380876b1c8b3a80fac95
301 lines
9.4 KiB
HTML
301 lines
9.4 KiB
HTML
<!DOCTYPE html>
|
|
<!--
|
|
@license
|
|
Copyright (C) 2018 The Android Open Source Project
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
-->
|
|
|
|
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
|
|
<title>gr-diff</title>
|
|
|
|
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
|
|
<script src="../../../bower_components/web-component-tester/browser.js"></script>
|
|
<link rel="import" href="../../../test/common-test-setup.html"/>
|
|
|
|
<link rel="import" href="gr-diff-host.html">
|
|
|
|
<script>void(0);</script>
|
|
|
|
<test-fixture id="basic">
|
|
<template>
|
|
<gr-diff-host></gr-diff-host>
|
|
</template>
|
|
</test-fixture>
|
|
|
|
<script>
|
|
suite('gr-diff-host tests', () => {
|
|
let element;
|
|
let sandbox;
|
|
|
|
setup(() => {
|
|
sandbox = sinon.sandbox.create();
|
|
});
|
|
|
|
teardown(() => {
|
|
sandbox.restore();
|
|
});
|
|
|
|
test('delegates reload()', () => {
|
|
element = fixture('basic');
|
|
const returnValue = Promise.resolve();
|
|
const stub = sandbox.stub(element.$.diff, 'reload').returns(returnValue);
|
|
assert.equal(element.reload(), returnValue);
|
|
assert.isTrue(stub.calledOnce);
|
|
assert.equal(stub.lastCall.args.length, 0);
|
|
});
|
|
|
|
test('delegates cancel()', () => {
|
|
element = fixture('basic');
|
|
const stub = sandbox.stub(element.$.diff, 'cancel');
|
|
element.reload();
|
|
assert.isTrue(stub.calledOnce);
|
|
assert.equal(stub.lastCall.args.length, 0);
|
|
});
|
|
|
|
test('delegates getCursorStops()', () => {
|
|
element = fixture('basic');
|
|
const returnValue = [document.createElement('b')];
|
|
const stub = sandbox.stub(element.$.diff, 'getCursorStops')
|
|
.returns(returnValue);
|
|
assert.equal(element.getCursorStops(), returnValue);
|
|
assert.isTrue(stub.calledOnce);
|
|
assert.equal(stub.lastCall.args.length, 0);
|
|
});
|
|
|
|
test('delegates isRangeSelected()', () => {
|
|
element = fixture('basic');
|
|
const returnValue = true;
|
|
const stub = sandbox.stub(element.$.diff, 'isRangeSelected')
|
|
.returns(returnValue);
|
|
assert.equal(element.isRangeSelected(), returnValue);
|
|
assert.isTrue(stub.calledOnce);
|
|
assert.equal(stub.lastCall.args.length, 0);
|
|
});
|
|
|
|
test('delegates toggleLeftDiff()', () => {
|
|
element = fixture('basic');
|
|
const stub = sandbox.stub(element.$.diff, 'toggleLeftDiff');
|
|
element.toggleLeftDiff();
|
|
assert.isTrue(stub.calledOnce);
|
|
assert.equal(stub.lastCall.args.length, 0);
|
|
});
|
|
|
|
test('delegates loadBlame()', () => {
|
|
element = fixture('basic');
|
|
const returnValue = Promise.resolve();
|
|
const stub = sandbox.stub(element.$.diff, 'loadBlame')
|
|
.returns(returnValue);
|
|
assert.equal(element.loadBlame(), returnValue);
|
|
assert.isTrue(stub.calledOnce);
|
|
assert.equal(stub.lastCall.args.length, 0);
|
|
});
|
|
|
|
test('delegates clearBlame()', () => {
|
|
element = fixture('basic');
|
|
const stub = sandbox.stub(element.$.diff, 'clearBlame');
|
|
element.clearBlame();
|
|
assert.isTrue(stub.calledOnce);
|
|
assert.equal(stub.lastCall.args.length, 0);
|
|
});
|
|
|
|
test('delegates getThreadEls()', () => {
|
|
element = fixture('basic');
|
|
const returnValue = [document.createElement('b')];
|
|
const stub = sandbox.stub(element.$.diff, 'getThreadEls')
|
|
.returns(returnValue);
|
|
assert.equal(element.getThreadEls(), returnValue);
|
|
assert.isTrue(stub.calledOnce);
|
|
assert.equal(stub.lastCall.args.length, 0);
|
|
});
|
|
|
|
test('delegates addDraftAtLine(el)', () => {
|
|
element = fixture('basic');
|
|
const param0 = document.createElement('b');
|
|
const stub = sandbox.stub(element.$.diff, 'addDraftAtLine');
|
|
element.addDraftAtLine(param0);
|
|
assert.isTrue(stub.calledOnce);
|
|
assert.equal(stub.lastCall.args.length, 1);
|
|
assert.equal(stub.lastCall.args[0], param0);
|
|
});
|
|
|
|
test('delegates clearDiffContent()', () => {
|
|
element = fixture('basic');
|
|
const stub = sandbox.stub(element.$.diff, 'clearDiffContent');
|
|
element.clearDiffContent();
|
|
assert.isTrue(stub.calledOnce);
|
|
assert.equal(stub.lastCall.args.length, 0);
|
|
});
|
|
|
|
test('delegates expandAllContext()', () => {
|
|
element = fixture('basic');
|
|
const stub = sandbox.stub(element.$.diff, 'expandAllContext');
|
|
element.expandAllContext();
|
|
assert.isTrue(stub.calledOnce);
|
|
assert.equal(stub.lastCall.args.length, 0);
|
|
});
|
|
|
|
test('passes in changeNum', () => {
|
|
element = fixture('basic');
|
|
const value = '12345';
|
|
element.changeNum = value;
|
|
assert.equal(element.$.diff.changeNum, value);
|
|
});
|
|
|
|
test('passes in noAutoRender', () => {
|
|
element = fixture('basic');
|
|
const value = true;
|
|
element.noAutoRender = value;
|
|
assert.equal(element.$.diff.noAutoRender, value);
|
|
});
|
|
|
|
test('passes in patchRange', () => {
|
|
element = fixture('basic');
|
|
const value = {patchNum: 'foo', basePatchNum: 'bar'};
|
|
element.patchRange = value;
|
|
assert.equal(element.$.diff.patchRange, value);
|
|
});
|
|
|
|
test('passes in path', () => {
|
|
element = fixture('basic');
|
|
const value = 'some/file/path';
|
|
element.path = value;
|
|
assert.equal(element.$.diff.path, value);
|
|
});
|
|
|
|
test('passes in prefs', () => {
|
|
element = fixture('basic');
|
|
const value = {};
|
|
element.prefs = value;
|
|
assert.equal(element.$.diff.prefs, value);
|
|
});
|
|
|
|
test('passes in projectConfig', () => {
|
|
element = fixture('basic');
|
|
const value = {};
|
|
element.projectConfig = value;
|
|
assert.equal(element.$.diff.projectConfig, value);
|
|
});
|
|
|
|
test('passes in changeNum', () => {
|
|
element = fixture('basic');
|
|
const value = '12345';
|
|
element.changeNum = value;
|
|
assert.equal(element.$.diff.changeNum, value);
|
|
});
|
|
|
|
test('passes in projectName', () => {
|
|
element = fixture('basic');
|
|
const value = 'Gerrit';
|
|
element.projectName = value;
|
|
assert.equal(element.$.diff.projectName, value);
|
|
});
|
|
|
|
test('passes in displayLine', () => {
|
|
element = fixture('basic');
|
|
const value = true;
|
|
element.displayLine = value;
|
|
assert.equal(element.$.diff.displayLine, value);
|
|
});
|
|
|
|
test('passes out isImageDiff', () => {
|
|
element = fixture('basic');
|
|
const value = true;
|
|
// isImageDiff is computed, so we cannot just set it.
|
|
sandbox.stub(element.$.diff, '_computeIsImageDiff').returns(value);
|
|
element.$.diff._diff = {left: [], right: [], content: []};
|
|
|
|
assert.equal(element.isImageDiff, value);
|
|
});
|
|
|
|
test('passes in commitRange', () => {
|
|
element = fixture('basic');
|
|
const value = {};
|
|
element.commitRange = value;
|
|
assert.equal(element.$.diff.commitRange, value);
|
|
});
|
|
|
|
test('passes in filesWeblinks', () => {
|
|
element = fixture('basic');
|
|
const value = {};
|
|
element.filesWeblinks = value;
|
|
assert.equal(element.$.diff.filesWeblinks, value);
|
|
});
|
|
|
|
test('passes out filesWeblinks', () => {
|
|
element = fixture('basic');
|
|
const value = {};
|
|
element.$.diff.filesWeblinks = value;
|
|
assert.equal(element.filesWeblinks, value);
|
|
});
|
|
|
|
test('passes in hidden', () => {
|
|
element = fixture('basic');
|
|
const value = true;
|
|
element.hidden = value;
|
|
assert.equal(element.$.diff.hidden, value);
|
|
assert.isNotNull(element.getAttribute('hidden'));
|
|
});
|
|
|
|
test('passes in noRenderOnPrefsChange', () => {
|
|
element = fixture('basic');
|
|
const value = true;
|
|
element.noRenderOnPrefsChange = value;
|
|
assert.equal(element.$.diff.noRenderOnPrefsChange, value);
|
|
});
|
|
|
|
test('passes in comments', () => {
|
|
element = fixture('basic');
|
|
const value = {left: [], right: []};
|
|
element.comments = value;
|
|
assert.equal(element.$.diff.comments, value);
|
|
});
|
|
|
|
test('passes in lineWrapping', () => {
|
|
element = fixture('basic');
|
|
const value = true;
|
|
element.lineWrapping = value;
|
|
assert.equal(element.$.diff.lineWrapping, value);
|
|
});
|
|
|
|
test('passes in viewMode', () => {
|
|
element = fixture('basic');
|
|
const value = 'SIDE_BY_SIDE';
|
|
element.viewMode = value;
|
|
assert.equal(element.$.diff.viewMode, value);
|
|
});
|
|
|
|
test('passes in lineOfInterest', () => {
|
|
element = fixture('basic');
|
|
const value = {number: 123, leftSide: true};
|
|
element.lineOfInterest = value;
|
|
assert.equal(element.$.diff.lineOfInterest, value);
|
|
});
|
|
|
|
test('passes in showLoadFailure', () => {
|
|
element = fixture('basic');
|
|
const value = true;
|
|
element.showLoadFailure = value;
|
|
assert.equal(element.$.diff.showLoadFailure, value);
|
|
});
|
|
|
|
test('passes out isBlameLoaded', () => {
|
|
element = fixture('basic');
|
|
const value = true;
|
|
sandbox.stub(element.$.diff, '_computeIsBlameLoaded').returns(value);
|
|
element.$.diff._blame = {};
|
|
assert.equal(element.isBlameLoaded, value);
|
|
});
|
|
});
|
|
</script>
|