
The tests accidentally used assert() instead of assert.equal(). This still passed because assert is also a function that takes two parameters, an expression and an error message. The test was passing in a truthy expected value as the expression, and so it never threw an error. In the meanwhile, this test was completely broken and referenced several no longer existing fields. So I ended up rewriting it to actually test the methods again. Change-Id: I173722d92ec4d87a000ac90510de373b2f0e62ea
169 lines
5.5 KiB
HTML
169 lines
5.5 KiB
HTML
<!DOCTYPE html>
|
|
<!--
|
|
@license
|
|
Copyright (C) 2017 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-thread-group</title>
|
|
|
|
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
|
|
<script src="../../../bower_components/web-component-tester/browser.js"></script>
|
|
<link rel="import" href="../../../test/common-test-setup.html"/>
|
|
<script src="../../../scripts/util.js"></script>
|
|
|
|
<link rel="import" href="gr-diff-comment-thread-group.html">
|
|
|
|
<script>void(0);</script>
|
|
|
|
<test-fixture id="basic">
|
|
<template>
|
|
<gr-diff-comment-thread-group></gr-diff-comment-thread-group>
|
|
</template>
|
|
</test-fixture>
|
|
|
|
<script>
|
|
suite('gr-diff-comment-thread-group tests', () => {
|
|
let element;
|
|
let sandbox;
|
|
|
|
setup(() => {
|
|
sandbox = sinon.sandbox.create();
|
|
stub('gr-rest-api-interface', {
|
|
getLoggedIn() { return Promise.resolve(false); },
|
|
});
|
|
element = fixture('basic');
|
|
});
|
|
|
|
teardown(() => {
|
|
sandbox.restore();
|
|
});
|
|
|
|
test('getThread', () => {
|
|
const range = {
|
|
start_line: 1,
|
|
start_character: 1,
|
|
end_line: 1,
|
|
end_character: 2,
|
|
};
|
|
element.threads = [
|
|
{
|
|
rootId: 'sallys_confession',
|
|
commentSide: 'left',
|
|
comments: [
|
|
{
|
|
id: 'sallys_confession',
|
|
message: 'i like you, jack',
|
|
updated: '2015-12-23 15:00:20.396000000',
|
|
__commentSide: 'left',
|
|
}, {
|
|
id: 'jacks_reply',
|
|
message: 'i like you, too',
|
|
updated: '2015-12-24 15:01:20.396000000',
|
|
__commentSide: 'left',
|
|
in_reply_to: 'sallys_confession',
|
|
}, {
|
|
id: 'new_draft',
|
|
message: 'i do not like either of you',
|
|
__commentSide: 'left',
|
|
__draft: true,
|
|
in_reply_to: 'sallys_confession',
|
|
updated: '2015-12-20 15:01:20.396000000',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
rootId: 'right_side_comment',
|
|
commentSide: 'right',
|
|
comments: [
|
|
{
|
|
id: 'right_side_comment',
|
|
message: 'right side comment',
|
|
__commentSide: 'right',
|
|
__draft: true,
|
|
updated: '2015-12-20 15:01:20.396000000',
|
|
},
|
|
],
|
|
}, {
|
|
rootId: 'betsys_confession',
|
|
commentSide: 'left',
|
|
range,
|
|
comments: [
|
|
{
|
|
id: 'betsys_confession',
|
|
message: 'i like you more, jack',
|
|
updated: '2015-12-24 15:00:10.396000000',
|
|
range,
|
|
__commentSide: 'left',
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
flushAsynchronousOperations();
|
|
assert.deepEqual(element.getThread('right').rootId, 'right_side_comment');
|
|
assert.deepEqual(element.getThread('right').comments.length, 1);
|
|
assert.deepEqual(element.getThread('left').rootId, 'sallys_confession');
|
|
assert.deepEqual(element.getThread('left').comments.length, 3);
|
|
assert.deepEqual(element.getThread('left', range).rootId,
|
|
'betsys_confession');
|
|
assert.deepEqual(element.getThread('left', range).comments.length, 1);
|
|
});
|
|
|
|
test('addNewThread', () => {
|
|
const commentSide = 'left';
|
|
const range = {startLine: 1, endLine: 2, startChar: 3, endChar: 4};
|
|
element.patchForNewThreads = 5;
|
|
element.addNewThread(commentSide, range);
|
|
assert.equal(element.threads.length, 1);
|
|
assert.equal(element.threads[0].comments.length, 0);
|
|
assert.equal(element.threads[0].commentSide, commentSide);
|
|
assert.equal(element.threads[0].patchNum, 5);
|
|
assert.equal(element.threads[0].range.startLine, range.startLine);
|
|
assert.equal(element.threads[0].range.endLine, range.endLine);
|
|
assert.equal(element.threads[0].range.startChar, range.startChar);
|
|
assert.equal(element.threads[0].range.endChar, range.endChar);
|
|
});
|
|
|
|
test('removeThread', () => {
|
|
element.threads = [
|
|
{rootId: 4711},
|
|
{rootId: 42},
|
|
];
|
|
element.removeThread(4711);
|
|
assert.equal(element.threads.length, 1);
|
|
assert.equal(element.threads[0].rootId, 42);
|
|
});
|
|
|
|
test('_rangesEqual', () => {
|
|
const range1 =
|
|
{startLine: 123, startChar: 345, endLine: 234, endChar: 456};
|
|
const range2 =
|
|
{startLine: 1, startChar: 2, endLine: 3, endChar: 4};
|
|
|
|
assert.isTrue(element._rangesEqual(null, null));
|
|
assert.isTrue(element._rangesEqual(null, undefined));
|
|
assert.isTrue(element._rangesEqual(undefined, null));
|
|
assert.isTrue(element._rangesEqual(undefined, undefined));
|
|
|
|
assert.isFalse(element._rangesEqual(range1, null));
|
|
assert.isFalse(element._rangesEqual(null, range1));
|
|
assert.isFalse(element._rangesEqual(range1, range2));
|
|
|
|
assert.isTrue(element._rangesEqual(range1, Object.assign({}, range1)));
|
|
});
|
|
});
|
|
</script>
|