2015-11-18 16:31:18 -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-diff-comment</title>
|
|
|
|
|
|
2016-03-04 17:48:22 -05:00
|
|
|
|
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.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-18 16:31:18 -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-comment.html">
|
2015-11-18 16:31:18 -05:00
|
|
|
|
|
|
|
|
|
<test-fixture id="basic">
|
|
|
|
|
<template>
|
|
|
|
|
<gr-diff-comment></gr-diff-comment>
|
|
|
|
|
</template>
|
|
|
|
|
</test-fixture>
|
|
|
|
|
|
2015-12-02 11:40:14 -05:00
|
|
|
|
<test-fixture id="draft">
|
|
|
|
|
<template>
|
|
|
|
|
<gr-diff-comment draft="true"></gr-diff-comment>
|
|
|
|
|
</template>
|
|
|
|
|
</test-fixture>
|
|
|
|
|
|
2015-11-18 16:31:18 -05:00
|
|
|
|
<script>
|
|
|
|
|
suite('gr-diff-comment tests', function() {
|
|
|
|
|
var element;
|
|
|
|
|
setup(function() {
|
2016-05-03 15:14:57 -04:00
|
|
|
|
stub('gr-rest-api-interface', {
|
|
|
|
|
getAccount: function() { return Promise.resolve(null); },
|
|
|
|
|
});
|
2015-11-18 16:31:18 -05:00
|
|
|
|
element = fixture('basic');
|
2015-12-02 11:40:14 -05:00
|
|
|
|
element.comment = {
|
|
|
|
|
author: {
|
|
|
|
|
name: 'Mr. Peanutbutter',
|
|
|
|
|
email: 'tenn1sballchaser@aol.com',
|
|
|
|
|
},
|
|
|
|
|
id: 'baf0414d_60047215',
|
|
|
|
|
line: 5,
|
|
|
|
|
message: 'is this a crossover episode!?',
|
|
|
|
|
updated: '2015-12-08 19:48:33.843000000',
|
2015-12-20 19:13:45 -05:00
|
|
|
|
};
|
2015-11-18 16:31:18 -05:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('proper event fires on reply', function(done) {
|
2015-12-20 19:13:45 -05:00
|
|
|
|
element.addEventListener('reply', function(e) {
|
2016-01-28 18:07:26 -05:00
|
|
|
|
assert.ok(e.detail.comment);
|
2015-11-18 16:31:18 -05:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
MockInteractions.tap(element.$$('.reply'));
|
|
|
|
|
});
|
|
|
|
|
|
2016-01-28 18:07:26 -05:00
|
|
|
|
test('proper event fires on quote', function(done) {
|
|
|
|
|
element.addEventListener('reply', function(e) {
|
|
|
|
|
assert.ok(e.detail.comment);
|
|
|
|
|
assert.isTrue(e.detail.quote);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
MockInteractions.tap(element.$$('.quote'));
|
|
|
|
|
});
|
|
|
|
|
|
2015-11-18 16:31:18 -05:00
|
|
|
|
test('proper event fires on done', function(done) {
|
2015-12-20 19:13:45 -05:00
|
|
|
|
element.addEventListener('done', function(e) {
|
2015-11-18 16:31:18 -05:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
MockInteractions.tap(element.$$('.done'));
|
|
|
|
|
});
|
|
|
|
|
|
2015-12-02 11:40:14 -05:00
|
|
|
|
test('clicking on date link does not trigger nav', function() {
|
|
|
|
|
var showStub = sinon.stub(page, 'show');
|
|
|
|
|
var dateEl = element.$$('.date');
|
|
|
|
|
assert.ok(dateEl);
|
|
|
|
|
MockInteractions.tap(dateEl);
|
|
|
|
|
var dest = window.location.pathname + '#5';
|
|
|
|
|
assert(showStub.lastCall.calledWithExactly(dest, null, false),
|
|
|
|
|
'Should navigate to ' + dest + ' without triggering nav');
|
|
|
|
|
showStub.restore();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
suite('gr-diff-comment draft tests', function() {
|
|
|
|
|
var element;
|
|
|
|
|
|
|
|
|
|
setup(function() {
|
2016-05-03 15:14:57 -04:00
|
|
|
|
stub('gr-rest-api-interface', {
|
|
|
|
|
getAccount: function() { return Promise.resolve(null); },
|
|
|
|
|
saveDiffDraft: function() {
|
|
|
|
|
return Promise.resolve({
|
|
|
|
|
ok: true,
|
|
|
|
|
text: function() {
|
|
|
|
|
return Promise.resolve(
|
|
|
|
|
')]}\'\n{' +
|
|
|
|
|
'"id": "baf0414d_40572e03",' +
|
|
|
|
|
'"path": "/path/to/file",' +
|
|
|
|
|
'"line": 5,' +
|
|
|
|
|
'"updated": "2015-12-08 21:52:36.177000000",' +
|
|
|
|
|
'"message": "saved!"' +
|
|
|
|
|
'}'
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
removeChangeReviewer: function() {
|
|
|
|
|
return Promise.resolve({ok: true});
|
|
|
|
|
},
|
|
|
|
|
});
|
2016-06-05 12:20:11 +02:00
|
|
|
|
stub('gr-storage', {
|
|
|
|
|
getDraftComment: function() { return null; },
|
|
|
|
|
});
|
2015-12-02 11:40:14 -05:00
|
|
|
|
element = fixture('draft');
|
|
|
|
|
element.changeNum = 42;
|
|
|
|
|
element.patchNum = 1;
|
2016-02-05 18:22:05 -08:00
|
|
|
|
element.editing = false;
|
2015-12-02 11:40:14 -05:00
|
|
|
|
element.comment = {
|
|
|
|
|
__draft: true,
|
|
|
|
|
__draftID: 'temp_draft_id',
|
|
|
|
|
path: '/path/to/file',
|
|
|
|
|
line: 5,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function isVisible(el) {
|
|
|
|
|
assert.ok(el);
|
|
|
|
|
return getComputedStyle(el).getPropertyValue('display') != 'none';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test('button visibility states', function() {
|
2015-12-20 19:13:45 -05:00
|
|
|
|
element.showActions = false;
|
|
|
|
|
assert.isTrue(element.$$('.actions').hasAttribute('hidden'));
|
|
|
|
|
element.showActions = true;
|
|
|
|
|
assert.isFalse(element.$$('.actions').hasAttribute('hidden'));
|
|
|
|
|
|
2015-12-02 11:40:14 -05:00
|
|
|
|
element.draft = true;
|
|
|
|
|
assert.isTrue(isVisible(element.$$('.edit')), 'edit is visible');
|
|
|
|
|
assert.isTrue(isVisible(element.$$('.discard')), 'discard is visible');
|
|
|
|
|
assert.isFalse(isVisible(element.$$('.save')), 'save is not visible');
|
|
|
|
|
assert.isFalse(isVisible(element.$$('.cancel')), 'cancel is not visible');
|
|
|
|
|
assert.isFalse(isVisible(element.$$('.reply')), 'reply is not visible');
|
2016-01-28 18:07:26 -05:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.quote')), 'quote is not visible');
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.done')), 'done is not visible');
|
|
|
|
|
|
|
|
|
|
element.editing = true;
|
2016-02-02 21:02:42 +01:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.edit')), 'edit is not visible');
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert.isTrue(isVisible(element.$$('.discard')), 'discard is visible');
|
|
|
|
|
assert.isTrue(isVisible(element.$$('.save')), 'save is visible');
|
2016-01-28 18:07:26 -05:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.cancel')), 'cancel is visible');
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.reply')), 'reply is not visible');
|
2016-01-28 18:07:26 -05:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.quote')), 'quote is not visible');
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.done')), 'done is not visible');
|
|
|
|
|
|
2016-02-02 21:02:42 +01:00
|
|
|
|
element.draft = false;
|
2015-12-02 11:40:14 -05:00
|
|
|
|
element.editing = false;
|
2016-02-02 21:02:42 +01:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.edit')), 'edit is not visible');
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.discard')),
|
|
|
|
|
'discard is not visible');
|
|
|
|
|
assert.isFalse(isVisible(element.$$('.save')), 'save is not visible');
|
|
|
|
|
assert.isFalse(isVisible(element.$$('.cancel')), 'cancel is not visible');
|
2016-01-28 18:07:26 -05:00
|
|
|
|
assert.isTrue(isVisible(element.$$('.reply')), 'reply is visible');
|
|
|
|
|
assert.isTrue(isVisible(element.$$('.quote')), 'quote is visible');
|
|
|
|
|
assert.isTrue(isVisible(element.$$('.done')), 'done is visible');
|
2015-12-02 11:40:14 -05:00
|
|
|
|
|
2016-01-28 18:07:26 -05:00
|
|
|
|
element.comment.id = 'foo';
|
2016-02-05 18:22:05 -08:00
|
|
|
|
element.draft = true;
|
2016-01-28 18:07:26 -05:00
|
|
|
|
element.editing = true;
|
|
|
|
|
assert.isTrue(isVisible(element.$$('.cancel')), 'cancel is visible');
|
2015-12-02 11:40:14 -05:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('draft creation/cancelation', function(done) {
|
|
|
|
|
assert.isFalse(element.editing);
|
|
|
|
|
MockInteractions.tap(element.$$('.edit'));
|
|
|
|
|
assert.isTrue(element.editing);
|
|
|
|
|
|
2016-05-23 13:53:10 -07:00
|
|
|
|
element._messageText = '';
|
2015-12-02 11:40:14 -05:00
|
|
|
|
// Save should be disabled on an empty message.
|
|
|
|
|
var disabled = element.$$('.save').hasAttribute('disabled');
|
|
|
|
|
assert.isTrue(disabled, 'save button should be disabled.');
|
2016-05-23 13:53:10 -07:00
|
|
|
|
element._messageText = ' ';
|
2015-12-02 11:40:14 -05:00
|
|
|
|
disabled = element.$$('.save').hasAttribute('disabled');
|
|
|
|
|
assert.isTrue(disabled, 'save button should be disabled.');
|
|
|
|
|
|
2016-08-05 15:05:50 -07:00
|
|
|
|
var updateStub = sinon.stub();
|
|
|
|
|
element.addEventListener('comment-update', updateStub);
|
|
|
|
|
|
2015-12-02 11:40:14 -05:00
|
|
|
|
var numDiscardEvents = 0;
|
2016-03-25 11:29:36 -04:00
|
|
|
|
element.addEventListener('comment-discard', function(e) {
|
2015-12-02 11:40:14 -05:00
|
|
|
|
numDiscardEvents++;
|
2016-01-16 13:35:57 -05:00
|
|
|
|
if (numDiscardEvents == 3) {
|
2016-08-05 15:05:50 -07:00
|
|
|
|
assert.isFalse(updateStub.called);
|
2015-12-02 11:40:14 -05:00
|
|
|
|
done();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
MockInteractions.tap(element.$$('.cancel'));
|
|
|
|
|
MockInteractions.tap(element.$$('.discard'));
|
2016-08-05 15:05:50 -07:00
|
|
|
|
element.flushDebouncer('fire-update');
|
2016-01-18 14:24:33 -05:00
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element.$.editTextarea, 27); // esc
|
2015-12-02 11:40:14 -05:00
|
|
|
|
});
|
|
|
|
|
|
2016-08-23 12:07:04 -07:00
|
|
|
|
test('ctrl+s saves comment', function(done) {
|
|
|
|
|
var stub = sinon.stub(element, 'save', function() {
|
|
|
|
|
assert.isTrue(stub.called);
|
|
|
|
|
stub.restore();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
element._messageText = 'is that the horse from horsing around??';
|
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(
|
|
|
|
|
element.$.editTextarea.textarea,
|
|
|
|
|
83, 'ctrl'); // 'ctrl + s'
|
|
|
|
|
});
|
|
|
|
|
|
2015-12-02 11:40:14 -05:00
|
|
|
|
test('draft saving/editing', function(done) {
|
2016-05-23 15:24:05 -07:00
|
|
|
|
var fireStub = sinon.stub(element, 'fire');
|
|
|
|
|
|
2015-12-02 11:40:14 -05:00
|
|
|
|
element.draft = true;
|
|
|
|
|
MockInteractions.tap(element.$$('.edit'));
|
2016-05-23 13:53:10 -07:00
|
|
|
|
element._messageText = 'good news, everyone!';
|
2016-05-23 15:24:05 -07:00
|
|
|
|
element.flushDebouncer('fire-update');
|
|
|
|
|
element.flushDebouncer('store');
|
|
|
|
|
assert(fireStub.calledWith('comment-update'),
|
|
|
|
|
'comment-update should be sent');
|
|
|
|
|
assert.deepEqual(fireStub.lastCall.args, [
|
|
|
|
|
'comment-update', {
|
|
|
|
|
comment: {
|
|
|
|
|
__draft: true,
|
|
|
|
|
__draftID: 'temp_draft_id',
|
|
|
|
|
__editing: true,
|
|
|
|
|
line: 5,
|
|
|
|
|
path: '/path/to/file',
|
|
|
|
|
},
|
2016-06-09 16:08:04 -07:00
|
|
|
|
patchNum: 1,
|
2016-05-23 15:24:05 -07:00
|
|
|
|
},
|
|
|
|
|
]);
|
2015-12-02 11:40:14 -05:00
|
|
|
|
MockInteractions.tap(element.$$('.save'));
|
2016-05-23 15:24:05 -07:00
|
|
|
|
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert.isTrue(element.disabled,
|
|
|
|
|
'Element should be disabled when creating draft.');
|
|
|
|
|
|
2016-05-03 15:14:57 -04:00
|
|
|
|
element._xhrPromise.then(function(draft) {
|
2016-05-23 15:24:05 -07:00
|
|
|
|
assert(fireStub.calledWith('comment-save'),
|
|
|
|
|
'comment-save should be sent');
|
2016-07-14 12:31:09 -07:00
|
|
|
|
assert.deepEqual(fireStub.lastCall.args[1], {
|
|
|
|
|
comment: {
|
|
|
|
|
__draft: true,
|
|
|
|
|
__draftID: 'temp_draft_id',
|
|
|
|
|
__editing: false,
|
|
|
|
|
id: 'baf0414d_40572e03',
|
|
|
|
|
line: 5,
|
|
|
|
|
message: 'saved!',
|
|
|
|
|
path: '/path/to/file',
|
|
|
|
|
updated: '2015-12-08 21:52:36.177000000',
|
2016-05-23 15:24:05 -07:00
|
|
|
|
},
|
2016-07-14 12:31:09 -07:00
|
|
|
|
patchNum: 1,
|
|
|
|
|
});
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert.isFalse(element.disabled,
|
2016-05-23 15:24:05 -07:00
|
|
|
|
'Element should be enabled when done creating draft.');
|
2016-05-03 15:14:57 -04:00
|
|
|
|
assert.equal(draft.message, 'saved!');
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert.isFalse(element.editing);
|
|
|
|
|
}).then(function() {
|
|
|
|
|
MockInteractions.tap(element.$$('.edit'));
|
2016-06-09 16:08:04 -07:00
|
|
|
|
element._messageText = 'You’ll be delivering a package to Chapek 9, ' +
|
|
|
|
|
'a world where humans are killed on sight.';
|
2015-12-02 11:40:14 -05:00
|
|
|
|
MockInteractions.tap(element.$$('.save'));
|
|
|
|
|
assert.isTrue(element.disabled,
|
|
|
|
|
'Element should be disabled when updating draft.');
|
|
|
|
|
|
2016-05-03 15:14:57 -04:00
|
|
|
|
element._xhrPromise.then(function(draft) {
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert.isFalse(element.disabled,
|
|
|
|
|
'Element should be enabled when done updating draft.');
|
2016-05-03 15:14:57 -04:00
|
|
|
|
assert.equal(draft.message, 'saved!');
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert.isFalse(element.editing);
|
2016-06-05 12:20:11 +02:00
|
|
|
|
fireStub.restore();
|
2015-12-02 11:40:14 -05:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('clicking on date link does not trigger nav', function() {
|
|
|
|
|
var showStub = sinon.stub(page, 'show');
|
|
|
|
|
var dateEl = element.$$('.date');
|
|
|
|
|
assert.ok(dateEl);
|
|
|
|
|
MockInteractions.tap(dateEl);
|
|
|
|
|
var dest = window.location.pathname + '#5';
|
|
|
|
|
assert(showStub.lastCall.calledWithExactly(dest, null, false),
|
|
|
|
|
'Should navigate to ' + dest + ' without triggering nav');
|
|
|
|
|
showStub.restore();
|
|
|
|
|
});
|
2015-11-18 16:31:18 -05:00
|
|
|
|
});
|
|
|
|
|
</script>
|