Commit f8be43e5 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Fix off-by-one error by setting root thread visible:false

Ensure empty root threads are not counted when counting results
by always setting this empty thread `visible:false`

Fixes #3137
parent e4f98c5b
...@@ -306,7 +306,11 @@ export default function buildThread(annotations, options) { ...@@ -306,7 +306,11 @@ export default function buildThread(annotations, options) {
thread.children = thread.children.filter(options.threadFilterFn); thread.children = thread.children.filter(options.threadFilterFn);
} }
// Set visibility for threads // Set visibility for threads.
// The root thread itself should be set as non-visible, to avoid confusion
// when counting visible threads. It's a container thread: its children
// are the top-level annotations.
thread.visible = false;
thread = mapThread(thread, thread => { thread = mapThread(thread, thread => {
let threadIsVisible = thread.visible; let threadIsVisible = thread.visible;
......
...@@ -69,9 +69,9 @@ function createThread(fixture, options, keys) { ...@@ -69,9 +69,9 @@ function createThread(fixture, options, keys) {
return rootThread.children; return rootThread.children;
} }
describe('sidebar/helpers/build-thread', function () { describe('sidebar/helpers/build-thread', () => {
describe('threading', function () { describe('threading', () => {
it('arranges parents and children as a thread', function () { it('arranges parents and children as a thread', () => {
const thread = createThread(SIMPLE_FIXTURE); const thread = createThread(SIMPLE_FIXTURE);
assert.deepEqual(thread, [ assert.deepEqual(thread, [
{ {
...@@ -378,6 +378,15 @@ describe('sidebar/helpers/build-thread', function () { ...@@ -378,6 +378,15 @@ describe('sidebar/helpers/build-thread', function () {
]); ]);
}); });
it('sets root thread visible:false so it does not get counted as a visible thread', () => {
// Always set the root-level thread `visible:false` such that it is
// not inadvertently counted as a visible thread. It doesn't contain
// any thread content itself; its children are top-level threads.
const thread = buildThread(SIMPLE_FIXTURE, defaultBuildThreadOpts);
assert.isFalse(thread.visible);
});
it('shows threads containing replies that match the filter', () => { it('shows threads containing replies that match the filter', () => {
const threads = createThread( const threads = createThread(
SIMPLE_FIXTURE, SIMPLE_FIXTURE,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment