Skip to content

Commit 8bbdb37

Browse files
committed
test: - Teach TaskBuilder to support parent
1 parent e256484 commit 8bbdb37

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

tests/TestingTools/TaskBuilder.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import moment from 'moment';
66
import type { Task } from '../../src/Task/Task';
77
import example_kanban from '../Obsidian/__test_data__/example_kanban.json';
88
import jason_properties from '../Obsidian/__test_data__/jason_properties.json';
9+
import { ListItem } from '../../src/Task/ListItem';
10+
import { TaskLocation } from '../../src/Task/TaskLocation';
11+
import { TasksFile } from '../../src/Scripting/TasksFile';
912
import { TaskBuilder } from './TaskBuilder';
1013

1114
export {};
@@ -25,6 +28,14 @@ describe('TaskBuilder', () => {
2528
expect(task.originalMarkdown).toEqual('- [ ] hello');
2629
});
2730

31+
it('should allow parent to be supplied', () => {
32+
const location = TaskLocation.fromUnknownPosition(new TasksFile('somewhere.md'));
33+
const parent = ListItem.fromListItemLine('- any old list item', null, location);
34+
const builder = new TaskBuilder();
35+
const task = builder.parent(parent).build();
36+
expect(task.parent).toEqual(parent);
37+
});
38+
2839
it('should populate CachedMetadata', () => {
2940
const builder = new TaskBuilder().mockData(example_kanban);
3041
const task = builder.build();

tests/TestingTools/TaskBuilder.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { StatusConfiguration, StatusType } from '../../src/Statuses/StatusConfig
1111
import { TaskLocation } from '../../src/Task/TaskLocation';
1212
import { Priority } from '../../src/Task/Priority';
1313
import { setCurrentCacheFile } from '../__mocks__/obsidian';
14+
import type { ListItem } from '../../src/Task/ListItem';
1415

1516
/**
1617
* A fluent class for creating tasks for tests.
@@ -26,6 +27,8 @@ import { setCurrentCacheFile } from '../__mocks__/obsidian';
2627
*/
2728
export class TaskBuilder {
2829
// NEW_TASK_FIELD_EDIT_REQUIRED
30+
private _parent: ListItem | null = null;
31+
2932
private _status: Status = Status.TODO;
3033
private _description: string = 'my description';
3134
private _path: string = '';
@@ -79,6 +82,7 @@ export class TaskBuilder {
7982
const cachedMetadata = this._mockData?.cachedMetadata ?? {};
8083
const task = new Task({
8184
// NEW_TASK_FIELD_EDIT_REQUIRED
85+
parent: this._parent,
8286
status: this._status,
8387
description: description,
8488
taskLocation: new TaskLocation(
@@ -324,4 +328,9 @@ export class TaskBuilder {
324328
return null;
325329
}
326330
}
331+
332+
public parent(parent: ListItem | null) {
333+
this._parent = parent;
334+
return this;
335+
}
327336
}

0 commit comments

Comments
 (0)