2015-11-14 15:40:47 -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">
|
2015-11-18 16:31:18 -05:00
|
|
|
<title>gr-diff-view</title>
|
2015-11-14 15:40:47 -05:00
|
|
|
|
2016-03-04 17:48:22 -05:00
|
|
|
<script src="../../../bower_components/webcomponentsjs/webcomponents.min.js"></script>
|
|
|
|
<script src="../../../bower_components/web-component-tester/browser.js"></script>
|
|
|
|
<script src="../../../bower_components/page/page.js"></script>
|
|
|
|
<script src="../../../scripts/util.js"></script>
|
2015-11-25 19:08:45 -05:00
|
|
|
|
2016-03-04 17:48:22 -05:00
|
|
|
<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
|
|
|
|
<link rel="import" href="gr-diff-view.html">
|
2015-11-14 15:40:47 -05:00
|
|
|
|
|
|
|
<test-fixture id="basic">
|
2015-12-02 13:17:35 -05:00
|
|
|
<template>
|
|
|
|
<gr-diff-view></gr-diff-view>
|
|
|
|
</template>
|
|
|
|
</test-fixture>
|
|
|
|
|
2016-08-25 12:35:50 -07:00
|
|
|
<test-fixture id="blank">
|
|
|
|
<template>
|
|
|
|
<div></div>
|
|
|
|
</template>
|
2016-09-16 10:44:37 -07:00
|
|
|
</test-fixture>
|
2016-08-25 12:35:50 -07:00
|
|
|
|
2015-11-14 15:40:47 -05:00
|
|
|
<script>
|
2015-12-11 12:02:57 -05:00
|
|
|
suite('gr-diff-view tests', function() {
|
2015-11-14 15:40:47 -05:00
|
|
|
var element;
|
2015-12-02 13:17:35 -05:00
|
|
|
|
2015-11-14 15:40:47 -05:00
|
|
|
setup(function() {
|
2016-03-29 14:06:39 -04:00
|
|
|
stub('gr-rest-api-interface', {
|
|
|
|
getLoggedIn: function() { return Promise.resolve(false); },
|
2016-04-05 16:06:57 -04:00
|
|
|
getProjectConfig: function() { return Promise.resolve({}); },
|
|
|
|
getDiffChangeDetail: function() { return Promise.resolve(null); },
|
|
|
|
getChangeFiles: function() { return Promise.resolve({}); },
|
|
|
|
saveFileReviewed: function() { return Promise.resolve(); },
|
2016-03-29 14:06:39 -04:00
|
|
|
});
|
2015-11-14 15:40:47 -05:00
|
|
|
element = fixture('basic');
|
2015-12-02 13:17:35 -05:00
|
|
|
});
|
2015-11-14 15:40:47 -05:00
|
|
|
|
2016-08-10 11:53:12 -07:00
|
|
|
test('toggle left diff with a hotkey', function() {
|
|
|
|
var toggleLeftDiffStub = sinon.stub(element.$.diff, 'toggleLeftDiff');
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 65, 'shift'); // 'a'
|
|
|
|
assert.isTrue(toggleLeftDiffStub.calledOnce);
|
|
|
|
toggleLeftDiffStub.restore();
|
|
|
|
});
|
|
|
|
|
2015-12-01 01:02:00 -05:00
|
|
|
test('keyboard shortcuts', function() {
|
|
|
|
element._changeNum = '42';
|
2015-12-11 12:02:57 -05:00
|
|
|
element._patchRange = {
|
2016-05-11 14:31:49 -04:00
|
|
|
basePatchNum: 'PARENT',
|
2015-12-11 12:02:57 -05:00
|
|
|
patchNum: '10',
|
|
|
|
};
|
2016-02-25 11:51:15 -05:00
|
|
|
element._change = {
|
|
|
|
revisions: {
|
2016-04-29 22:25:51 +02:00
|
|
|
a: {_number: 10},
|
2016-02-25 11:51:15 -05:00
|
|
|
},
|
|
|
|
};
|
2015-12-01 01:02:00 -05:00
|
|
|
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
|
|
|
|
element._path = 'glados.txt';
|
2016-02-03 20:40:36 -08:00
|
|
|
element.changeViewState.selectedFileIndex = 1;
|
2015-12-01 01:02:00 -05:00
|
|
|
|
|
|
|
var showStub = sinon.stub(page, 'show');
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 85); // 'u'
|
2016-02-25 11:51:15 -05:00
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/'),
|
|
|
|
'Should navigate to /c/42/');
|
2015-12-01 01:02:00 -05:00
|
|
|
|
2016-01-11 17:20:53 -05:00
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 221); // ']'
|
2015-12-01 01:02:00 -05:00
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/10/wheatley.md'),
|
|
|
|
'Should navigate to /c/42/10/wheatley.md');
|
|
|
|
element._path = 'wheatley.md';
|
2016-02-03 20:40:36 -08:00
|
|
|
assert.equal(element.changeViewState.selectedFileIndex, 2);
|
2015-12-01 01:02:00 -05:00
|
|
|
|
2016-01-11 17:20:53 -05:00
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
|
2015-12-01 01:02:00 -05:00
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/10/glados.txt'),
|
|
|
|
'Should navigate to /c/42/10/glados.txt');
|
|
|
|
element._path = 'glados.txt';
|
2016-02-03 20:40:36 -08:00
|
|
|
assert.equal(element.changeViewState.selectedFileIndex, 1);
|
2015-12-01 01:02:00 -05:00
|
|
|
|
2016-01-11 17:20:53 -05:00
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
|
2015-12-01 01:02:00 -05:00
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/10/chell.go'),
|
|
|
|
'Should navigate to /c/42/10/chell.go');
|
|
|
|
element._path = 'chell.go';
|
2016-02-03 20:40:36 -08:00
|
|
|
assert.equal(element.changeViewState.selectedFileIndex, 0);
|
2015-12-01 01:02:00 -05:00
|
|
|
|
2016-01-11 17:20:53 -05:00
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
|
2016-02-25 11:51:15 -05:00
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/'),
|
|
|
|
'Should navigate to /c/42/');
|
2016-02-03 20:40:36 -08:00
|
|
|
assert.equal(element.changeViewState.selectedFileIndex, 0);
|
2015-12-01 01:02:00 -05:00
|
|
|
|
2016-09-16 10:44:37 -07:00
|
|
|
var showPrefsStub = sinon.stub(element.$.prefsOverlay, 'open',
|
|
|
|
function() { return Promise.resolve({}); });
|
|
|
|
|
2016-01-26 16:30:02 -05:00
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 188); // ','
|
|
|
|
assert(showPrefsStub.calledOnce);
|
|
|
|
|
2016-05-17 09:46:00 -07:00
|
|
|
var scrollStub = sinon.stub(element.$.cursor, 'moveToNextChunk');
|
2016-02-25 18:19:51 -05:00
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 78); // 'n'
|
|
|
|
assert(scrollStub.calledOnce);
|
|
|
|
scrollStub.restore();
|
|
|
|
|
2016-05-17 09:46:00 -07:00
|
|
|
scrollStub = sinon.stub(element.$.cursor, 'moveToPreviousChunk');
|
2016-02-25 18:19:51 -05:00
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 80); // 'p'
|
|
|
|
assert(scrollStub.calledOnce);
|
|
|
|
scrollStub.restore();
|
|
|
|
|
2016-05-17 09:46:00 -07:00
|
|
|
scrollStub = sinon.stub(element.$.cursor, 'moveToNextCommentThread');
|
2016-02-25 18:19:51 -05:00
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 78, ['shift']); // 'N'
|
|
|
|
assert(scrollStub.calledOnce);
|
|
|
|
scrollStub.restore();
|
|
|
|
|
2016-05-17 09:46:00 -07:00
|
|
|
scrollStub = sinon.stub(element.$.cursor, 'moveToPreviousCommentThread');
|
2016-02-25 18:19:51 -05:00
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 80, ['shift']); // 'P'
|
|
|
|
assert(scrollStub.calledOnce);
|
|
|
|
scrollStub.restore();
|
|
|
|
|
2016-01-26 16:30:02 -05:00
|
|
|
showPrefsStub.restore();
|
2015-12-01 01:02:00 -05:00
|
|
|
showStub.restore();
|
2016-01-08 10:13:54 -05:00
|
|
|
});
|
2015-12-01 01:02:00 -05:00
|
|
|
|
2016-09-16 10:44:37 -07:00
|
|
|
test('saving diff preferences', function() {
|
|
|
|
var savePrefs = sinon.stub(element, '_handlePrefsSave');
|
|
|
|
var cancelPrefs = sinon.stub(element, '_handlePrefsCancel');
|
|
|
|
element.$.diffPreferences._handleSave();
|
|
|
|
assert(savePrefs.calledOnce);
|
|
|
|
assert(cancelPrefs.notCalled);
|
|
|
|
savePrefs.restore();
|
|
|
|
cancelPrefs.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('cancelling diff preferences', function() {
|
|
|
|
var savePrefs = sinon.stub(element, '_handlePrefsSave');
|
|
|
|
var cancelPrefs = sinon.stub(element, '_handlePrefsCancel');
|
|
|
|
element.$.diffPreferences._handleCancel();
|
|
|
|
assert(cancelPrefs.calledOnce);
|
|
|
|
assert(savePrefs.notCalled);
|
|
|
|
savePrefs.restore();
|
|
|
|
cancelPrefs.restore();
|
|
|
|
});
|
|
|
|
|
2016-01-08 10:13:54 -05:00
|
|
|
test('keyboard shortcuts with patch range', function() {
|
|
|
|
element._changeNum = '42';
|
|
|
|
element._patchRange = {
|
|
|
|
basePatchNum: '5',
|
|
|
|
patchNum: '10',
|
|
|
|
};
|
2016-02-25 11:51:15 -05:00
|
|
|
element._change = {
|
|
|
|
revisions: {
|
2016-04-29 22:25:51 +02:00
|
|
|
a: {_number: 10},
|
2016-02-25 11:51:15 -05:00
|
|
|
},
|
|
|
|
};
|
2016-01-08 10:13:54 -05:00
|
|
|
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
|
|
|
|
element._path = 'glados.txt';
|
2015-12-01 01:02:00 -05:00
|
|
|
|
2016-01-08 10:13:54 -05:00
|
|
|
var showStub = sinon.stub(page, 'show');
|
2015-12-01 01:02:00 -05:00
|
|
|
|
2016-01-28 14:58:04 -05:00
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 65); // 'a'
|
|
|
|
assert.isTrue(showStub.notCalled, 'The `a` keyboard shortcut should ' +
|
|
|
|
'only work when the user is logged in.');
|
|
|
|
assert.isNull(window.sessionStorage.getItem(
|
2016-02-22 18:12:27 -05:00
|
|
|
'changeView.showReplyDialog'));
|
2016-01-28 14:58:04 -05:00
|
|
|
|
|
|
|
element._loggedIn = true;
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 65); // 'a'
|
2016-02-22 18:12:27 -05:00
|
|
|
assert.isTrue(element.changeViewState.showReplyDialog);
|
2016-02-03 20:40:36 -08:00
|
|
|
|
2016-05-11 14:31:49 -04:00
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/5..10'),
|
|
|
|
'Should navigate to /c/42/5..10');
|
2016-01-28 14:58:04 -05:00
|
|
|
|
2016-01-08 10:13:54 -05:00
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 85); // 'u'
|
2016-05-11 14:31:49 -04:00
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/5..10'),
|
|
|
|
'Should navigate to /c/42/5..10');
|
2015-12-01 01:02:00 -05:00
|
|
|
|
2016-01-11 17:20:53 -05:00
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 221); // ']'
|
2016-01-08 10:13:54 -05:00
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/5..10/wheatley.md'),
|
|
|
|
'Should navigate to /c/42/5..10/wheatley.md');
|
|
|
|
element._path = 'wheatley.md';
|
2015-12-01 01:02:00 -05:00
|
|
|
|
2016-01-11 17:20:53 -05:00
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
|
2016-01-08 10:13:54 -05:00
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/5..10/glados.txt'),
|
|
|
|
'Should navigate to /c/42/5..10/glados.txt');
|
|
|
|
element._path = 'glados.txt';
|
2015-12-01 01:02:00 -05:00
|
|
|
|
2016-01-11 17:20:53 -05:00
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
|
2016-01-08 10:13:54 -05:00
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/5..10/chell.go'),
|
|
|
|
'Should navigate to /c/42/5..10/chell.go');
|
|
|
|
element._path = 'chell.go';
|
2015-12-01 01:02:00 -05:00
|
|
|
|
2016-01-11 17:20:53 -05:00
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
|
2016-05-11 14:31:49 -04:00
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/5..10'),
|
|
|
|
'Should navigate to /c/42/5..10');
|
2016-02-25 11:51:15 -05:00
|
|
|
|
|
|
|
showStub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('keyboard shortcuts with old patch number', function() {
|
|
|
|
element._changeNum = '42';
|
|
|
|
element._patchRange = {
|
2016-05-11 14:31:49 -04:00
|
|
|
basePatchNum: 'PARENT',
|
2016-02-25 11:51:15 -05:00
|
|
|
patchNum: '1',
|
|
|
|
};
|
|
|
|
element._change = {
|
|
|
|
revisions: {
|
2016-04-29 22:25:51 +02:00
|
|
|
a: {_number: 1},
|
|
|
|
b: {_number: 2},
|
2016-02-25 11:51:15 -05:00
|
|
|
},
|
|
|
|
};
|
|
|
|
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
|
|
|
|
element._path = 'glados.txt';
|
|
|
|
|
|
|
|
var showStub = sinon.stub(page, 'show');
|
|
|
|
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 65); // 'a'
|
|
|
|
assert.isTrue(showStub.notCalled, 'The `a` keyboard shortcut should ' +
|
|
|
|
'only work when the user is logged in.');
|
|
|
|
assert.isNull(window.sessionStorage.getItem(
|
|
|
|
'changeView.showReplyDialog'));
|
|
|
|
|
|
|
|
element._loggedIn = true;
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 65); // 'a'
|
|
|
|
assert.isTrue(element.changeViewState.showReplyDialog);
|
|
|
|
|
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/1'),
|
|
|
|
'Should navigate to /c/42/1');
|
|
|
|
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 85); // 'u'
|
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/1'),
|
|
|
|
'Should navigate to /c/42/1');
|
|
|
|
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 221); // ']'
|
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/1/wheatley.md'),
|
|
|
|
'Should navigate to /c/42/1/wheatley.md');
|
|
|
|
element._path = 'wheatley.md';
|
|
|
|
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
|
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/1/glados.txt'),
|
|
|
|
'Should navigate to /c/42/1/glados.txt');
|
|
|
|
element._path = 'glados.txt';
|
|
|
|
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
|
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/1/chell.go'),
|
|
|
|
'Should navigate to /c/42/1/chell.go');
|
|
|
|
element._path = 'chell.go';
|
|
|
|
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
|
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/1'),
|
|
|
|
'Should navigate to /c/42/1');
|
|
|
|
|
|
|
|
showStub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('go up to change via kb without change loaded', function() {
|
|
|
|
element._changeNum = '42';
|
|
|
|
element._patchRange = {
|
2016-05-11 14:31:49 -04:00
|
|
|
basePatchNum: 'PARENT',
|
2016-02-25 11:51:15 -05:00
|
|
|
patchNum: '1',
|
|
|
|
};
|
|
|
|
|
|
|
|
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
|
|
|
|
element._path = 'glados.txt';
|
|
|
|
|
|
|
|
var showStub = sinon.stub(page, 'show');
|
|
|
|
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 65); // 'a'
|
|
|
|
assert.isTrue(showStub.notCalled, 'The `a` keyboard shortcut should ' +
|
|
|
|
'only work when the user is logged in.');
|
|
|
|
assert.isNull(window.sessionStorage.getItem(
|
|
|
|
'changeView.showReplyDialog'));
|
|
|
|
|
|
|
|
element._loggedIn = true;
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 65); // 'a'
|
|
|
|
assert.isTrue(element.changeViewState.showReplyDialog);
|
|
|
|
|
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/1'),
|
|
|
|
'Should navigate to /c/42/1');
|
|
|
|
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 85); // 'u'
|
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/1'),
|
|
|
|
'Should navigate to /c/42/1');
|
|
|
|
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 221); // ']'
|
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/1/wheatley.md'),
|
|
|
|
'Should navigate to /c/42/1/wheatley.md');
|
|
|
|
element._path = 'wheatley.md';
|
|
|
|
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
|
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/1/glados.txt'),
|
|
|
|
'Should navigate to /c/42/1/glados.txt');
|
|
|
|
element._path = 'glados.txt';
|
|
|
|
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
|
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/1/chell.go'),
|
|
|
|
'Should navigate to /c/42/1/chell.go');
|
|
|
|
element._path = 'chell.go';
|
|
|
|
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
|
|
|
|
assert(showStub.lastCall.calledWithExactly('/c/42/1'),
|
|
|
|
'Should navigate to /c/42/1');
|
|
|
|
|
|
|
|
showStub.restore();
|
2015-12-01 01:02:00 -05:00
|
|
|
});
|
2015-12-11 12:02:57 -05:00
|
|
|
|
2015-12-28 12:40:03 -05:00
|
|
|
test('jump to file dropdown', function() {
|
|
|
|
element._changeNum = '42';
|
|
|
|
element._patchRange = {
|
2016-05-11 14:31:49 -04:00
|
|
|
basePatchNum: 'PARENT',
|
2015-12-28 12:40:03 -05:00
|
|
|
patchNum: '10',
|
|
|
|
};
|
|
|
|
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
|
|
|
|
element._path = 'glados.txt';
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
var linkEls =
|
|
|
|
Polymer.dom(element.root).querySelectorAll('.dropdown-content > a');
|
|
|
|
assert.equal(linkEls.length, 3);
|
|
|
|
assert.isFalse(linkEls[0].hasAttribute('selected'));
|
|
|
|
assert.isTrue(linkEls[1].hasAttribute('selected'));
|
|
|
|
assert.isFalse(linkEls[2].hasAttribute('selected'));
|
|
|
|
assert.equal(linkEls[0].getAttribute('data-key-nav'), '[');
|
|
|
|
assert.equal(linkEls[1].getAttribute('data-key-nav'), '');
|
|
|
|
assert.equal(linkEls[2].getAttribute('data-key-nav'), ']');
|
2016-01-08 10:13:54 -05:00
|
|
|
assert.equal(linkEls[0].getAttribute('href'), '/c/42/10/chell.go');
|
|
|
|
assert.equal(linkEls[1].getAttribute('href'), '/c/42/10/glados.txt');
|
|
|
|
assert.equal(linkEls[2].getAttribute('href'), '/c/42/10/wheatley.md');
|
2016-03-02 18:00:09 -05:00
|
|
|
|
|
|
|
assert.equal(element._computeFileDisplayName('/foo/bar/baz'),
|
|
|
|
'/foo/bar/baz');
|
|
|
|
assert.equal(element._computeFileDisplayName('/COMMIT_MSG'),
|
|
|
|
'Commit message');
|
2015-12-28 12:40:03 -05:00
|
|
|
});
|
|
|
|
|
2016-01-08 10:13:54 -05:00
|
|
|
test('jump to file dropdown with patch range', function() {
|
|
|
|
element._changeNum = '42';
|
|
|
|
element._patchRange = {
|
|
|
|
basePatchNum: '5',
|
|
|
|
patchNum: '10',
|
|
|
|
};
|
|
|
|
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
|
|
|
|
element._path = 'glados.txt';
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
var linkEls =
|
|
|
|
Polymer.dom(element.root).querySelectorAll('.dropdown-content > a');
|
|
|
|
assert.equal(linkEls.length, 3);
|
|
|
|
assert.isFalse(linkEls[0].hasAttribute('selected'));
|
|
|
|
assert.isTrue(linkEls[1].hasAttribute('selected'));
|
|
|
|
assert.isFalse(linkEls[2].hasAttribute('selected'));
|
|
|
|
assert.equal(linkEls[0].getAttribute('data-key-nav'), '[');
|
|
|
|
assert.equal(linkEls[1].getAttribute('data-key-nav'), '');
|
|
|
|
assert.equal(linkEls[2].getAttribute('data-key-nav'), ']');
|
|
|
|
assert.equal(linkEls[0].getAttribute('href'), '/c/42/5..10/chell.go');
|
|
|
|
assert.equal(linkEls[1].getAttribute('href'), '/c/42/5..10/glados.txt');
|
|
|
|
assert.equal(linkEls[2].getAttribute('href'), '/c/42/5..10/wheatley.md');
|
|
|
|
});
|
2016-02-10 21:59:20 +01:00
|
|
|
|
2016-09-07 17:34:41 -04:00
|
|
|
test('prev/next links', function() {
|
|
|
|
element._changeNum = '42';
|
|
|
|
element._patchRange = {
|
|
|
|
basePatchNum: 'PARENT',
|
|
|
|
patchNum: '10',
|
|
|
|
};
|
|
|
|
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
|
|
|
|
element._path = 'glados.txt';
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
var linkEls = Polymer.dom(element.root).querySelectorAll('.navLink');
|
|
|
|
assert.equal(linkEls.length, 2);
|
|
|
|
assert.equal(linkEls[0].getAttribute('href'), '/c/42/10/chell.go');
|
|
|
|
assert.equal(linkEls[1].getAttribute('href'), '/c/42/10/wheatley.md');
|
|
|
|
element._path = 'wheatley.md';
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
assert.equal(linkEls[0].getAttribute('href'), '/c/42/10/glados.txt');
|
|
|
|
assert.isFalse(linkEls[1].hasAttribute('href'));
|
|
|
|
element._path = 'chell.go';
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
assert.isFalse(linkEls[0].hasAttribute('href'));
|
|
|
|
assert.equal(linkEls[1].getAttribute('href'), '/c/42/10/glados.txt');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('prev/next links with patch range', function() {
|
|
|
|
element._changeNum = '42';
|
|
|
|
element._patchRange = {
|
|
|
|
basePatchNum: '5',
|
|
|
|
patchNum: '10',
|
|
|
|
};
|
|
|
|
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
|
|
|
|
element._path = 'glados.txt';
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
var linkEls = Polymer.dom(element.root).querySelectorAll('.navLink');
|
|
|
|
assert.equal(linkEls.length, 2);
|
|
|
|
assert.equal(linkEls[0].getAttribute('href'), '/c/42/5..10/chell.go');
|
|
|
|
assert.equal(linkEls[1].getAttribute('href'), '/c/42/5..10/wheatley.md');
|
|
|
|
element._path = 'wheatley.md';
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
assert.equal(linkEls[0].getAttribute('href'), '/c/42/5..10/glados.txt');
|
|
|
|
assert.isFalse(linkEls[1].hasAttribute('href'));
|
|
|
|
element._path = 'chell.go';
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
assert.isFalse(linkEls[0].hasAttribute('href'));
|
|
|
|
assert.equal(linkEls[1].getAttribute('href'), '/c/42/5..10/glados.txt');
|
|
|
|
});
|
|
|
|
|
2016-02-10 21:59:20 +01:00
|
|
|
test('file review status', function(done) {
|
|
|
|
element._loggedIn = true;
|
|
|
|
element._changeNum = '42';
|
|
|
|
element._patchRange = {
|
|
|
|
basePatchNum: '1',
|
|
|
|
patchNum: '2',
|
|
|
|
};
|
|
|
|
element._fileList = ['/COMMIT_MSG'];
|
|
|
|
element._path = '/COMMIT_MSG';
|
2016-04-05 16:06:57 -04:00
|
|
|
var saveReviewedStub = sinon.stub(element, '_saveReviewedState',
|
|
|
|
function() { return Promise.resolve(); });
|
2016-02-10 21:59:20 +01:00
|
|
|
|
2016-03-06 14:57:02 +01:00
|
|
|
flush(function() {
|
2016-02-10 21:59:20 +01:00
|
|
|
var commitMsg = Polymer.dom(element.root).querySelector(
|
|
|
|
'input[type="checkbox"]');
|
|
|
|
|
|
|
|
assert.isTrue(commitMsg.checked);
|
2016-04-05 16:06:57 -04:00
|
|
|
MockInteractions.tap(commitMsg);
|
|
|
|
assert.isFalse(commitMsg.checked);
|
|
|
|
assert.isTrue(saveReviewedStub.lastCall.calledWithExactly(false));
|
2016-02-10 21:59:20 +01:00
|
|
|
|
|
|
|
MockInteractions.tap(commitMsg);
|
2016-04-05 16:06:57 -04:00
|
|
|
assert.isTrue(commitMsg.checked);
|
|
|
|
assert.isTrue(saveReviewedStub.lastCall.calledWithExactly(true));
|
|
|
|
|
|
|
|
saveReviewedStub.restore();
|
|
|
|
done();
|
2016-03-06 14:57:02 +01:00
|
|
|
});
|
2016-02-10 21:59:20 +01:00
|
|
|
});
|
2016-05-05 16:53:38 -07:00
|
|
|
|
|
|
|
test('diff mode selector correctly toggles the diff', function() {
|
|
|
|
var select = element.$.modeSelect;
|
|
|
|
var diffDisplay = element.$.diff;
|
2016-08-30 12:44:27 -07:00
|
|
|
var blurSpy = sinon.spy(select, 'blur');
|
2016-05-05 16:53:38 -07:00
|
|
|
element._userPrefs = {diff_view: 'SIDE_BY_SIDE'};
|
|
|
|
|
|
|
|
// The mode selected in the view state reflects the selected option.
|
|
|
|
assert.equal(element._getDiffViewMode(), select.value);
|
|
|
|
|
|
|
|
// The mode selected in the view state reflects the view rednered in the
|
|
|
|
// diff.
|
|
|
|
assert.equal(select.value, diffDisplay.viewMode);
|
|
|
|
|
|
|
|
// We will simulate a user change of the selected mode.
|
|
|
|
var newMode = 'UNIFIED_DIFF';
|
|
|
|
// Set the actual value of the select, and simulate the change event.
|
|
|
|
select.value = newMode;
|
2016-07-13 21:06:03 +02:00
|
|
|
element.fire('change', {}, {node: select});
|
2016-05-05 16:53:38 -07:00
|
|
|
|
|
|
|
// Make sure the handler was called and the state is still coherent.
|
|
|
|
assert.equal(element._getDiffViewMode(), newMode);
|
|
|
|
assert.equal(element._getDiffViewMode(), select.value);
|
|
|
|
assert.equal(element._getDiffViewMode(), diffDisplay.viewMode);
|
2016-08-30 12:44:27 -07:00
|
|
|
assert(blurSpy.called, 'select should be blurred after selection');
|
2016-05-05 16:53:38 -07:00
|
|
|
});
|
2016-06-20 14:38:33 -07:00
|
|
|
|
2016-08-25 12:35:50 -07:00
|
|
|
test('diff mode selector initializes from preferences', function() {
|
|
|
|
var resolvePrefs;
|
|
|
|
var prefsPromise = new Promise(function(resolve) {
|
|
|
|
resolvePrefs = resolve;
|
|
|
|
});
|
|
|
|
var getPreferencesStub = sinon.stub(element.$.restAPI, 'getPreferences',
|
|
|
|
function() { return prefsPromise; });
|
|
|
|
|
|
|
|
// Attach a new gr-diff-view so we can intercept the preferences fetch.
|
|
|
|
var view = document.createElement('gr-diff-view');
|
|
|
|
var select = view.$.modeSelect;
|
|
|
|
fixture('blank').appendChild(view);
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
|
|
|
|
// At this point the diff mode doesn't yet have the user's preference.
|
|
|
|
assert.equal(select.value, 'SIDE_BY_SIDE');
|
|
|
|
|
|
|
|
// Receive the overriding preference.
|
|
|
|
resolvePrefs({diff_view: 'UNIFIED'});
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
assert.equal(select.value, 'SIDE_BY_SIDE');
|
2016-10-19 22:30:42 +02:00
|
|
|
getPreferencesStub.restore();
|
2016-08-25 12:35:50 -07:00
|
|
|
});
|
|
|
|
|
2016-10-07 17:22:16 -07:00
|
|
|
test('unified view is always default on small screens', function() {
|
|
|
|
var resolvePrefs;
|
|
|
|
var prefsPromise = new Promise(function(resolve) {
|
|
|
|
resolvePrefs = resolve;
|
|
|
|
});
|
|
|
|
|
|
|
|
var getPreferencesStub = sinon.stub(element.$.restAPI, 'getPreferences',
|
|
|
|
function() { return prefsPromise; });
|
|
|
|
|
|
|
|
// Attach a new gr-diff-view so we can intercept the preferences fetch.
|
|
|
|
var view = document.createElement('gr-diff-view');
|
|
|
|
|
|
|
|
view.changeViewState = {diffMode: null};
|
|
|
|
|
|
|
|
sinon.stub(view, '_getWindowWidth', function() {
|
|
|
|
return 800;
|
|
|
|
});
|
|
|
|
|
|
|
|
var select = view.$.modeSelect;
|
|
|
|
fixture('blank').appendChild(view);
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
|
|
|
|
// At this point the diff mode doesn't yet have the user's preference.
|
|
|
|
assert.equal(select.value, 'UNIFIED_DIFF');
|
|
|
|
|
|
|
|
// Receive the overriding preference.
|
|
|
|
resolvePrefs({diff_view: 'SIDE_BY_SIDE'});
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
|
|
|
|
// On small screens, unified should override user perferences
|
|
|
|
assert.equal(select.value, 'UNIFIED_DIFF');
|
2016-10-19 22:30:42 +02:00
|
|
|
getPreferencesStub.restore();
|
2016-10-07 17:22:16 -07:00
|
|
|
});
|
|
|
|
|
2016-06-20 14:38:33 -07:00
|
|
|
test('_loadHash', function() {
|
|
|
|
assert.isNotOk(element.$.cursor.initialLineNumber);
|
|
|
|
|
|
|
|
// Ignores invalid hashes:
|
|
|
|
element._loadHash('not valid');
|
|
|
|
assert.isNotOk(element.$.cursor.initialLineNumber);
|
|
|
|
|
|
|
|
// Revision hash:
|
|
|
|
element._loadHash('234');
|
|
|
|
assert.equal(element.$.cursor.initialLineNumber, 234);
|
|
|
|
assert.equal(element.$.cursor.side, 'right');
|
|
|
|
|
|
|
|
// Base hash:
|
|
|
|
element._loadHash('b345');
|
|
|
|
assert.equal(element.$.cursor.initialLineNumber, 345);
|
|
|
|
assert.equal(element.$.cursor.side, 'left');
|
2016-10-19 15:03:18 -07:00
|
|
|
|
|
|
|
// GWT-style base hash:
|
|
|
|
element._loadHash('a123');
|
|
|
|
assert.equal(element.$.cursor.initialLineNumber, 123);
|
|
|
|
assert.equal(element.$.cursor.side, 'left');
|
2016-06-20 14:38:33 -07:00
|
|
|
});
|
2016-09-27 15:57:56 -07:00
|
|
|
|
|
|
|
test('_checkForModifiers', function() {
|
|
|
|
assert.isTrue(element._checkForModifiers({altKey: true}));
|
|
|
|
assert.isTrue(element._checkForModifiers({ctrlKey: true}));
|
|
|
|
assert.isTrue(element._checkForModifiers({metaKey: true}));
|
|
|
|
assert.isTrue(element._checkForModifiers({shiftKey: true}));
|
|
|
|
assert.isFalse(element._checkForModifiers({}));
|
|
|
|
});
|
2016-10-11 13:23:53 -07:00
|
|
|
|
|
|
|
test('_shortenPath with long path should add ellipsis', function() {
|
|
|
|
var path =
|
|
|
|
'level1/level2/level3/level4/file.js';
|
|
|
|
var shortenedPath = element._shortenPath(path);
|
|
|
|
// The expected path is truncated with an ellipsis.
|
|
|
|
var expectedPath = '\u2026/file.js';
|
|
|
|
assert.equal(shortenedPath, expectedPath);
|
|
|
|
|
|
|
|
var path = 'level2/file.js';
|
|
|
|
var shortenedPath = element._shortenPath(path);
|
|
|
|
assert.equal(shortenedPath, expectedPath);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('_shortenPath with short path should not add ellipsis', function() {
|
|
|
|
var path = 'file.js';
|
|
|
|
var expectedPath = 'file.js';
|
|
|
|
var shortenedPath = element._shortenPath(path);
|
|
|
|
assert.equal(shortenedPath, expectedPath);
|
|
|
|
});
|
2015-11-14 15:40:47 -05:00
|
|
|
});
|
|
|
|
</script>
|