Skip to content

Commit

Permalink
Merge pull request #3109 from ilandikov/refactor-test-renderering-des…
Browse files Browse the repository at this point in the history
…criptions

refactor: test renderering descriptions
  • Loading branch information
claremacrae authored Oct 5, 2024
2 parents e184a8e + b0c567f commit 40466ce
Show file tree
Hide file tree
Showing 10 changed files with 351 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- grandparent list item
- [ ] parent 1
- [ ] child 1
- [ ] grandchild 1
- list item grand grand child
- [ ] child 2
- non task grandchild
- [ ] grand grand child
- [ ] parent 2
8 changes: 7 additions & 1 deletion src/Renderer/QueryResultsRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { postponeButtonTitle, shouldShowPostponeButton } from '../DateTime/Postp
import type { TasksFile } from '../Scripting/TasksFile';
import type { Task } from '../Task/Task';
import { PostponeMenu } from '../ui/Menus/PostponeMenu';
import { TaskLineRenderer, createAndAppendElement } from './TaskLineRenderer';
import { TaskLineRenderer, type TextRenderer, createAndAppendElement } from './TaskLineRenderer';

type BacklinksEventHandler = (ev: MouseEvent, task: Task) => Promise<void>;
type EditButtonClickHandler = (event: MouseEvent, task: Task, allTasks: Task[]) => void;
Expand Down Expand Up @@ -46,6 +46,9 @@ export class QueryResultsRenderer {
public query: IQuery;
protected queryType: string; // whilst there is only one query type, there is no point logging this value

// Renders the description in TaskLineRenderer:
private readonly textRenderer;
// Renders the group heading in this class:
private readonly renderMarkdown;
private readonly obsidianComponent: Component | null;

Expand All @@ -55,11 +58,13 @@ export class QueryResultsRenderer {
tasksFile: TasksFile,
renderMarkdown: (markdown: string, el: HTMLElement, sourcePath: string, component: Component) => Promise<void>,
obsidianComponent: Component | null,
textRenderer: TextRenderer = TaskLineRenderer.obsidianMarkdownRenderer,
) {
this.source = source;
this.tasksFile = tasksFile;
this.renderMarkdown = renderMarkdown;
this.obsidianComponent = obsidianComponent;
this.textRenderer = textRenderer;

// The engine is chosen on the basis of the code block language. Currently,
// there is only the main engine for the plugin, this allows others to be
Expand Down Expand Up @@ -204,6 +209,7 @@ export class QueryResultsRenderer {
if (groupingAttribute && groupingAttribute.length > 0) taskList.dataset.taskGroupBy = groupingAttribute;

const taskLineRenderer = new TaskLineRenderer({
textRenderer: this.textRenderer,
obsidianComponent: this.obsidianComponent,
parentUlElement: taskList,
taskLayoutOptions: this.query.taskLayoutOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/TaskLineRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class TaskLineRenderer {
private readonly taskLayoutOptions: TaskLayoutOptions;
private readonly queryLayoutOptions: QueryLayoutOptions;

private static async obsidianMarkdownRenderer(
public static async obsidianMarkdownRenderer(
text: string,
element: HTMLSpanElement,
path: string,
Expand Down
2 changes: 2 additions & 0 deletions tests/Obsidian/AllCacheSampleData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { inheritance_2siblings } from './__test_data__/inheritance_2siblings';
import { inheritance_listitem_listitem_task } from './__test_data__/inheritance_listitem_listitem_task';
import { inheritance_listitem_task } from './__test_data__/inheritance_listitem_task';
import { inheritance_listitem_task_siblings } from './__test_data__/inheritance_listitem_task_siblings';
import { inheritance_rendering_sample } from './__test_data__/inheritance_rendering_sample';
import { inheritance_task_2listitem_3task } from './__test_data__/inheritance_task_2listitem_3task';
import { inheritance_task_listitem } from './__test_data__/inheritance_task_listitem';
import { inheritance_task_listitem_mixed_grandchildren } from './__test_data__/inheritance_task_listitem_mixed_grandchildren';
Expand Down Expand Up @@ -89,6 +90,7 @@ export function allCacheSampleData() {
inheritance_listitem_listitem_task,
inheritance_listitem_task,
inheritance_listitem_task_siblings,
inheritance_rendering_sample,
inheritance_task_2listitem_3task,
inheritance_task_listitem,
inheritance_task_listitem_mixed_grandchildren,
Expand Down
178 changes: 178 additions & 0 deletions tests/Obsidian/__test_data__/inheritance_rendering_sample.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
export const inheritance_rendering_sample = {
filePath: 'Test Data/inheritance_rendering_sample.md',
fileContents:
'- grandparent list item\n' +
' - [ ] parent 1\n' +
' - [ ] child 1\n' +
' - [ ] grandchild 1\n' +
' - list item grand grand child\n' +
' - [ ] child 2\n' +
' - non task grandchild\n' +
' - [ ] grand grand child\n' +
' - [ ] parent 2\n',
cachedMetadata: {
sections: [
{
type: 'list',
position: {
start: {
line: 0,
col: 0,
offset: 0,
},
end: {
line: 8,
col: 18,
offset: 257,
},
},
},
],
listItems: [
{
position: {
start: {
line: 0,
col: 0,
offset: 0,
},
end: {
line: 0,
col: 24,
offset: 24,
},
},
parent: -1,
},
{
position: {
start: {
line: 1,
col: 3,
offset: 28,
},
end: {
line: 1,
col: 18,
offset: 43,
},
},
parent: 0,
task: ' ',
},
{
position: {
start: {
line: 2,
col: 6,
offset: 50,
},
end: {
line: 2,
col: 21,
offset: 65,
},
},
parent: 1,
task: ' ',
},
{
position: {
start: {
line: 3,
col: 10,
offset: 76,
},
end: {
line: 3,
col: 30,
offset: 96,
},
},
parent: 2,
task: ' ',
},
{
position: {
start: {
line: 4,
col: 14,
offset: 111,
},
end: {
line: 4,
col: 45,
offset: 142,
},
},
parent: 3,
},
{
position: {
start: {
line: 5,
col: 6,
offset: 149,
},
end: {
line: 5,
col: 21,
offset: 164,
},
},
parent: 1,
task: ' ',
},
{
position: {
start: {
line: 6,
col: 10,
offset: 175,
},
end: {
line: 6,
col: 33,
offset: 198,
},
},
parent: 5,
},
{
position: {
start: {
line: 7,
col: 14,
offset: 213,
},
end: {
line: 7,
col: 39,
offset: 238,
},
},
parent: 6,
task: ' ',
},
{
position: {
start: {
line: 8,
col: 3,
offset: 242,
},
end: {
line: 8,
col: 18,
offset: 257,
},
},
parent: 0,
task: ' ',
},
],
},
obsidianApiVersion: '1.7.3',
getAllTags: [],
parseFrontMatterTags: null,
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
data-task-status-type="TODO">
<input class="task-list-item-checkbox" type="checkbox" title="Right-click for options" data-line="0" />
<span class="tasks-list-text">
<span class="task-description"><span></span></span>
<span class="task-description"><span>Do exercises #todo #health</span></span>
<span class="task-id"><span>🆔 abcdef</span></span>
<span class="task-dependsOn"><span>⛔ 123456,abc123</span></span>
<span class="task-priority" data-task-priority="medium"><span>🔼</span></span>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<div>
<ul class="contains-task-list plugin-tasks-query-result tasks-layout-hide-urgency">
<li
class="task-list-item plugin-tasks-list-item"
data-task-priority="normal"
data-task=""
data-line="0"
data-task-status-name="Todo"
data-task-status-type="TODO">
<input class="task-list-item-checkbox" type="checkbox" title="Right-click for options" data-line="0" />
<span class="tasks-list-text">
<span class="task-description"><span>parent 1</span></span>
</span>
<span class="task-extras">
<span class="tasks-backlink">
(
<a rel="noopener" target="_blank" class="internal-link">inheritance_rendering_sample</a>
)
</span>
<a class="tasks-edit" title="Edit task" href="#"></a>
</span>
</li>
<li
class="task-list-item plugin-tasks-list-item"
data-task-priority="normal"
data-task=""
data-line="1"
data-task-status-name="Todo"
data-task-status-type="TODO">
<input class="task-list-item-checkbox" type="checkbox" title="Right-click for options" data-line="1" />
<span class="tasks-list-text">
<span class="task-description"><span>child 1</span></span>
</span>
<span class="task-extras">
<span class="tasks-backlink">
(
<a rel="noopener" target="_blank" class="internal-link">inheritance_rendering_sample</a>
)
</span>
<a class="tasks-edit" title="Edit task" href="#"></a>
</span>
</li>
<li
class="task-list-item plugin-tasks-list-item"
data-task-priority="normal"
data-task=""
data-line="2"
data-task-status-name="Todo"
data-task-status-type="TODO">
<input class="task-list-item-checkbox" type="checkbox" title="Right-click for options" data-line="2" />
<span class="tasks-list-text">
<span class="task-description"><span>grandchild 1</span></span>
</span>
<span class="task-extras">
<span class="tasks-backlink">
(
<a rel="noopener" target="_blank" class="internal-link">inheritance_rendering_sample</a>
)
</span>
<a class="tasks-edit" title="Edit task" href="#"></a>
</span>
</li>
<li
class="task-list-item plugin-tasks-list-item"
data-task-priority="normal"
data-task=""
data-line="3"
data-task-status-name="Todo"
data-task-status-type="TODO">
<input class="task-list-item-checkbox" type="checkbox" title="Right-click for options" data-line="3" />
<span class="tasks-list-text">
<span class="task-description"><span>child 2</span></span>
</span>
<span class="task-extras">
<span class="tasks-backlink">
(
<a rel="noopener" target="_blank" class="internal-link">inheritance_rendering_sample</a>
)
</span>
<a class="tasks-edit" title="Edit task" href="#"></a>
</span>
</li>
<li
class="task-list-item plugin-tasks-list-item"
data-task-priority="normal"
data-task=""
data-line="4"
data-task-status-name="Todo"
data-task-status-type="TODO">
<input class="task-list-item-checkbox" type="checkbox" title="Right-click for options" data-line="4" />
<span class="tasks-list-text">
<span class="task-description"><span>grand grand child</span></span>
</span>
<span class="task-extras">
<span class="tasks-backlink">
(
<a rel="noopener" target="_blank" class="internal-link">inheritance_rendering_sample</a>
)
</span>
<a class="tasks-edit" title="Edit task" href="#"></a>
</span>
</li>
<li
class="task-list-item plugin-tasks-list-item"
data-task-priority="normal"
data-task=""
data-line="5"
data-task-status-name="Todo"
data-task-status-type="TODO">
<input class="task-list-item-checkbox" type="checkbox" title="Right-click for options" data-line="5" />
<span class="tasks-list-text">
<span class="task-description"><span>parent 2</span></span>
</span>
<span class="task-extras">
<span class="tasks-backlink">
(
<a rel="noopener" target="_blank" class="internal-link">inheritance_rendering_sample</a>
)
</span>
<a class="tasks-edit" title="Edit task" href="#"></a>
</span>
</li>
</ul>
<div class="task-count">6 tasks</div>
</div>
Loading

0 comments on commit 40466ce

Please sign in to comment.