2015-12-16 18:34:58 -05:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<!--
|
|
|
|
Copyright (C) 2015 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-patch-range-select</title>
|
|
|
|
|
2017-03-28 17:02:44 -07:00
|
|
|
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
|
2016-03-04 17:48:22 -05:00
|
|
|
<script src="../../../bower_components/web-component-tester/browser.js"></script>
|
2017-06-02 13:08:19 -04:00
|
|
|
<link rel="import" href="../../../test/common-test-setup.html"/>
|
2016-03-04 17:48:22 -05:00
|
|
|
<script src="../../../bower_components/page/page.js"></script>
|
2015-12-16 18:34:58 -05:00
|
|
|
|
2016-03-04 17:48:22 -05:00
|
|
|
<link rel="import" href="gr-patch-range-select.html">
|
2015-12-16 18:34:58 -05:00
|
|
|
|
2017-03-28 17:02:44 -07:00
|
|
|
<script>void(0);</script>
|
|
|
|
|
2015-12-16 18:34:58 -05:00
|
|
|
<test-fixture id="basic">
|
|
|
|
<template>
|
|
|
|
<gr-patch-range-select auto></gr-patch-range-select>
|
|
|
|
</template>
|
|
|
|
</test-fixture>
|
|
|
|
|
|
|
|
<script>
|
2017-05-16 14:41:17 -07:00
|
|
|
suite('gr-patch-range-select tests', () => {
|
|
|
|
let element;
|
2017-04-25 23:48:05 +02:00
|
|
|
let sandbox;
|
2015-12-16 18:34:58 -05:00
|
|
|
|
2017-05-16 14:41:17 -07:00
|
|
|
setup(() => {
|
2015-12-16 18:34:58 -05:00
|
|
|
element = fixture('basic');
|
2017-04-25 23:48:05 +02:00
|
|
|
sandbox = sinon.sandbox.create();
|
2015-12-16 18:34:58 -05:00
|
|
|
});
|
|
|
|
|
2017-04-25 23:48:05 +02:00
|
|
|
teardown(() => sandbox.restore());
|
|
|
|
|
2017-05-16 14:41:17 -07:00
|
|
|
test('enabled/disabled options', () => {
|
|
|
|
const patchRange = {
|
2015-12-16 18:34:58 -05:00
|
|
|
basePatchNum: 'PARENT',
|
|
|
|
patchNum: '3',
|
|
|
|
};
|
2017-09-12 16:54:19 -07:00
|
|
|
const sortedRevisions = [
|
2017-04-25 23:48:05 +02:00
|
|
|
{_number: 1},
|
|
|
|
{_number: 2},
|
|
|
|
{_number: element.EDIT_NAME, basePatchNum: 2},
|
|
|
|
{_number: 3},
|
|
|
|
];
|
2017-05-16 14:41:17 -07:00
|
|
|
for (const patchNum of ['1', '2', '3']) {
|
2017-09-12 16:54:19 -07:00
|
|
|
assert.isFalse(element._computeRightDisabled(patchNum,
|
|
|
|
patchRange.basePatchNum, sortedRevisions));
|
2017-05-16 14:41:17 -07:00
|
|
|
}
|
|
|
|
for (const patchNum of ['PARENT', '1', '2']) {
|
2017-09-12 16:54:19 -07:00
|
|
|
assert.isFalse(element._computeLeftDisabled(patchNum,
|
|
|
|
patchRange.patchNum, sortedRevisions));
|
2017-05-16 14:41:17 -07:00
|
|
|
}
|
2017-09-12 16:54:19 -07:00
|
|
|
assert.isTrue(element._computeLeftDisabled('3', patchRange.patchNum));
|
2015-12-16 18:34:58 -05:00
|
|
|
|
2017-04-25 23:48:05 +02:00
|
|
|
patchRange.basePatchNum = element.EDIT_NAME;
|
2017-09-12 16:54:19 -07:00
|
|
|
assert.isTrue(element._computeLeftDisabled('3', patchRange.patchNum,
|
|
|
|
sortedRevisions));
|
|
|
|
assert.isTrue(element._computeRightDisabled('1', patchRange.basePatchNum,
|
|
|
|
sortedRevisions));
|
|
|
|
assert.isTrue(element._computeRightDisabled('2', patchRange.basePatchNum,
|
|
|
|
sortedRevisions));
|
|
|
|
assert.isFalse(element._computeRightDisabled('3', patchRange.basePatchNum,
|
|
|
|
sortedRevisions));
|
|
|
|
assert.isTrue(element._computeRightDisabled(element.EDIT_NAME,
|
|
|
|
patchRange.basePatchNum, sortedRevisions));
|
2015-12-16 18:34:58 -05:00
|
|
|
});
|
|
|
|
|
2017-09-12 16:54:19 -07:00
|
|
|
test('_updateSelected called with subproperty changes', () => {
|
|
|
|
sandbox.stub(element, '_updateSelected');
|
|
|
|
element.patchRange = {patchNum: 1, basePatchNum: 'PARENT'};
|
|
|
|
assert.equal(element._updateSelected.callCount, 1);
|
|
|
|
|
|
|
|
element.set('patchRange.patchNum', 2);
|
|
|
|
assert.equal(element._updateSelected.callCount, 2);
|
|
|
|
|
|
|
|
element.set('patchRange.basePatchNum', 1);
|
|
|
|
assert.equal(element._updateSelected.callCount, 3);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('_computeLeftDisabled called when patchNum updates', () => {
|
|
|
|
element.revisions = [
|
|
|
|
{commit: {}},
|
|
|
|
{commit: {}},
|
|
|
|
{commit: {}},
|
|
|
|
{commit: {}},
|
|
|
|
];
|
|
|
|
element.availablePatches = [
|
|
|
|
{num: 1},
|
|
|
|
{num: 2},
|
|
|
|
{num: 3},
|
|
|
|
{num: 'edit'},
|
|
|
|
];
|
|
|
|
element.patchRange = {patchNum: 2, basePatchNum: 'PARENT'};
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
|
|
|
|
// Should be recomputed for each available patch
|
|
|
|
sandbox.stub(element, '_computeLeftDisabled');
|
|
|
|
element.set('patchRange.patchNum', '1');
|
|
|
|
assert.equal(element._computeLeftDisabled.callCount, 4);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('_computeRightDisabled called when basePatchNum updates', () => {
|
|
|
|
element.revisions = [
|
|
|
|
{commit: {}},
|
|
|
|
{commit: {}},
|
|
|
|
{commit: {}},
|
|
|
|
{commit: {}},
|
|
|
|
];
|
|
|
|
element.availablePatches = [
|
|
|
|
{num: 1},
|
|
|
|
{num: 2},
|
|
|
|
{num: 3},
|
|
|
|
{num: 'edit'},
|
|
|
|
];
|
|
|
|
element.patchRange = {patchNum: 2, basePatchNum: 'PARENT'};
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
|
|
|
|
// Should be recomputed for each available patch
|
|
|
|
sandbox.stub(element, '_computeRightDisabled');
|
|
|
|
element.set('patchRange.basePatchNum', '1');
|
|
|
|
assert.equal(element._computeRightDisabled.callCount, 4);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test('changes in patch range fire event', done => {
|
2017-04-25 23:48:05 +02:00
|
|
|
sandbox.stub(element, '_computeLeftDisabled').returns(false);
|
|
|
|
sandbox.stub(element, '_computeRightDisabled').returns(false);
|
2017-09-12 16:54:19 -07:00
|
|
|
const patchRangeChangedStub = sandbox.stub();
|
|
|
|
element.addEventListener('patch-range-change', patchRangeChangedStub);
|
|
|
|
|
2017-05-16 14:41:17 -07:00
|
|
|
const leftSelectEl = element.$.leftPatchSelect;
|
|
|
|
const rightSelectEl = element.$.rightPatchSelect;
|
2017-04-25 23:48:05 +02:00
|
|
|
const blurSpy = sandbox.spy(leftSelectEl, 'blur');
|
2015-12-16 18:34:58 -05:00
|
|
|
element.changeNum = '42';
|
|
|
|
element.path = 'path/to/file.txt';
|
2017-09-12 16:54:19 -07:00
|
|
|
element.availablePatches =
|
|
|
|
[{num: '1'}, {num: '2'}, {num: '3'}, {num: 'edit'}];
|
2016-10-27 18:52:56 -07:00
|
|
|
element.patchRange = {
|
|
|
|
basePatchNum: 'PARENT',
|
|
|
|
patchNum: '3',
|
|
|
|
};
|
2015-12-16 18:34:58 -05:00
|
|
|
flushAsynchronousOperations();
|
|
|
|
|
2017-05-16 14:41:17 -07:00
|
|
|
let numEvents = 0;
|
|
|
|
leftSelectEl.addEventListener('change', e => {
|
2015-12-16 18:34:58 -05:00
|
|
|
numEvents++;
|
2017-09-12 16:54:19 -07:00
|
|
|
if (numEvents === 1) {
|
|
|
|
assert.deepEqual(patchRangeChangedStub.lastCall.args[0].detail,
|
|
|
|
{rightPatch: '3', leftPatch: 'PARENT'});
|
|
|
|
leftSelectEl.nativeSelect.value = 'edit';
|
2015-12-16 18:34:58 -05:00
|
|
|
element.fire('change', {}, {node: leftSelectEl});
|
2016-08-30 12:44:27 -07:00
|
|
|
assert(blurSpy.called, 'Dropdown should be blurred after selection');
|
2017-09-12 16:54:19 -07:00
|
|
|
} else if (numEvents === 2) {
|
|
|
|
assert.deepEqual(patchRangeChangedStub.lastCall.args[0].detail,
|
|
|
|
{rightPatch: '3', leftPatch: 'edit'});
|
|
|
|
rightSelectEl.nativeSelect.value = '1';
|
|
|
|
element.fire('change', {}, {node: rightSelectEl});
|
2015-12-16 18:34:58 -05:00
|
|
|
}
|
|
|
|
});
|
2017-09-12 16:54:19 -07:00
|
|
|
rightSelectEl.addEventListener('change', e => {
|
|
|
|
assert.deepEqual(patchRangeChangedStub.lastCall.args[0].detail,
|
|
|
|
{rightPatch: '1', leftPatch: 'edit'});
|
|
|
|
done();
|
|
|
|
});
|
2017-07-05 14:12:44 -07:00
|
|
|
leftSelectEl.nativeSelect.value = 'PARENT';
|
|
|
|
rightSelectEl.nativeSelect.value = '3';
|
2015-12-16 18:34:58 -05:00
|
|
|
element.fire('change', {}, {node: leftSelectEl});
|
|
|
|
});
|
2016-08-03 13:16:36 -07:00
|
|
|
|
2017-09-12 16:54:19 -07:00
|
|
|
test('diff against dropdown', done => {
|
|
|
|
element.revisions = [
|
|
|
|
{commit: {}},
|
|
|
|
{commit: {}},
|
|
|
|
{commit: {}},
|
|
|
|
{commit: {}},
|
|
|
|
];
|
|
|
|
element.availablePatches = [
|
|
|
|
{num: 1},
|
|
|
|
{num: 2},
|
|
|
|
{num: 3},
|
|
|
|
{num: 'edit'},
|
|
|
|
];
|
|
|
|
element.patchRange = {
|
|
|
|
basePatchNum: 'PARENT',
|
|
|
|
patchNum: '3',
|
|
|
|
};
|
|
|
|
|
|
|
|
const patchRangeChangedStub = sandbox.stub();
|
|
|
|
element.addEventListener('patch-range-change', patchRangeChangedStub);
|
|
|
|
|
|
|
|
flush(() => {
|
|
|
|
const selectEl = element.$.leftPatchSelect;
|
|
|
|
assert.equal(selectEl.nativeSelect.value, 'PARENT');
|
|
|
|
assert.isTrue(element.$$('#leftPatchSelect option[value="3"]')
|
|
|
|
.hasAttribute('disabled'));
|
|
|
|
selectEl.addEventListener('change', () => {
|
|
|
|
assert.equal(selectEl.nativeSelect.value, 'edit');
|
|
|
|
assert.deepEqual(patchRangeChangedStub.lastCall.args[0].detail,
|
|
|
|
{leftPatch: 'edit', rightPatch: '3'});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
selectEl.nativeSelect.value = 'edit';
|
|
|
|
element.fire('change', {}, {node: selectEl.nativeSelect});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-16 14:41:17 -07:00
|
|
|
test('filesWeblinks', () => {
|
2016-08-03 13:16:36 -07:00
|
|
|
element.filesWeblinks = {
|
|
|
|
meta_a: [
|
|
|
|
{
|
|
|
|
name: 'foo',
|
|
|
|
url: 'f.oo',
|
2017-05-16 14:41:17 -07:00
|
|
|
},
|
2016-08-03 13:16:36 -07:00
|
|
|
],
|
|
|
|
meta_b: [
|
|
|
|
{
|
|
|
|
name: 'bar',
|
|
|
|
url: 'ba.r',
|
2017-05-16 14:41:17 -07:00
|
|
|
},
|
2016-08-03 13:16:36 -07:00
|
|
|
],
|
|
|
|
};
|
|
|
|
flushAsynchronousOperations();
|
2017-05-16 14:41:17 -07:00
|
|
|
const domApi = Polymer.dom(element.root);
|
2016-08-03 13:16:36 -07:00
|
|
|
assert.equal(
|
|
|
|
domApi.querySelector('a[href="f.oo"]').textContent, 'foo');
|
|
|
|
assert.equal(
|
|
|
|
domApi.querySelector('a[href="ba.r"]').textContent, 'bar');
|
|
|
|
});
|
2017-09-12 16:54:19 -07:00
|
|
|
|
|
|
|
test('_computePatchSetCommentsString', () => {
|
|
|
|
// Test string with unresolved comments.
|
|
|
|
comments = {
|
|
|
|
foo: [{
|
|
|
|
id: '27dcee4d_f7b77cfa',
|
|
|
|
message: 'test',
|
|
|
|
patch_set: 1,
|
|
|
|
unresolved: true,
|
|
|
|
}],
|
|
|
|
bar: [{
|
|
|
|
id: '27dcee4d_f7b77cfa',
|
|
|
|
message: 'test',
|
|
|
|
patch_set: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: '27dcee4d_f7b77cfa',
|
|
|
|
message: 'test',
|
|
|
|
patch_set: 1,
|
|
|
|
}],
|
|
|
|
abc: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.equal(element._computePatchSetCommentsString(comments, 1),
|
|
|
|
'(3 comments, 1 unresolved)');
|
|
|
|
|
|
|
|
// Test string with no unresolved comments.
|
|
|
|
delete comments['foo'];
|
|
|
|
assert.equal(element._computePatchSetCommentsString(comments, 1),
|
|
|
|
'(2 comments)');
|
|
|
|
|
|
|
|
// Test string with no comments.
|
|
|
|
delete comments['bar'];
|
|
|
|
assert.equal(element._computePatchSetCommentsString(comments, 1), '');
|
|
|
|
});
|
2015-12-16 18:34:58 -05:00
|
|
|
});
|
|
|
|
</script>
|