Skip to content

Commit 6c14468

Browse files
test: - Add tests of QueryResultsRenderer's findClosestParentTask()
The tests are in ListItem.test.ts for now, as we hope to move the functionality there eventually. Co-Authored-By: Ilyas Landikov <[email protected]>
1 parent 4360a4c commit 6c14468

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Renderer/QueryResultsRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface QueryRendererParameters {
3636
*
3737
* @param listItem
3838
*/
39-
function findClosestParentTask(listItem: ListItem) {
39+
export function findClosestParentTask(listItem: ListItem) {
4040
// Try to find the closest parent that is a task
4141
let closestParentTask = listItem.parent;
4242
while (closestParentTask !== null && !(closestParentTask instanceof Task)) {

tests/Task/ListItem.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { TaskLocation } from '../../src/Task/TaskLocation';
88
import { ListItem } from '../../src/Task/ListItem';
99
import { TaskBuilder } from '../TestingTools/TaskBuilder';
1010
import { fromLine } from '../TestingTools/TestHelpers';
11+
import { findClosestParentTask } from '../../src/Renderer/QueryResultsRenderer';
1112
import { createChildListItem } from './ListItemHelpers';
1213

1314
window.moment = moment;
@@ -100,6 +101,28 @@ describe('list item tests', () => {
100101
});
101102
});
102103

104+
describe('related items', () => {
105+
it('should detect if no closest parent task', () => {
106+
const task = fromLine({ line: '- [ ] task' });
107+
const item = new ListItem('- item', null);
108+
const childOfItem = new ListItem('- child of item', item);
109+
110+
expect(findClosestParentTask(task)).toEqual(null);
111+
expect(findClosestParentTask(item)).toEqual(null);
112+
expect(findClosestParentTask(childOfItem)).toEqual(null);
113+
});
114+
115+
it('should find the closest parent task', () => {
116+
const parentTask = fromLine({ line: '- [ ] task' });
117+
const child = new ListItem('- item', parentTask);
118+
const grandChild = new ListItem('- item', child);
119+
120+
expect(findClosestParentTask(parentTask)).toEqual(null);
121+
expect(findClosestParentTask(child)).toEqual(parentTask);
122+
expect(findClosestParentTask(grandChild)).toEqual(parentTask);
123+
});
124+
});
125+
103126
describe('identicalTo', () => {
104127
it('should test same markdown', () => {
105128
const listItem1 = new ListItem('- same description', null);

0 commit comments

Comments
 (0)