Files
gerrit/polygerrit-ui/app/test/gr-diff-view-test.html
Urs Wolfer 51a7070de5 Add file review status to diff view
When diff is opened, it is automatically marked as reviewed.

Change-Id: I13e4c28f2ccc38dd2e9fb41793cedae4ffdd5ba7
Feature: Issue 3880
2016-02-10 22:15:45 +01:00

254 lines
9.1 KiB
HTML

<!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-diff-view</title>
<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/fake-app.js"></script>
<script src="../scripts/util.js"></script>
<link rel="import" href="../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="../elements/gr-diff-view.html">
<test-fixture id="basic">
<template>
<gr-diff-view></gr-diff-view>
</template>
</test-fixture>
<script>
suite('gr-diff-view tests', function() {
var element;
var server;
setup(function() {
element = fixture('basic');
element.$.changeDetailXHR.auto = false;
element.$.filesXHR.auto = false;
element.$.configXHR.auto = false;
element.$.diff.auto = false;
server = sinon.fakeServer.create();
server.respondWith(
'PUT',
'/changes/42/revisions/2/files/%2FCOMMIT_MSG/reviewed',
[
201,
{'Content-Type': 'application/json'},
')]}\'\n' +
'""',
]
);
server.respondWith(
'DELETE',
'/changes/42/revisions/2/files/%2FCOMMIT_MSG/reviewed',
[
204,
{'Content-Type': 'application/json'},
'',
]
);
});
teardown(function() {
server.restore();
});
test('keyboard shortcuts', function() {
element._changeNum = '42';
element._patchRange = {
patchNum: '10',
};
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
element._path = 'glados.txt';
element.changeViewState.selectedFileIndex = 1;
var showStub = sinon.stub(page, 'show');
MockInteractions.pressAndReleaseKeyOn(element, 85); // 'u'
assert(showStub.lastCall.calledWithExactly('/c/42'),
'Should navigate to /c/42');
MockInteractions.pressAndReleaseKeyOn(element, 221); // ']'
assert(showStub.lastCall.calledWithExactly('/c/42/10/wheatley.md'),
'Should navigate to /c/42/10/wheatley.md');
element._path = 'wheatley.md';
assert.equal(element.changeViewState.selectedFileIndex, 2);
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
assert(showStub.lastCall.calledWithExactly('/c/42/10/glados.txt'),
'Should navigate to /c/42/10/glados.txt');
element._path = 'glados.txt';
assert.equal(element.changeViewState.selectedFileIndex, 1);
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
assert(showStub.lastCall.calledWithExactly('/c/42/10/chell.go'),
'Should navigate to /c/42/10/chell.go');
element._path = 'chell.go';
assert.equal(element.changeViewState.selectedFileIndex, 0);
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
assert(showStub.lastCall.calledWithExactly('/c/42'),
'Should navigate to /c/42');
assert.equal(element.changeViewState.selectedFileIndex, 0);
var showPrefsStub = sinon.stub(element.$.diff, 'showDiffPreferences');
MockInteractions.pressAndReleaseKeyOn(element, 188); // ','
assert(showPrefsStub.calledOnce);
showPrefsStub.restore();
showStub.restore();
});
test('keyboard shortcuts 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';
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.showReplyDropdown'));
element._loggedIn = true;
MockInteractions.pressAndReleaseKeyOn(element, 65); // 'a'
assert.isTrue(element.changeViewState.showReplyDropdown);
assert(showStub.lastCall.calledWithExactly('/c/42'),
'Should navigate to /c/42');
MockInteractions.pressAndReleaseKeyOn(element, 85); // 'u'
assert(showStub.lastCall.calledWithExactly('/c/42'),
'Should navigate to /c/42');
MockInteractions.pressAndReleaseKeyOn(element, 221); // ']'
assert(showStub.lastCall.calledWithExactly('/c/42/5..10/wheatley.md'),
'Should navigate to /c/42/5..10/wheatley.md');
element._path = 'wheatley.md';
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
assert(showStub.lastCall.calledWithExactly('/c/42/5..10/glados.txt'),
'Should navigate to /c/42/5..10/glados.txt');
element._path = 'glados.txt';
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
assert(showStub.lastCall.calledWithExactly('/c/42/5..10/chell.go'),
'Should navigate to /c/42/5..10/chell.go');
element._path = 'chell.go';
MockInteractions.pressAndReleaseKeyOn(element, 219); // '['
assert(showStub.lastCall.calledWithExactly('/c/42'),
'Should navigate to /c/42');
});
test('jump to file dropdown', function() {
element._changeNum = '42';
element._patchRange = {
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/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');
});
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');
});
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';
server.respond();
element.async(function() {
var commitMsg = Polymer.dom(element.root).querySelector(
'input[type="checkbox"]');
assert.isTrue(commitMsg.checked);
MockInteractions.tap(commitMsg);
server.respond();
element._xhrPromise.then(function(req) {
assert.isFalse(commitMsg.checked);
assert.equal(req.status, 204);
assert.equal(req.url,
'/changes/42/revisions/2/files/%2FCOMMIT_MSG/reviewed');
MockInteractions.tap(commitMsg);
server.respond();
}).then(function() {
element._xhrPromise.then(function(req) {
assert.isTrue(commitMsg.checked);
assert.equal(req.status, 201);
assert.equal(req.url,
'/changes/42/revisions/2/files/%2FCOMMIT_MSG/reviewed');
done();
});
});
}, 1);
});
});
</script>