@@ -8,6 +8,7 @@ import { TaskLocation } from '../../src/Task/TaskLocation';
88import { ListItem } from '../../src/Task/ListItem' ;
99import { TaskBuilder } from '../TestingTools/TaskBuilder' ;
1010import { fromLine } from '../TestingTools/TestHelpers' ;
11+ import { findClosestParentTask } from '../../src/Renderer/QueryResultsRenderer' ;
1112import { createChildListItem } from './ListItemHelpers' ;
1213
1314window . 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+
103126describe ( 'identicalTo' , ( ) => {
104127 it ( 'should test same markdown' , ( ) => {
105128 const listItem1 = new ListItem ( '- same description' , null ) ;
0 commit comments