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

Only force threads to visible if they are not already visible

parent 9ea6d545
...@@ -7,10 +7,10 @@ const NESTED_THREADS = { ...@@ -7,10 +7,10 @@ const NESTED_THREADS = {
id: '1', id: '1',
children: [ children: [
{ id: '1a', children: [{ id: '1ai', children: [] }] }, { id: '1a', children: [{ id: '1ai', children: [] }] },
{ id: '1b', children: [] }, { id: '1b', children: [], visible: true },
{ {
id: '1c', id: '1c',
children: [{ id: '1ci', children: [] }], children: [{ id: '1ci', children: [], visible: false }],
}, },
], ],
}, },
...@@ -21,7 +21,7 @@ const NESTED_THREADS = { ...@@ -21,7 +21,7 @@ const NESTED_THREADS = {
{ {
id: '2b', id: '2b',
children: [ children: [
{ id: '2bi', children: [] }, { id: '2bi', children: [], visible: true },
{ id: '2bii', children: [] }, { id: '2bii', children: [] },
], ],
}, },
...@@ -46,26 +46,31 @@ describe('threadsService', function () { ...@@ -46,26 +46,31 @@ describe('threadsService', function () {
}); });
describe('#forceVisible', () => { describe('#forceVisible', () => {
it('should set the thread and its children force-visible in the store', () => { let nonVisibleThreadIds;
service.forceVisible(NESTED_THREADS); beforeEach(() => {
nonVisibleThreadIds = [
[
'top', 'top',
'1', '1',
'2', '2',
'3', '3',
'1a', '1a',
'1b',
'1c', '1c',
'2a', '2a',
'2b', '2b',
'1ai', '1ai',
'1ci', '1ci',
'2bi',
'2bii', '2bii',
].forEach(threadId => ];
assert.calledWith(fakeStore.setForcedVisible, threadId) });
); it('should set the thread and its children force-visible in the store', () => {
service.forceVisible(NESTED_THREADS);
nonVisibleThreadIds.forEach(threadId => {
assert.calledWith(fakeStore.setForcedVisible, threadId);
assert.callCount(
fakeStore.setForcedVisible,
nonVisibleThreadIds.length
);
});
}); });
it('should not set the visibility on thread ancestors', () => { it('should not set the visibility on thread ancestors', () => {
...@@ -76,14 +81,7 @@ describe('threadsService', function () { ...@@ -76,14 +81,7 @@ describe('threadsService', function () {
for (let i = 0; i < fakeStore.setForcedVisible.callCount; i++) { for (let i = 0; i < fakeStore.setForcedVisible.callCount; i++) {
calledWithThreadIds.push(fakeStore.setForcedVisible.getCall(i).args[0]); calledWithThreadIds.push(fakeStore.setForcedVisible.getCall(i).args[0]);
} }
assert.deepEqual(calledWithThreadIds, [ assert.deepEqual(calledWithThreadIds, ['1ai', '1a', '1ci', '1c', '1']);
'1ai',
'1a',
'1b',
'1ci',
'1c',
'1',
]);
}); });
}); });
}); });
/**
* @typedef {import('../util/build-thread').Thread} Thread
*/
// @ngInject // @ngInject
export default function threadsService(store) { export default function threadsService(store) {
/** /**
* Make this thread and all of its children "visible". This has the effect of * Make this thread and all of its children "visible". This has the effect of
* "unhiding" a thread which is currently hidden by an applied search filter * "unhiding" a thread which is currently hidden by an applied search filter
* (as well as its child threads). * (as well as its child threads). Only threads that are not currently visible
* will be forced visible.
*
* @param {Thread} thread
*/ */
function forceVisible(thread) { function forceVisible(thread) {
thread.children.forEach(child => { thread.children.forEach(child => {
forceVisible(child); forceVisible(child);
}); });
store.setForcedVisible(thread.id, true); if (!thread.visible) {
store.setForcedVisible(thread.id, true);
}
} }
return { return {
......
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