2015-11-18 16:31:18 -05:00
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<!--
|
2018-03-26 10:04:27 -04:00
|
|
|
|
@license
|
2015-11-18 16:31:18 -05:00
|
|
|
|
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>
|
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>
|
|
|
|
|
<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="gr-diff-comment.html">
|
2015-11-18 16:31:18 -05:00
|
|
|
|
|
2017-03-28 17:02:44 -07:00
|
|
|
|
<script>void(0);</script>
|
|
|
|
|
|
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>
|
2016-10-06 10:18:32 -07:00
|
|
|
|
|
|
|
|
|
function isVisible(el) {
|
|
|
|
|
assert.ok(el);
|
|
|
|
|
return getComputedStyle(el).getPropertyValue('display') !== 'none';
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
suite('gr-diff-comment tests', () => {
|
|
|
|
|
let element;
|
|
|
|
|
let sandbox;
|
|
|
|
|
setup(() => {
|
2016-05-03 15:14:57 -04:00
|
|
|
|
stub('gr-rest-api-interface', {
|
2017-05-16 13:50:27 -07:00
|
|
|
|
getAccount() { return Promise.resolve(null); },
|
2016-05-03 15:14:57 -04:00
|
|
|
|
});
|
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
|
|
|
|
};
|
2016-11-02 14:18:48 -07:00
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
teardown(() => {
|
2016-11-02 14:18:48 -07:00
|
|
|
|
sandbox.restore();
|
2015-11-18 16:31:18 -05:00
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('collapsible comments', () => {
|
2016-10-06 10:18:32 -07:00
|
|
|
|
// When a comment (not draft) is loaded, it should be collapsed
|
2016-10-10 17:31:56 -07:00
|
|
|
|
assert.isTrue(element.collapsed);
|
2016-11-08 15:49:05 -08:00
|
|
|
|
assert.isFalse(isVisible(element.$$('gr-formatted-text')),
|
|
|
|
|
'gr-formatted-text is not visible');
|
2016-10-06 10:18:32 -07:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.actions')),
|
|
|
|
|
'actions are not visible');
|
2018-04-05 10:48:03 -07:00
|
|
|
|
assert.isNotOk(element.textarea, 'textarea is not visible');
|
2016-10-06 10:18:32 -07:00
|
|
|
|
|
|
|
|
|
// The header middle content is only visible when comments are collapsed.
|
|
|
|
|
// It shows the message in a condensed way, and limits to a single line.
|
|
|
|
|
assert.isTrue(isVisible(element.$$('.collapsedContent')),
|
|
|
|
|
'header middle content is visible');
|
|
|
|
|
|
|
|
|
|
// When the header row is clicked, the comment should expand
|
|
|
|
|
MockInteractions.tap(element.$.header);
|
2016-10-10 17:31:56 -07:00
|
|
|
|
assert.isFalse(element.collapsed);
|
2016-11-08 15:49:05 -08:00
|
|
|
|
assert.isTrue(isVisible(element.$$('gr-formatted-text')),
|
|
|
|
|
'gr-formatted-text is visible');
|
2016-10-06 10:18:32 -07:00
|
|
|
|
assert.isTrue(isVisible(element.$$('.actions')),
|
|
|
|
|
'actions are visible');
|
2018-04-05 10:48:03 -07:00
|
|
|
|
assert.isNotOk(element.textarea, 'textarea is not visible');
|
2016-10-06 10:18:32 -07:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.collapsedContent')),
|
|
|
|
|
'header middle content is not visible');
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('clicking on date link does not trigger nav', () => {
|
|
|
|
|
const showStub = sinon.stub(page, 'show');
|
|
|
|
|
const dateEl = element.$$('.date');
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert.ok(dateEl);
|
|
|
|
|
MockInteractions.tap(dateEl);
|
2017-05-16 13:50:27 -07:00
|
|
|
|
const dest = window.location.pathname + '#5';
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert(showStub.lastCall.calledWithExactly(dest, null, false),
|
|
|
|
|
'Should navigate to ' + dest + ' without triggering nav');
|
|
|
|
|
showStub.restore();
|
|
|
|
|
});
|
2016-10-10 17:31:56 -07:00
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('message is not retrieved from storage when other edits', done => {
|
|
|
|
|
const storageStub = sandbox.stub(element.$.storage, 'getDraftComment');
|
|
|
|
|
const loadSpy = sandbox.spy(element, '_loadLocalDraft');
|
2016-12-22 15:04:11 -08:00
|
|
|
|
|
|
|
|
|
element.changeNum = 1;
|
|
|
|
|
element.patchNum = 1;
|
|
|
|
|
element.comment = {
|
|
|
|
|
author: {
|
|
|
|
|
name: 'Mr. Peanutbutter',
|
|
|
|
|
email: 'tenn1sballchaser@aol.com',
|
|
|
|
|
},
|
|
|
|
|
line: 5,
|
|
|
|
|
__otherEditing: true,
|
|
|
|
|
};
|
2017-05-16 13:50:27 -07:00
|
|
|
|
flush(() => {
|
2016-12-22 15:04:11 -08:00
|
|
|
|
assert.isTrue(loadSpy.called);
|
|
|
|
|
assert.isFalse(storageStub.called);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('message is retrieved from storage when no other edits', done => {
|
|
|
|
|
const storageStub = sandbox.stub(element.$.storage, 'getDraftComment');
|
|
|
|
|
const loadSpy = sandbox.spy(element, '_loadLocalDraft');
|
2016-12-22 15:04:11 -08:00
|
|
|
|
|
|
|
|
|
element.changeNum = 1;
|
|
|
|
|
element.patchNum = 1;
|
|
|
|
|
element.comment = {
|
|
|
|
|
author: {
|
|
|
|
|
name: 'Mr. Peanutbutter',
|
|
|
|
|
email: 'tenn1sballchaser@aol.com',
|
|
|
|
|
},
|
|
|
|
|
line: 5,
|
|
|
|
|
};
|
2017-05-16 13:50:27 -07:00
|
|
|
|
flush(() => {
|
2016-12-22 15:04:11 -08:00
|
|
|
|
assert.isTrue(loadSpy.called);
|
|
|
|
|
assert.isTrue(storageStub.called);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('_getPatchNum', () => {
|
2017-03-21 14:56:19 -07:00
|
|
|
|
element.side = 'PARENT';
|
2017-03-13 11:42:42 -07:00
|
|
|
|
element.patchNum = 1;
|
|
|
|
|
assert.equal(element._getPatchNum(), 'PARENT');
|
2017-03-21 14:56:19 -07:00
|
|
|
|
element.side = 'REVISION';
|
2017-03-13 11:42:42 -07:00
|
|
|
|
assert.equal(element._getPatchNum(), 1);
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('comment expand and collapse', () => {
|
2016-10-10 17:31:56 -07:00
|
|
|
|
element.collapsed = true;
|
2016-11-08 15:49:05 -08:00
|
|
|
|
assert.isFalse(isVisible(element.$$('gr-formatted-text')),
|
|
|
|
|
'gr-formatted-text is not visible');
|
2016-10-10 17:31:56 -07:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.actions')),
|
|
|
|
|
'actions are not visible');
|
2018-04-05 10:48:03 -07:00
|
|
|
|
assert.isNotOk(element.textarea, 'textarea is not visible');
|
2016-10-10 17:31:56 -07:00
|
|
|
|
assert.isTrue(isVisible(element.$$('.collapsedContent')),
|
|
|
|
|
'header middle content is visible');
|
|
|
|
|
|
|
|
|
|
element.collapsed = false;
|
|
|
|
|
assert.isFalse(element.collapsed);
|
2016-11-08 15:49:05 -08:00
|
|
|
|
assert.isTrue(isVisible(element.$$('gr-formatted-text')),
|
|
|
|
|
'gr-formatted-text is visible');
|
2016-10-10 17:31:56 -07:00
|
|
|
|
assert.isTrue(isVisible(element.$$('.actions')),
|
|
|
|
|
'actions are visible');
|
2018-04-05 10:48:03 -07:00
|
|
|
|
assert.isNotOk(element.textarea, 'textarea is not visible');
|
2016-10-10 17:31:56 -07:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.collapsedContent')),
|
|
|
|
|
'header middle content is is not visible');
|
|
|
|
|
});
|
2016-11-02 14:18:48 -07:00
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
suite('while editing', () => {
|
|
|
|
|
setup(() => {
|
2017-02-24 16:26:32 -08:00
|
|
|
|
element.editing = true;
|
|
|
|
|
element._messageText = 'test';
|
|
|
|
|
sandbox.stub(element, '_handleCancel');
|
|
|
|
|
sandbox.stub(element, '_handleSave');
|
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
|
});
|
2016-11-02 14:18:48 -07:00
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
suite('when text is empty', () => {
|
|
|
|
|
setup(() => {
|
2017-02-24 16:26:32 -08:00
|
|
|
|
element._messageText = '';
|
2017-11-27 16:13:06 -08:00
|
|
|
|
element.comment = {};
|
2017-02-24 16:26:32 -08:00
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('esc closes comment when text is empty', () => {
|
2017-02-24 16:26:32 -08:00
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(
|
2018-04-05 10:48:03 -07:00
|
|
|
|
element.textarea, 27); // esc
|
2017-02-24 16:26:32 -08:00
|
|
|
|
assert.isTrue(element._handleCancel.called);
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('ctrl+enter does not save', () => {
|
2017-02-24 16:26:32 -08:00
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(
|
2018-04-05 10:48:03 -07:00
|
|
|
|
element.textarea, 13, 'ctrl'); // ctrl + enter
|
2017-02-24 16:26:32 -08:00
|
|
|
|
assert.isFalse(element._handleSave.called);
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('meta+enter does not save', () => {
|
2017-02-24 16:26:32 -08:00
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(
|
2018-04-05 10:48:03 -07:00
|
|
|
|
element.textarea, 13, 'meta'); // meta + enter
|
2017-02-24 16:26:32 -08:00
|
|
|
|
assert.isFalse(element._handleSave.called);
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('ctrl+s does not save', () => {
|
2017-02-24 16:26:32 -08:00
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(
|
2018-04-05 10:48:03 -07:00
|
|
|
|
element.textarea, 83, 'ctrl'); // ctrl + s
|
2017-02-24 16:26:32 -08:00
|
|
|
|
assert.isFalse(element._handleSave.called);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('esc does not close comment that has content', () => {
|
2017-02-24 16:26:32 -08:00
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(
|
2018-04-05 10:48:03 -07:00
|
|
|
|
element.textarea, 27); // esc
|
2017-02-24 16:26:32 -08:00
|
|
|
|
assert.isFalse(element._handleCancel.called);
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('ctrl+enter saves', () => {
|
2017-02-24 16:26:32 -08:00
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(
|
2018-04-05 10:48:03 -07:00
|
|
|
|
element.textarea, 13, 'ctrl'); // ctrl + enter
|
2017-02-24 16:26:32 -08:00
|
|
|
|
assert.isTrue(element._handleSave.called);
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('meta+enter saves', () => {
|
2017-02-24 16:26:32 -08:00
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(
|
2018-04-05 10:48:03 -07:00
|
|
|
|
element.textarea, 13, 'meta'); // meta + enter
|
2017-02-24 16:26:32 -08:00
|
|
|
|
assert.isTrue(element._handleSave.called);
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('ctrl+s saves', () => {
|
2017-02-24 16:26:32 -08:00
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(
|
2018-04-05 10:48:03 -07:00
|
|
|
|
element.textarea, 83, 'ctrl'); // ctrl + s
|
2017-02-24 16:26:32 -08:00
|
|
|
|
assert.isTrue(element._handleSave.called);
|
2016-11-02 14:18:48 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
2017-05-17 16:00:33 -07:00
|
|
|
|
test('delete comment button for non-admins is hidden', () => {
|
2017-05-08 10:40:06 -07:00
|
|
|
|
element._isAdmin = false;
|
2017-05-18 16:34:17 -07:00
|
|
|
|
assert.isFalse(element.$$('.action.delete')
|
|
|
|
|
.classList.contains('showDeleteButtons'));
|
2017-05-18 13:02:14 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('delete comment button for admins with draft is hidden', () => {
|
|
|
|
|
element._isAdmin = false;
|
|
|
|
|
element.draft = true;
|
2017-05-18 16:34:17 -07:00
|
|
|
|
assert.isFalse(element.$$('.action.delete')
|
|
|
|
|
.classList.contains('showDeleteButtons'));
|
2017-05-08 10:40:06 -07:00
|
|
|
|
});
|
|
|
|
|
|
2017-05-17 16:00:33 -07:00
|
|
|
|
test('delete comment', done => {
|
2017-05-08 10:40:06 -07:00
|
|
|
|
sandbox.stub(
|
2017-05-03 10:03:35 -07:00
|
|
|
|
element.$.restAPI, 'deleteComment').returns(Promise.resolve({}));
|
2018-04-05 10:48:03 -07:00
|
|
|
|
sandbox.spy(element.confirmDeleteOverlay, 'open');
|
2017-05-08 10:40:06 -07:00
|
|
|
|
element.changeNum = 42;
|
|
|
|
|
element.patchNum = 0xDEADBEEF;
|
|
|
|
|
element._isAdmin = true;
|
2017-05-18 16:34:17 -07:00
|
|
|
|
assert.isTrue(element.$$('.action.delete')
|
|
|
|
|
.classList.contains('showDeleteButtons'));
|
2017-05-08 10:40:06 -07:00
|
|
|
|
MockInteractions.tap(element.$$('.action.delete'));
|
2017-05-23 14:05:07 -07:00
|
|
|
|
flush(() => {
|
2018-04-05 10:48:03 -07:00
|
|
|
|
element.confirmDeleteOverlay.open.lastCall.returnValue.then(() => {
|
|
|
|
|
const dialog =
|
|
|
|
|
this.confirmDeleteOverlay.querySelector('#confirmDeleteComment');
|
|
|
|
|
dialog.message = 'removal reason';
|
2017-05-23 14:05:07 -07:00
|
|
|
|
element._handleConfirmDeleteComment();
|
|
|
|
|
assert.isTrue(element.$.restAPI.deleteComment.calledWith(
|
|
|
|
|
42, 0xDEADBEEF, 'baf0414d_60047215', 'removal reason'));
|
|
|
|
|
done();
|
|
|
|
|
});
|
2017-05-08 10:40:06 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
2018-05-14 12:59:23 -07:00
|
|
|
|
|
|
|
|
|
suite('draft update reporting', () => {
|
2018-06-13 14:14:38 -07:00
|
|
|
|
let endStub;
|
|
|
|
|
let getTimerStub;
|
2018-05-14 12:59:23 -07:00
|
|
|
|
let mockEvent;
|
|
|
|
|
|
|
|
|
|
setup(() => {
|
|
|
|
|
mockEvent = {preventDefault() {}};
|
|
|
|
|
sandbox.stub(element, 'save')
|
|
|
|
|
.returns(Promise.resolve({}));
|
|
|
|
|
sandbox.stub(element, '_discardDraft')
|
|
|
|
|
.returns(Promise.resolve({}));
|
2018-06-13 14:14:38 -07:00
|
|
|
|
endStub = sinon.stub();
|
|
|
|
|
getTimerStub = sandbox.stub(element.$.reporting, 'getTimer')
|
|
|
|
|
.returns({end: endStub});
|
2018-05-14 12:59:23 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('create', () => {
|
|
|
|
|
element.comment = {};
|
|
|
|
|
return element._handleSave(mockEvent).then(() => {
|
2018-06-13 14:14:38 -07:00
|
|
|
|
assert.isTrue(endStub.calledOnce);
|
|
|
|
|
assert.isTrue(getTimerStub.calledOnce);
|
|
|
|
|
assert.equal(getTimerStub.lastCall.args[0], 'CreateDraftComment');
|
2018-05-14 12:59:23 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update', () => {
|
|
|
|
|
element.comment = {id: 'abc_123'};
|
|
|
|
|
return element._handleSave(mockEvent).then(() => {
|
2018-06-13 14:14:38 -07:00
|
|
|
|
assert.isTrue(endStub.calledOnce);
|
|
|
|
|
assert.isTrue(getTimerStub.calledOnce);
|
|
|
|
|
assert.equal(getTimerStub.lastCall.args[0], 'UpdateDraftComment');
|
2018-05-14 12:59:23 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('discard', () => {
|
|
|
|
|
element.comment = {id: 'abc_123'};
|
|
|
|
|
sandbox.stub(element, '_closeConfirmDiscardOverlay');
|
|
|
|
|
return element._handleConfirmDiscard(mockEvent).then(() => {
|
2018-06-13 14:14:38 -07:00
|
|
|
|
assert.isTrue(endStub.calledOnce);
|
|
|
|
|
assert.isTrue(getTimerStub.calledOnce);
|
|
|
|
|
assert.equal(getTimerStub.lastCall.args[0], 'DiscardDraftComment');
|
2018-05-14 12:59:23 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-06-19 17:03:43 -07:00
|
|
|
|
|
|
|
|
|
test('edit reports interaction', () => {
|
|
|
|
|
const reportStub = sandbox.stub(element.$.reporting,
|
|
|
|
|
'recordDraftInteraction');
|
|
|
|
|
MockInteractions.tap(element.$$('.edit'));
|
|
|
|
|
assert.isTrue(reportStub.calledOnce);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('discard reports interaction', () => {
|
|
|
|
|
const reportStub = sandbox.stub(element.$.reporting,
|
|
|
|
|
'recordDraftInteraction');
|
|
|
|
|
element.draft = true;
|
|
|
|
|
MockInteractions.tap(element.$$('.discard'));
|
|
|
|
|
assert.isTrue(reportStub.calledOnce);
|
|
|
|
|
});
|
2015-12-02 11:40:14 -05:00
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
suite('gr-diff-comment draft tests', () => {
|
|
|
|
|
let element;
|
|
|
|
|
let sandbox;
|
2015-12-02 11:40:14 -05:00
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
setup(() => {
|
2016-05-03 15:14:57 -04:00
|
|
|
|
stub('gr-rest-api-interface', {
|
2017-05-16 13:50:27 -07:00
|
|
|
|
getAccount() { return Promise.resolve(null); },
|
|
|
|
|
saveDiffDraft() {
|
2016-05-03 15:14:57 -04:00
|
|
|
|
return Promise.resolve({
|
|
|
|
|
ok: true,
|
2017-05-16 13:50:27 -07:00
|
|
|
|
text() {
|
2016-05-03 15:14:57 -04:00
|
|
|
|
return Promise.resolve(
|
2017-05-16 13:50:27 -07:00
|
|
|
|
')]}\'\n{' +
|
2016-05-03 15:14:57 -04:00
|
|
|
|
'"id": "baf0414d_40572e03",' +
|
|
|
|
|
'"path": "/path/to/file",' +
|
|
|
|
|
'"line": 5,' +
|
|
|
|
|
'"updated": "2015-12-08 21:52:36.177000000",' +
|
|
|
|
|
'"message": "saved!"' +
|
|
|
|
|
'}'
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
2017-05-16 13:50:27 -07:00
|
|
|
|
removeChangeReviewer() {
|
2016-05-03 15:14:57 -04:00
|
|
|
|
return Promise.resolve({ok: true});
|
|
|
|
|
},
|
|
|
|
|
});
|
2016-06-05 12:20:11 +02:00
|
|
|
|
stub('gr-storage', {
|
2017-05-16 13:50:27 -07:00
|
|
|
|
getDraftComment() { return null; },
|
2016-06-05 12:20:11 +02:00
|
|
|
|
});
|
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 = {
|
2017-01-30 12:03:13 -08:00
|
|
|
|
__commentSide: 'right',
|
2015-12-02 11:40:14 -05:00
|
|
|
|
__draft: true,
|
|
|
|
|
__draftID: 'temp_draft_id',
|
|
|
|
|
path: '/path/to/file',
|
|
|
|
|
line: 5,
|
|
|
|
|
};
|
2017-01-30 12:03:13 -08:00
|
|
|
|
element.commentSide = 'right';
|
2016-12-01 10:55:14 -08:00
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
teardown(() => {
|
2016-12-01 10:55:14 -08:00
|
|
|
|
sandbox.restore();
|
2015-12-02 11:40:14 -05:00
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('button visibility states', () => {
|
2015-12-20 19:13:45 -05:00
|
|
|
|
element.showActions = false;
|
2016-12-07 13:36:49 -08:00
|
|
|
|
assert.isTrue(element.$$('.humanActions').hasAttribute('hidden'));
|
|
|
|
|
assert.isTrue(element.$$('.robotActions').hasAttribute('hidden'));
|
|
|
|
|
|
2015-12-20 19:13:45 -05:00
|
|
|
|
element.showActions = true;
|
2016-12-07 13:36:49 -08:00
|
|
|
|
assert.isFalse(element.$$('.humanActions').hasAttribute('hidden'));
|
|
|
|
|
assert.isTrue(element.$$('.robotActions').hasAttribute('hidden'));
|
2015-12-20 19:13:45 -05:00
|
|
|
|
|
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');
|
2017-12-05 11:03:52 -08:00
|
|
|
|
assert.isTrue(isVisible(element.$$('.resolve')), 'resolve is visible');
|
2016-12-07 13:36:49 -08:00
|
|
|
|
assert.isFalse(element.$$('.humanActions').hasAttribute('hidden'));
|
|
|
|
|
assert.isTrue(element.$$('.robotActions').hasAttribute('hidden'));
|
2015-12-02 11:40:14 -05:00
|
|
|
|
|
|
|
|
|
element.editing = true;
|
2018-04-05 10:48:03 -07:00
|
|
|
|
flushAsynchronousOperations();
|
2016-02-02 21:02:42 +01:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.edit')), 'edit is not visible');
|
2017-11-01 12:15:19 -07:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.discard')), 'discard not visible');
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert.isTrue(isVisible(element.$$('.save')), 'save is visible');
|
2017-11-06 17:02:06 -08:00
|
|
|
|
assert.isTrue(isVisible(element.$$('.cancel')), 'cancel is visible');
|
2017-01-04 16:45:21 -08:00
|
|
|
|
assert.isTrue(isVisible(element.$$('.resolve')), 'resolve is visible');
|
2016-12-07 13:36:49 -08:00
|
|
|
|
assert.isFalse(element.$$('.humanActions').hasAttribute('hidden'));
|
|
|
|
|
assert.isTrue(element.$$('.robotActions').hasAttribute('hidden'));
|
2015-12-02 11:40:14 -05:00
|
|
|
|
|
2016-02-02 21:02:42 +01:00
|
|
|
|
element.draft = false;
|
2015-12-02 11:40:14 -05:00
|
|
|
|
element.editing = false;
|
2018-04-05 10:48:03 -07:00
|
|
|
|
flushAsynchronousOperations();
|
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-12-07 13:36:49 -08:00
|
|
|
|
assert.isFalse(element.$$('.humanActions').hasAttribute('hidden'));
|
|
|
|
|
assert.isTrue(element.$$('.robotActions').hasAttribute('hidden'));
|
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;
|
2018-04-05 10:48:03 -07:00
|
|
|
|
flushAsynchronousOperations();
|
2016-01-28 18:07:26 -05:00
|
|
|
|
assert.isTrue(isVisible(element.$$('.cancel')), 'cancel is visible');
|
2016-12-07 13:36:49 -08:00
|
|
|
|
assert.isFalse(element.$$('.humanActions').hasAttribute('hidden'));
|
|
|
|
|
assert.isTrue(element.$$('.robotActions').hasAttribute('hidden'));
|
|
|
|
|
|
|
|
|
|
element.isRobotComment = true;
|
|
|
|
|
element.draft = true;
|
|
|
|
|
assert.isTrue(element.$$('.humanActions').hasAttribute('hidden'));
|
|
|
|
|
assert.isFalse(element.$$('.robotActions').hasAttribute('hidden'));
|
|
|
|
|
|
|
|
|
|
// It is not expected to see Robot comment drafts, but if they appear,
|
|
|
|
|
// they will behave the same as non-drafts.
|
|
|
|
|
element.draft = false;
|
|
|
|
|
assert.isTrue(element.$$('.humanActions').hasAttribute('hidden'));
|
|
|
|
|
assert.isFalse(element.$$('.robotActions').hasAttribute('hidden'));
|
2018-03-14 15:26:45 -07:00
|
|
|
|
|
|
|
|
|
// A robot comment with run ID should display plain text.
|
|
|
|
|
element.set(['comment', 'robot_run_id'], 'text');
|
|
|
|
|
element.editing = false;
|
|
|
|
|
element.collapsed = false;
|
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
|
assert.isNotOk(element.$$('.robotRun.link'));
|
|
|
|
|
assert.notEqual(getComputedStyle(element.$$('.robotRun.text')).display,
|
|
|
|
|
'none');
|
|
|
|
|
|
|
|
|
|
// A robot comment with run ID and url should display a link.
|
|
|
|
|
element.set(['comment', 'url'], '/path/to/run');
|
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
|
assert.notEqual(getComputedStyle(element.$$('.robotRun.link')).display,
|
|
|
|
|
'none');
|
|
|
|
|
assert.equal(getComputedStyle(element.$$('.robotRun.text')).display,
|
|
|
|
|
'none');
|
2015-12-02 11:40:14 -05:00
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('collapsible drafts', () => {
|
2016-10-10 17:31:56 -07:00
|
|
|
|
assert.isTrue(element.collapsed);
|
2016-11-08 15:49:05 -08:00
|
|
|
|
assert.isFalse(isVisible(element.$$('gr-formatted-text')),
|
|
|
|
|
'gr-formatted-text is not visible');
|
2016-10-06 10:18:32 -07:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.actions')),
|
|
|
|
|
'actions are not visible');
|
2018-04-05 10:48:03 -07:00
|
|
|
|
assert.isNotOk(element.textarea, 'textarea is not visible');
|
2016-10-06 10:18:32 -07:00
|
|
|
|
assert.isTrue(isVisible(element.$$('.collapsedContent')),
|
|
|
|
|
'header middle content is visible');
|
|
|
|
|
|
|
|
|
|
MockInteractions.tap(element.$.header);
|
2016-10-10 17:31:56 -07:00
|
|
|
|
assert.isFalse(element.collapsed);
|
2016-11-08 15:49:05 -08:00
|
|
|
|
assert.isTrue(isVisible(element.$$('gr-formatted-text')),
|
|
|
|
|
'gr-formatted-text is visible');
|
2016-10-06 10:18:32 -07:00
|
|
|
|
assert.isTrue(isVisible(element.$$('.actions')),
|
|
|
|
|
'actions are visible');
|
2018-04-05 10:48:03 -07:00
|
|
|
|
assert.isNotOk(element.textarea, 'textarea is not visible');
|
2016-10-06 10:18:32 -07:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.collapsedContent')),
|
|
|
|
|
'header middle content is is not visible');
|
|
|
|
|
|
|
|
|
|
// When the edit button is pressed, should still see the actions
|
|
|
|
|
// and also textarea
|
|
|
|
|
MockInteractions.tap(element.$$('.edit'));
|
2018-04-05 10:48:03 -07:00
|
|
|
|
flushAsynchronousOperations();
|
2016-10-10 17:31:56 -07:00
|
|
|
|
assert.isFalse(element.collapsed);
|
2016-11-08 15:49:05 -08:00
|
|
|
|
assert.isFalse(isVisible(element.$$('gr-formatted-text')),
|
|
|
|
|
'gr-formatted-text is not visible');
|
2016-10-06 10:18:32 -07:00
|
|
|
|
assert.isTrue(isVisible(element.$$('.actions')),
|
|
|
|
|
'actions are visible');
|
2018-04-05 10:48:03 -07:00
|
|
|
|
assert.isTrue(isVisible(element.textarea), 'textarea is visible');
|
2016-10-06 10:18:32 -07:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.collapsedContent')),
|
|
|
|
|
'header middle content is not visible');
|
|
|
|
|
|
|
|
|
|
// When toggle again, everything should be hidden except for textarea
|
|
|
|
|
// and header middle content should be visible
|
|
|
|
|
MockInteractions.tap(element.$.header);
|
2016-10-10 17:31:56 -07:00
|
|
|
|
assert.isTrue(element.collapsed);
|
2016-11-08 15:49:05 -08:00
|
|
|
|
assert.isFalse(isVisible(element.$$('gr-formatted-text')),
|
|
|
|
|
'gr-formatted-text is not visible');
|
2016-10-06 10:18:32 -07:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.actions')),
|
|
|
|
|
'actions are not visible');
|
2017-05-03 10:03:35 -07:00
|
|
|
|
assert.isFalse(isVisible(element.$$('gr-textarea')),
|
2016-10-06 10:18:32 -07:00
|
|
|
|
'textarea is not visible');
|
|
|
|
|
assert.isTrue(isVisible(element.$$('.collapsedContent')),
|
|
|
|
|
'header middle content is visible');
|
|
|
|
|
|
|
|
|
|
// When toggle again, textarea should remain open in the state it was
|
|
|
|
|
// before
|
|
|
|
|
MockInteractions.tap(element.$.header);
|
2016-11-08 15:49:05 -08:00
|
|
|
|
assert.isFalse(isVisible(element.$$('gr-formatted-text')),
|
|
|
|
|
'gr-formatted-text is not visible');
|
2016-10-06 10:18:32 -07:00
|
|
|
|
assert.isTrue(isVisible(element.$$('.actions')),
|
|
|
|
|
'actions are visible');
|
2018-04-05 10:48:03 -07:00
|
|
|
|
assert.isTrue(isVisible(element.textarea), 'textarea is visible');
|
2016-10-06 10:18:32 -07:00
|
|
|
|
assert.isFalse(isVisible(element.$$('.collapsedContent')),
|
|
|
|
|
'header middle content is not visible');
|
|
|
|
|
});
|
|
|
|
|
|
2017-11-27 16:13:06 -08:00
|
|
|
|
test('draft creation/cancellation', done => {
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert.isFalse(element.editing);
|
|
|
|
|
MockInteractions.tap(element.$$('.edit'));
|
|
|
|
|
assert.isTrue(element.editing);
|
|
|
|
|
|
2016-05-23 13:53:10 -07:00
|
|
|
|
element._messageText = '';
|
2017-05-16 13:50:27 -07:00
|
|
|
|
const eraseMessageDraftSpy = sandbox.spy(element, '_eraseDraftComment');
|
2016-12-01 10:55:14 -08:00
|
|
|
|
|
2015-12-02 11:40:14 -05:00
|
|
|
|
// Save should be disabled on an empty message.
|
2017-05-16 13:50:27 -07:00
|
|
|
|
let disabled = element.$$('.save').hasAttribute('disabled');
|
2015-12-02 11:40:14 -05:00
|
|
|
|
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.');
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
const updateStub = sinon.stub();
|
2016-08-05 15:05:50 -07:00
|
|
|
|
element.addEventListener('comment-update', updateStub);
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
let numDiscardEvents = 0;
|
|
|
|
|
element.addEventListener('comment-discard', e => {
|
2015-12-02 11:40:14 -05:00
|
|
|
|
numDiscardEvents++;
|
2016-12-01 10:55:14 -08:00
|
|
|
|
assert.isFalse(eraseMessageDraftSpy.called);
|
|
|
|
|
if (numDiscardEvents === 2) {
|
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'));
|
2016-08-05 15:05:50 -07:00
|
|
|
|
element.flushDebouncer('fire-update');
|
2016-11-02 14:18:48 -07:00
|
|
|
|
element._messageText = '';
|
2018-04-05 10:48:03 -07:00
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(element.textarea, 27); // esc
|
2015-12-02 11:40:14 -05:00
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('draft discard removes message from storage', done => {
|
2016-12-01 10:55:14 -08:00
|
|
|
|
element._messageText = '';
|
2017-05-16 13:50:27 -07:00
|
|
|
|
const eraseMessageDraftSpy = sandbox.spy(element, '_eraseDraftComment');
|
2017-10-18 13:22:43 -07:00
|
|
|
|
sandbox.stub(element, '_closeConfirmDiscardOverlay');
|
2016-12-01 10:55:14 -08:00
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
element.addEventListener('comment-discard', e => {
|
2016-12-01 10:55:14 -08:00
|
|
|
|
assert.isTrue(eraseMessageDraftSpy.called);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2017-10-18 13:22:43 -07:00
|
|
|
|
element._handleConfirmDiscard({preventDefault: sinon.stub()});
|
|
|
|
|
});
|
|
|
|
|
|
2017-10-26 14:11:24 -07:00
|
|
|
|
test('storage is cleared only after save success', () => {
|
2017-11-27 16:13:06 -08:00
|
|
|
|
element._messageText = 'test';
|
2017-10-26 14:11:24 -07:00
|
|
|
|
const eraseStub = sandbox.stub(element, '_eraseDraftComment');
|
|
|
|
|
sandbox.stub(element.$.restAPI, 'getResponseObject')
|
|
|
|
|
.returns(Promise.resolve({}));
|
|
|
|
|
|
|
|
|
|
sandbox.stub(element, '_saveDraft').returns(Promise.resolve({ok: false}));
|
|
|
|
|
|
|
|
|
|
const savePromise = element.save();
|
|
|
|
|
assert.isFalse(eraseStub.called);
|
|
|
|
|
return savePromise.then(() => {
|
|
|
|
|
assert.isFalse(eraseStub.called);
|
|
|
|
|
|
|
|
|
|
element._saveDraft.restore();
|
|
|
|
|
sandbox.stub(element, '_saveDraft')
|
|
|
|
|
.returns(Promise.resolve({ok: true}));
|
|
|
|
|
return element.save().then(() => {
|
|
|
|
|
assert.isTrue(eraseStub.called);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-11-27 16:13:06 -08:00
|
|
|
|
test('_computeSaveDisabled', () => {
|
2017-12-05 11:03:52 -08:00
|
|
|
|
const comment = {unresolved: true};
|
|
|
|
|
const msgComment = {message: 'test', unresolved: true};
|
|
|
|
|
assert.equal(element._computeSaveDisabled('', comment, false), true);
|
|
|
|
|
assert.equal(element._computeSaveDisabled('test', comment, false), false);
|
2018-01-18 14:51:41 -08:00
|
|
|
|
assert.equal(element._computeSaveDisabled('', msgComment, false), true);
|
2017-12-05 11:03:52 -08:00
|
|
|
|
assert.equal(
|
2018-01-18 14:51:41 -08:00
|
|
|
|
element._computeSaveDisabled('test', msgComment, false), false);
|
2017-12-05 11:03:52 -08:00
|
|
|
|
assert.equal(
|
|
|
|
|
element._computeSaveDisabled('test2', msgComment, false), false);
|
|
|
|
|
assert.equal(element._computeSaveDisabled('test', comment, true), false);
|
|
|
|
|
assert.equal(element._computeSaveDisabled('', comment, true), true);
|
|
|
|
|
assert.equal(element._computeSaveDisabled('', comment, false), true);
|
2017-11-27 16:13:06 -08:00
|
|
|
|
});
|
|
|
|
|
|
2017-10-18 13:22:43 -07:00
|
|
|
|
suite('confirm discard', () => {
|
|
|
|
|
let discardStub;
|
|
|
|
|
let overlayStub;
|
|
|
|
|
let mockEvent;
|
|
|
|
|
|
|
|
|
|
setup(() => {
|
|
|
|
|
discardStub = sandbox.stub(element, '_discardDraft');
|
2018-07-10 18:04:44 -07:00
|
|
|
|
overlayStub = sandbox.stub(element, '_openOverlay')
|
|
|
|
|
.returns(Promise.resolve());
|
2017-10-18 13:22:43 -07:00
|
|
|
|
mockEvent = {preventDefault: sinon.stub()};
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-05 11:40:43 -08:00
|
|
|
|
test('confirms discard of comments with message text', () => {
|
|
|
|
|
element._messageText = 'test';
|
2017-10-18 13:22:43 -07:00
|
|
|
|
element._handleDiscard(mockEvent);
|
2018-04-05 10:48:03 -07:00
|
|
|
|
assert.isTrue(overlayStub.calledWith(element.confirmDiscardOverlay));
|
2017-10-18 13:22:43 -07:00
|
|
|
|
assert.isFalse(discardStub.called);
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-05 11:40:43 -08:00
|
|
|
|
test('no confirmation for comments without message text', () => {
|
|
|
|
|
element._messageText = '';
|
2017-10-18 13:22:43 -07:00
|
|
|
|
element._handleDiscard(mockEvent);
|
|
|
|
|
assert.isFalse(overlayStub.called);
|
|
|
|
|
assert.isTrue(discardStub.calledOnce);
|
|
|
|
|
});
|
2016-12-01 10:55:14 -08:00
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('ctrl+s saves comment', done => {
|
|
|
|
|
const stub = sinon.stub(element, 'save', () => {
|
2016-08-23 12:07:04 -07:00
|
|
|
|
assert.isTrue(stub.called);
|
|
|
|
|
stub.restore();
|
|
|
|
|
done();
|
2018-05-14 12:59:23 -07:00
|
|
|
|
return Promise.resolve();
|
2016-08-23 12:07:04 -07:00
|
|
|
|
});
|
|
|
|
|
element._messageText = 'is that the horse from horsing around??';
|
2018-04-05 10:48:03 -07:00
|
|
|
|
element.editing = true;
|
|
|
|
|
flushAsynchronousOperations();
|
2016-08-23 12:07:04 -07:00
|
|
|
|
MockInteractions.pressAndReleaseKeyOn(
|
2018-04-05 10:48:03 -07:00
|
|
|
|
element.textarea.$.textarea.textarea,
|
2017-07-05 11:17:26 -07:00
|
|
|
|
83, 'ctrl'); // 'ctrl + s'
|
2016-08-23 12:07:04 -07:00
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('draft saving/editing', done => {
|
|
|
|
|
const fireStub = sinon.stub(element, 'fire');
|
2017-05-17 16:00:33 -07:00
|
|
|
|
const cancelDebounce = sandbox.stub(element, 'cancelDebouncer');
|
2016-05-23 15:24:05 -07:00
|
|
|
|
|
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'),
|
2017-05-16 13:50:27 -07:00
|
|
|
|
'comment-update should be sent');
|
Clean up comment editing UX
The removal of the 'Discard' button from comments in the editing state
complicated the UX of the 'Cancel' button a bit.
Previously:
- Discard deleted the draft completely.
- Cancel cancelled whatever edits were made, and reverted to the prior
draft state. Cancel was also hidden on new drafts.
Currently:
- Cancel cancels whatever edits were made, and reverts to whatever edit
was last stored.
This behavior is problematic, for a few reasons:
- Due to some vestigial code, the actual value of the comment's message
(not just the buffer value '_messageText') was updated any time the
draft comment was edited. This was done to prevent multiple drafts
from being created on the same thread -- that issue was made obsolete
by the removal of buttons from individual comments, and their
consolidation to the thread level.
- If a user cancels a draft, then restarts it (having their text
repopulated from localstorage), then cancels it again, the draft is
rendered as a saved draft comment with the localstorage value, despite
having never been saved at all.
So, with this change:
- Cancel cancels whatever edits were made.
- If a user tries to add a draft in the same place...
- ...and the draft has been saved on the server, the textarea is
prepopulated with the value from the comment received from the
server.
- ...and the draft has NOT been saved on the server, the textarea is
rehydrated from localstorage.
This UX makes sense because...
- Case 1 occurs when a user clicks "Edit" on an existing draft comment -
thus expecting to edit the content shown in the UI.
- Case 2 occurs when a user cancels a draft that they started
constructing, but did not save -- thus there is no suggestion of any
prepopulated value by the UI, _and_ the case in which a draft was
erroneously cancelled during editing can be solved.
Bug: Issue 7709
Change-Id: Iacf9a91fbb0226aba3a518f56edd61f28c15a8ef
2017-11-09 11:38:59 -08:00
|
|
|
|
assert.isTrue(fireStub.calledOnce);
|
|
|
|
|
|
|
|
|
|
element._messageText = 'good news, everyone!';
|
|
|
|
|
element.flushDebouncer('fire-update');
|
|
|
|
|
element.flushDebouncer('store');
|
|
|
|
|
assert.isTrue(fireStub.calledOnce,
|
|
|
|
|
'No events should fire for text editing');
|
|
|
|
|
|
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.');
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
element._xhrPromise.then(draft => {
|
2016-05-23 15:24:05 -07:00
|
|
|
|
assert(fireStub.calledWith('comment-save'),
|
2017-05-16 13:50:27 -07:00
|
|
|
|
'comment-save should be sent');
|
2017-05-16 15:12:08 -07:00
|
|
|
|
assert(cancelDebounce.calledWith('store'));
|
2017-05-16 13:50:27 -07:00
|
|
|
|
|
2016-07-14 12:31:09 -07:00
|
|
|
|
assert.deepEqual(fireStub.lastCall.args[1], {
|
|
|
|
|
comment: {
|
2017-01-30 12:03:13 -08:00
|
|
|
|
__commentSide: 'right',
|
2016-07-14 12:31:09 -07:00
|
|
|
|
__draft: true,
|
|
|
|
|
__draftID: 'temp_draft_id',
|
|
|
|
|
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,
|
2017-05-16 13:50:27 -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);
|
2017-05-16 13:50:27 -07:00
|
|
|
|
}).then(() => {
|
2015-12-02 11:40:14 -05:00
|
|
|
|
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.');
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
element._xhrPromise.then(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();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-10-24 16:34:10 -07:00
|
|
|
|
test('draft prevent save when disabled', () => {
|
2018-05-14 12:59:23 -07:00
|
|
|
|
const saveStub = sandbox.stub(element, 'save').returns(Promise.resolve());
|
2018-03-08 17:29:09 -08:00
|
|
|
|
element.showActions = true;
|
2017-10-24 16:34:10 -07:00
|
|
|
|
element.draft = true;
|
2018-03-08 17:29:09 -08:00
|
|
|
|
MockInteractions.tap(element.$.header);
|
2017-10-24 16:34:10 -07:00
|
|
|
|
MockInteractions.tap(element.$$('.edit'));
|
|
|
|
|
element._messageText = 'good news, everyone!';
|
|
|
|
|
element.flushDebouncer('fire-update');
|
|
|
|
|
element.flushDebouncer('store');
|
|
|
|
|
|
|
|
|
|
element.disabled = true;
|
|
|
|
|
MockInteractions.tap(element.$$('.save'));
|
|
|
|
|
assert.isFalse(saveStub.called);
|
|
|
|
|
|
|
|
|
|
element.disabled = false;
|
|
|
|
|
MockInteractions.tap(element.$$('.save'));
|
|
|
|
|
assert.isTrue(saveStub.calledOnce);
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('clicking on date link does not trigger nav', () => {
|
|
|
|
|
const showStub = sinon.stub(page, 'show');
|
|
|
|
|
const dateEl = element.$$('.date');
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert.ok(dateEl);
|
|
|
|
|
MockInteractions.tap(dateEl);
|
2017-05-16 13:50:27 -07:00
|
|
|
|
const dest = window.location.pathname + '#5';
|
2015-12-02 11:40:14 -05:00
|
|
|
|
assert(showStub.lastCall.calledWithExactly(dest, null, false),
|
|
|
|
|
'Should navigate to ' + dest + ' without triggering nav');
|
|
|
|
|
showStub.restore();
|
|
|
|
|
});
|
2017-01-04 16:45:21 -08:00
|
|
|
|
|
2017-12-05 11:03:52 -08:00
|
|
|
|
test('proper event fires on resolve, comment is not saved', done => {
|
2017-12-06 11:25:30 -08:00
|
|
|
|
const save = sandbox.stub(element, 'save');
|
2017-05-16 13:50:27 -07:00
|
|
|
|
element.addEventListener('comment-update', e => {
|
2017-01-04 16:45:21 -08:00
|
|
|
|
assert.isTrue(e.detail.comment.unresolved);
|
2017-12-05 11:03:52 -08:00
|
|
|
|
assert.isFalse(save.called);
|
2017-01-04 16:45:21 -08:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
MockInteractions.tap(element.$$('.resolve input'));
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
test('resolved comment state indicated by checkbox', () => {
|
2017-12-06 11:25:30 -08:00
|
|
|
|
sandbox.stub(element, 'save');
|
2017-01-04 16:45:21 -08:00
|
|
|
|
element.comment = {unresolved: false};
|
|
|
|
|
assert.isTrue(element.$$('.resolve input').checked);
|
|
|
|
|
element.comment = {unresolved: true};
|
|
|
|
|
assert.isFalse(element.$$('.resolve input').checked);
|
|
|
|
|
});
|
2017-09-12 17:01:42 -07:00
|
|
|
|
|
2018-03-08 17:29:09 -08:00
|
|
|
|
test('resolved checkbox saves with tap when !editing', () => {
|
2017-12-05 11:03:52 -08:00
|
|
|
|
element.editing = false;
|
2017-12-06 11:25:30 -08:00
|
|
|
|
const save = sandbox.stub(element, 'save');
|
2017-12-05 11:03:52 -08:00
|
|
|
|
|
|
|
|
|
element.comment = {unresolved: false};
|
|
|
|
|
assert.isTrue(element.$$('.resolve input').checked);
|
|
|
|
|
element.comment = {unresolved: true};
|
|
|
|
|
assert.isFalse(element.$$('.resolve input').checked);
|
2018-03-08 17:29:09 -08:00
|
|
|
|
assert.isFalse(save.called);
|
|
|
|
|
MockInteractions.tap(element.$.resolvedCheckbox);
|
|
|
|
|
assert.isTrue(element.$$('.resolve input').checked);
|
2017-12-05 11:03:52 -08:00
|
|
|
|
assert.isTrue(save.called);
|
|
|
|
|
});
|
|
|
|
|
|
2017-09-12 17:01:42 -07:00
|
|
|
|
suite('draft saving messages', () => {
|
|
|
|
|
test('_getSavingMessage', () => {
|
|
|
|
|
assert.equal(element._getSavingMessage(0), 'All changes saved');
|
|
|
|
|
assert.equal(element._getSavingMessage(1), 'Saving 1 draft...');
|
|
|
|
|
assert.equal(element._getSavingMessage(2), 'Saving 2 drafts...');
|
|
|
|
|
assert.equal(element._getSavingMessage(3), 'Saving 3 drafts...');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('_show{Start,End}Request', () => {
|
|
|
|
|
const updateStub = sandbox.stub(element, '_updateRequestToast');
|
2017-10-26 14:11:24 -07:00
|
|
|
|
element._numPendingDraftRequests.number = 1;
|
2017-09-12 17:01:42 -07:00
|
|
|
|
|
|
|
|
|
element._showStartRequest();
|
|
|
|
|
assert.isTrue(updateStub.calledOnce);
|
|
|
|
|
assert.equal(updateStub.lastCall.args[0], 2);
|
2017-10-26 14:11:24 -07:00
|
|
|
|
assert.equal(element._numPendingDraftRequests.number, 2);
|
2017-09-12 17:01:42 -07:00
|
|
|
|
|
|
|
|
|
element._showEndRequest();
|
|
|
|
|
assert.isTrue(updateStub.calledTwice);
|
|
|
|
|
assert.equal(updateStub.lastCall.args[0], 1);
|
2017-10-26 14:11:24 -07:00
|
|
|
|
assert.equal(element._numPendingDraftRequests.number, 1);
|
2017-09-12 17:01:42 -07:00
|
|
|
|
|
|
|
|
|
element._showEndRequest();
|
|
|
|
|
assert.isTrue(updateStub.calledThrice);
|
|
|
|
|
assert.equal(updateStub.lastCall.args[0], 0);
|
2017-10-26 14:11:24 -07:00
|
|
|
|
assert.equal(element._numPendingDraftRequests.number, 0);
|
2017-09-12 17:01:42 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
2017-11-02 18:17:52 -07:00
|
|
|
|
|
Clean up comment editing UX
The removal of the 'Discard' button from comments in the editing state
complicated the UX of the 'Cancel' button a bit.
Previously:
- Discard deleted the draft completely.
- Cancel cancelled whatever edits were made, and reverted to the prior
draft state. Cancel was also hidden on new drafts.
Currently:
- Cancel cancels whatever edits were made, and reverts to whatever edit
was last stored.
This behavior is problematic, for a few reasons:
- Due to some vestigial code, the actual value of the comment's message
(not just the buffer value '_messageText') was updated any time the
draft comment was edited. This was done to prevent multiple drafts
from being created on the same thread -- that issue was made obsolete
by the removal of buttons from individual comments, and their
consolidation to the thread level.
- If a user cancels a draft, then restarts it (having their text
repopulated from localstorage), then cancels it again, the draft is
rendered as a saved draft comment with the localstorage value, despite
having never been saved at all.
So, with this change:
- Cancel cancels whatever edits were made.
- If a user tries to add a draft in the same place...
- ...and the draft has been saved on the server, the textarea is
prepopulated with the value from the comment received from the
server.
- ...and the draft has NOT been saved on the server, the textarea is
rehydrated from localstorage.
This UX makes sense because...
- Case 1 occurs when a user clicks "Edit" on an existing draft comment -
thus expecting to edit the content shown in the UI.
- Case 2 occurs when a user cancels a draft that they started
constructing, but did not save -- thus there is no suggestion of any
prepopulated value by the UI, _and_ the case in which a draft was
erroneously cancelled during editing can be solved.
Bug: Issue 7709
Change-Id: Iacf9a91fbb0226aba3a518f56edd61f28c15a8ef
2017-11-09 11:38:59 -08:00
|
|
|
|
test('cancelling an unsaved draft discards, persists in storage', () => {
|
|
|
|
|
const discardSpy = sandbox.spy(element, '_fireDiscard');
|
|
|
|
|
const storeStub = sandbox.stub(element.$.storage, 'setDraftComment');
|
|
|
|
|
const eraseStub = sandbox.stub(element.$.storage, 'eraseDraftComment');
|
|
|
|
|
element._messageText = 'test text';
|
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
|
element.flushDebouncer('store');
|
|
|
|
|
|
|
|
|
|
assert.isTrue(storeStub.called);
|
|
|
|
|
assert.equal(storeStub.lastCall.args[1], 'test text');
|
|
|
|
|
element._handleCancel({preventDefault: () => {}});
|
|
|
|
|
assert.isTrue(discardSpy.called);
|
|
|
|
|
assert.isFalse(eraseStub.called);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cancelling edit on a saved draft does not store', () => {
|
|
|
|
|
element.comment.id = 'foo';
|
|
|
|
|
const discardSpy = sandbox.spy(element, '_fireDiscard');
|
|
|
|
|
const storeStub = sandbox.stub(element.$.storage, 'setDraftComment');
|
|
|
|
|
element._messageText = 'test text';
|
|
|
|
|
flushAsynchronousOperations();
|
|
|
|
|
element.flushDebouncer('store');
|
|
|
|
|
|
|
|
|
|
assert.isFalse(storeStub.called);
|
|
|
|
|
element._handleCancel({preventDefault: () => {}});
|
|
|
|
|
assert.isTrue(discardSpy.called);
|
|
|
|
|
});
|
2017-11-27 16:13:06 -08:00
|
|
|
|
|
|
|
|
|
test('deleting text from saved draft and saving deletes the draft', () => {
|
|
|
|
|
element.comment = {id: 'foo', message: 'test'};
|
|
|
|
|
element._messageText = '';
|
|
|
|
|
const discardStub = sandbox.stub(element, '_discardDraft');
|
|
|
|
|
|
|
|
|
|
element.save();
|
|
|
|
|
assert.isTrue(discardStub.called);
|
|
|
|
|
});
|
2015-11-18 16:31:18 -05:00
|
|
|
|
});
|
|
|
|
|
</script>
|