From 3f876b3ea8247adaac9dd4a944e1d1b7af83bd4c Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Fri, 4 Oct 2024 20:23:36 +0600 Subject: [PATCH 01/10] test: - show current rendering of nested task lists --- .../Test Data/inheritance_rendering_sample.md | 9 + tests/Obsidian/AllCacheSampleData.ts | 2 + .../inheritance_rendering_sample.ts | 178 ++++++++++++++++++ ...rer_tests_parent-child_items.approved.html | 125 ++++++++++++ tests/Renderer/QueryResultsRenderer.test.ts | 26 +++ 5 files changed, 340 insertions(+) create mode 100644 resources/sample_vaults/Tasks-Demo/Test Data/inheritance_rendering_sample.md create mode 100644 tests/Obsidian/__test_data__/inheritance_rendering_sample.ts create mode 100644 tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_parent-child_items.approved.html diff --git a/resources/sample_vaults/Tasks-Demo/Test Data/inheritance_rendering_sample.md b/resources/sample_vaults/Tasks-Demo/Test Data/inheritance_rendering_sample.md new file mode 100644 index 0000000000..6753633e3a --- /dev/null +++ b/resources/sample_vaults/Tasks-Demo/Test Data/inheritance_rendering_sample.md @@ -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 diff --git a/tests/Obsidian/AllCacheSampleData.ts b/tests/Obsidian/AllCacheSampleData.ts index 05c8ddaac3..e91e4d9e77 100644 --- a/tests/Obsidian/AllCacheSampleData.ts +++ b/tests/Obsidian/AllCacheSampleData.ts @@ -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'; @@ -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, diff --git a/tests/Obsidian/__test_data__/inheritance_rendering_sample.ts b/tests/Obsidian/__test_data__/inheritance_rendering_sample.ts new file mode 100644 index 0000000000..d051a35341 --- /dev/null +++ b/tests/Obsidian/__test_data__/inheritance_rendering_sample.ts @@ -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, +}; diff --git a/tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_parent-child_items.approved.html b/tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_parent-child_items.approved.html new file mode 100644 index 0000000000..265f3c2be6 --- /dev/null +++ b/tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_parent-child_items.approved.html @@ -0,0 +1,125 @@ +
+ +
6 tasks
+
diff --git a/tests/Renderer/QueryResultsRenderer.test.ts b/tests/Renderer/QueryResultsRenderer.test.ts index 9865b7db64..3221e4e2a2 100644 --- a/tests/Renderer/QueryResultsRenderer.test.ts +++ b/tests/Renderer/QueryResultsRenderer.test.ts @@ -5,6 +5,8 @@ import moment from 'moment'; import { State } from '../../src/Obsidian/Cache'; import { QueryResultsRenderer } from '../../src/Renderer/QueryResultsRenderer'; import { TasksFile } from '../../src/Scripting/TasksFile'; +import { inheritance_rendering_sample } from '../Obsidian/__test_data__/inheritance_rendering_sample'; +import { readTasksFromSimulatedFile } from '../Obsidian/SimulatedFile'; import { verifyWithFileExtension } from '../TestingTools/ApprovalTestHelpers'; import { prettifyHTML } from '../TestingTools/HTMLHelpers'; import { TaskBuilder } from '../TestingTools/TaskBuilder'; @@ -44,4 +46,28 @@ describe('QueryResultsRenderer tests', () => { const prettyHTML = prettifyHTML(container.outerHTML); verifyWithFileExtension(prettyHTML, 'html'); }); + + it('parent-child items', async () => { + const renderer = new QueryResultsRenderer( + 'block-language-tasks', + '', + new TasksFile('query.md'), + () => Promise.resolve(), + null, + ); + const allTasks = readTasksFromSimulatedFile(inheritance_rendering_sample); + const queryRendererParameters = { + allTasks, + allMarkdownFiles: [], + backlinksClickHandler: () => Promise.resolve(), + backlinksMousedownHandler: () => Promise.resolve(), + editTaskPencilClickHandler: () => Promise.resolve(), + }; + const container = document.createElement('div'); + + await renderer.render(State.Warm, allTasks, container, queryRendererParameters); + + const prettyHTML = prettifyHTML(container.outerHTML); + verifyWithFileExtension(prettyHTML, 'html'); + }); }); From dd80b3a672285b6b8cf26a78af599f67fe3ebd93 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Fri, 4 Oct 2024 20:26:51 +0600 Subject: [PATCH 02/10] test: . reorder code --- tests/Renderer/QueryResultsRenderer.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Renderer/QueryResultsRenderer.test.ts b/tests/Renderer/QueryResultsRenderer.test.ts index 3221e4e2a2..54ee7e8a06 100644 --- a/tests/Renderer/QueryResultsRenderer.test.ts +++ b/tests/Renderer/QueryResultsRenderer.test.ts @@ -24,6 +24,7 @@ afterEach(() => { describe('QueryResultsRenderer tests', () => { it('fully populated task', async () => { + const allTasks = [TaskBuilder.createFullyPopulatedTask()]; const renderer = new QueryResultsRenderer( 'block-language-tasks', '', @@ -31,7 +32,6 @@ describe('QueryResultsRenderer tests', () => { () => Promise.resolve(), null, ); - const allTasks = [TaskBuilder.createFullyPopulatedTask()]; const queryRendererParameters = { allTasks, allMarkdownFiles: [], @@ -48,6 +48,7 @@ describe('QueryResultsRenderer tests', () => { }); it('parent-child items', async () => { + const allTasks = readTasksFromSimulatedFile(inheritance_rendering_sample); const renderer = new QueryResultsRenderer( 'block-language-tasks', '', @@ -55,7 +56,6 @@ describe('QueryResultsRenderer tests', () => { () => Promise.resolve(), null, ); - const allTasks = readTasksFromSimulatedFile(inheritance_rendering_sample); const queryRendererParameters = { allTasks, allMarkdownFiles: [], From 3475b6e3273f82bbbf47068f9a27b1ad82d75181 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Fri, 4 Oct 2024 20:28:41 +0600 Subject: [PATCH 03/10] test: - extract verifyRenderedTasksHTML() and reuse it --- tests/Renderer/QueryResultsRenderer.test.ts | 30 ++++++--------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/tests/Renderer/QueryResultsRenderer.test.ts b/tests/Renderer/QueryResultsRenderer.test.ts index 54ee7e8a06..f8187b60f9 100644 --- a/tests/Renderer/QueryResultsRenderer.test.ts +++ b/tests/Renderer/QueryResultsRenderer.test.ts @@ -2,6 +2,7 @@ * @jest-environment jsdom */ import moment from 'moment'; +import type { Task } from 'Task/Task'; import { State } from '../../src/Obsidian/Cache'; import { QueryResultsRenderer } from '../../src/Renderer/QueryResultsRenderer'; import { TasksFile } from '../../src/Scripting/TasksFile'; @@ -23,8 +24,7 @@ afterEach(() => { }); describe('QueryResultsRenderer tests', () => { - it('fully populated task', async () => { - const allTasks = [TaskBuilder.createFullyPopulatedTask()]; + async function verifyRenderedTasksHTML(allTasks: Task[]) { const renderer = new QueryResultsRenderer( 'block-language-tasks', '', @@ -45,29 +45,15 @@ describe('QueryResultsRenderer tests', () => { const prettyHTML = prettifyHTML(container.outerHTML); verifyWithFileExtension(prettyHTML, 'html'); + } + + it('fully populated task', async () => { + const allTasks = [TaskBuilder.createFullyPopulatedTask()]; + await verifyRenderedTasksHTML(allTasks); }); it('parent-child items', async () => { const allTasks = readTasksFromSimulatedFile(inheritance_rendering_sample); - const renderer = new QueryResultsRenderer( - 'block-language-tasks', - '', - new TasksFile('query.md'), - () => Promise.resolve(), - null, - ); - const queryRendererParameters = { - allTasks, - allMarkdownFiles: [], - backlinksClickHandler: () => Promise.resolve(), - backlinksMousedownHandler: () => Promise.resolve(), - editTaskPencilClickHandler: () => Promise.resolve(), - }; - const container = document.createElement('div'); - - await renderer.render(State.Warm, allTasks, container, queryRendererParameters); - - const prettyHTML = prettifyHTML(container.outerHTML); - verifyWithFileExtension(prettyHTML, 'html'); + await verifyRenderedTasksHTML(allTasks); }); }); From ff0689e29b81bfcb11e0bf31ebd42097f7d508f7 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Sat, 5 Oct 2024 14:20:20 +0600 Subject: [PATCH 04/10] refactor: ! pass default text renderer in QueryResultsRenderer constructor --- src/Renderer/QueryResultsRenderer.ts | 1 + src/Renderer/TaskLineRenderer.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Renderer/QueryResultsRenderer.ts b/src/Renderer/QueryResultsRenderer.ts index 6f541c8bb5..05d709c468 100644 --- a/src/Renderer/QueryResultsRenderer.ts +++ b/src/Renderer/QueryResultsRenderer.ts @@ -204,6 +204,7 @@ export class QueryResultsRenderer { if (groupingAttribute && groupingAttribute.length > 0) taskList.dataset.taskGroupBy = groupingAttribute; const taskLineRenderer = new TaskLineRenderer({ + textRenderer: TaskLineRenderer.obsidianMarkdownRenderer, obsidianComponent: this.obsidianComponent, parentUlElement: taskList, taskLayoutOptions: this.query.taskLayoutOptions, diff --git a/src/Renderer/TaskLineRenderer.ts b/src/Renderer/TaskLineRenderer.ts index 78b34f41f7..a5297f51af 100644 --- a/src/Renderer/TaskLineRenderer.ts +++ b/src/Renderer/TaskLineRenderer.ts @@ -59,7 +59,7 @@ export class TaskLineRenderer { private readonly taskLayoutOptions: TaskLayoutOptions; private readonly queryLayoutOptions: QueryLayoutOptions; - private static async obsidianMarkdownRenderer( + static async obsidianMarkdownRenderer( text: string, element: HTMLSpanElement, path: string, From 90fdeccca6905607552f780dcd60534cf3bacf36 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Sat, 5 Oct 2024 14:21:52 +0600 Subject: [PATCH 05/10] refactor: . add textRenderer field --- src/Renderer/QueryResultsRenderer.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Renderer/QueryResultsRenderer.ts b/src/Renderer/QueryResultsRenderer.ts index 05d709c468..312b18e3a2 100644 --- a/src/Renderer/QueryResultsRenderer.ts +++ b/src/Renderer/QueryResultsRenderer.ts @@ -46,6 +46,7 @@ export class QueryResultsRenderer { public query: IQuery; protected queryType: string; // whilst there is only one query type, there is no point logging this value + private readonly textRenderer = TaskLineRenderer.obsidianMarkdownRenderer; private readonly renderMarkdown; private readonly obsidianComponent: Component | null; @@ -204,7 +205,7 @@ export class QueryResultsRenderer { if (groupingAttribute && groupingAttribute.length > 0) taskList.dataset.taskGroupBy = groupingAttribute; const taskLineRenderer = new TaskLineRenderer({ - textRenderer: TaskLineRenderer.obsidianMarkdownRenderer, + textRenderer: this.textRenderer, obsidianComponent: this.obsidianComponent, parentUlElement: taskList, taskLayoutOptions: this.query.taskLayoutOptions, From 15579d9e61f5f24a97f8829a25f7ee0c183b6e2c Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Sat, 5 Oct 2024 14:32:16 +0600 Subject: [PATCH 06/10] refactor: - make QueryResultsRenderer tests show rendered task description --- src/Renderer/QueryResultsRenderer.ts | 6 ++++-- ...Renderer_tests_fully_populated_task.approved.html | 2 +- ...tsRenderer_tests_parent-child_items.approved.html | 12 ++++++------ tests/Renderer/QueryResultsRenderer.test.ts | 2 ++ tests/Renderer/RenderingTestHelpers.ts | 7 +++++++ tests/Renderer/TaskLineRenderer.test.ts | 11 ++--------- 6 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 tests/Renderer/RenderingTestHelpers.ts diff --git a/src/Renderer/QueryResultsRenderer.ts b/src/Renderer/QueryResultsRenderer.ts index 312b18e3a2..5743c3ba45 100644 --- a/src/Renderer/QueryResultsRenderer.ts +++ b/src/Renderer/QueryResultsRenderer.ts @@ -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; type EditButtonClickHandler = (event: MouseEvent, task: Task, allTasks: Task[]) => void; @@ -46,7 +46,7 @@ export class QueryResultsRenderer { public query: IQuery; protected queryType: string; // whilst there is only one query type, there is no point logging this value - private readonly textRenderer = TaskLineRenderer.obsidianMarkdownRenderer; + private readonly textRenderer; private readonly renderMarkdown; private readonly obsidianComponent: Component | null; @@ -56,11 +56,13 @@ export class QueryResultsRenderer { tasksFile: TasksFile, renderMarkdown: (markdown: string, el: HTMLElement, sourcePath: string, component: Component) => Promise, 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 diff --git a/tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_fully_populated_task.approved.html b/tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_fully_populated_task.approved.html index cf0580980c..8693b924e3 100644 --- a/tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_fully_populated_task.approved.html +++ b/tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_fully_populated_task.approved.html @@ -15,7 +15,7 @@ data-task-status-type="TODO"> - + Do exercises #todo #health 🆔 abcdef ⛔ 123456,abc123 🔼 diff --git a/tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_parent-child_items.approved.html b/tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_parent-child_items.approved.html index 265f3c2be6..78627a4aff 100644 --- a/tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_parent-child_items.approved.html +++ b/tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_parent-child_items.approved.html @@ -9,7 +9,7 @@ data-task-status-type="TODO"> - + parent 1 @@ -29,7 +29,7 @@ data-task-status-type="TODO"> - + child 1 @@ -49,7 +49,7 @@ data-task-status-type="TODO"> - + grandchild 1 @@ -69,7 +69,7 @@ data-task-status-type="TODO"> - + child 2 @@ -89,7 +89,7 @@ data-task-status-type="TODO"> - + grand grand child @@ -109,7 +109,7 @@ data-task-status-type="TODO"> - + parent 2 diff --git a/tests/Renderer/QueryResultsRenderer.test.ts b/tests/Renderer/QueryResultsRenderer.test.ts index f8187b60f9..70eed7204a 100644 --- a/tests/Renderer/QueryResultsRenderer.test.ts +++ b/tests/Renderer/QueryResultsRenderer.test.ts @@ -11,6 +11,7 @@ import { readTasksFromSimulatedFile } from '../Obsidian/SimulatedFile'; import { verifyWithFileExtension } from '../TestingTools/ApprovalTestHelpers'; import { prettifyHTML } from '../TestingTools/HTMLHelpers'; import { TaskBuilder } from '../TestingTools/TaskBuilder'; +import { mockHTMLRenderer } from './RenderingTestHelpers'; window.moment = moment; @@ -31,6 +32,7 @@ describe('QueryResultsRenderer tests', () => { new TasksFile('query.md'), () => Promise.resolve(), null, + mockHTMLRenderer, ); const queryRendererParameters = { allTasks, diff --git a/tests/Renderer/RenderingTestHelpers.ts b/tests/Renderer/RenderingTestHelpers.ts new file mode 100644 index 0000000000..84a08188bd --- /dev/null +++ b/tests/Renderer/RenderingTestHelpers.ts @@ -0,0 +1,7 @@ +export const mockHTMLRenderer = async (text: string, element: HTMLSpanElement, _path: string) => { + // Contrary to the default mockTextRenderer(), + // instead of the rendered HTMLSpanElement.innerText, + // we need the plain HTML here like in TaskLineRenderer.renderComponentText(), + // to ensure that description and tags are retained. + element.innerHTML = text; +}; diff --git a/tests/Renderer/TaskLineRenderer.test.ts b/tests/Renderer/TaskLineRenderer.test.ts index 85824acd05..da1cffd23b 100644 --- a/tests/Renderer/TaskLineRenderer.test.ts +++ b/tests/Renderer/TaskLineRenderer.test.ts @@ -6,9 +6,9 @@ import moment from 'moment'; import { DebugSettings } from '../../src/Config/DebugSettings'; import { GlobalFilter } from '../../src/Config/GlobalFilter'; import { resetSettings, updateSettings } from '../../src/Config/Settings'; +import { DateParser } from '../../src/DateTime/DateParser'; import { QueryLayoutOptions } from '../../src/Layout/QueryLayoutOptions'; import { TaskLayoutComponent, TaskLayoutOptions, taskLayoutComponents } from '../../src/Layout/TaskLayoutOptions'; -import { DateParser } from '../../src/DateTime/DateParser'; import type { TextRenderer } from '../../src/Renderer/TaskLineRenderer'; import { TaskLineRenderer } from '../../src/Renderer/TaskLineRenderer'; import type { Task } from '../../src/Task/Task'; @@ -17,6 +17,7 @@ import { verifyWithFileExtension } from '../TestingTools/ApprovalTestHelpers'; import { prettifyHTML } from '../TestingTools/HTMLHelpers'; import { TaskBuilder } from '../TestingTools/TaskBuilder'; import { fromLine } from '../TestingTools/TestHelpers'; +import { mockHTMLRenderer } from './RenderingTestHelpers'; jest.mock('obsidian'); window.moment = moment; @@ -52,14 +53,6 @@ const mockTextRenderer = async (text: string, element: HTMLSpanElement, _path: s element.innerText = text; }; -const mockHTMLRenderer = async (text: string, element: HTMLSpanElement, _path: string) => { - // Contrary to the default mockTextRenderer(), - // instead of the rendered HTMLSpanElement.innerText, - // we need the plain HTML here like in TaskLineRenderer.renderComponentText(), - // to ensure that description and tags are retained. - element.innerHTML = text; -}; - function getTextSpan(listItem: HTMLElement) { return listItem.children[1] as HTMLSpanElement; } From 81472a1ef212887973de0f352fb749ef0c0f6332 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Sat, 5 Oct 2024 14:37:12 +0600 Subject: [PATCH 07/10] test: . restore imports --- tests/Renderer/TaskLineRenderer.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Renderer/TaskLineRenderer.test.ts b/tests/Renderer/TaskLineRenderer.test.ts index da1cffd23b..c204cd9811 100644 --- a/tests/Renderer/TaskLineRenderer.test.ts +++ b/tests/Renderer/TaskLineRenderer.test.ts @@ -6,9 +6,9 @@ import moment from 'moment'; import { DebugSettings } from '../../src/Config/DebugSettings'; import { GlobalFilter } from '../../src/Config/GlobalFilter'; import { resetSettings, updateSettings } from '../../src/Config/Settings'; -import { DateParser } from '../../src/DateTime/DateParser'; import { QueryLayoutOptions } from '../../src/Layout/QueryLayoutOptions'; import { TaskLayoutComponent, TaskLayoutOptions, taskLayoutComponents } from '../../src/Layout/TaskLayoutOptions'; +import { DateParser } from '../../src/DateTime/DateParser'; import type { TextRenderer } from '../../src/Renderer/TaskLineRenderer'; import { TaskLineRenderer } from '../../src/Renderer/TaskLineRenderer'; import type { Task } from '../../src/Task/Task'; From bf874be6b5b1ab2dc7bcdecd35d0c3a82294e454 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Sat, 5 Oct 2024 14:40:13 +0600 Subject: [PATCH 08/10] test: . move mockTextRenderer to RenderingTestHelpers.ts --- tests/Renderer/RenderingTestHelpers.ts | 4 ++++ tests/Renderer/TaskLineRenderer.test.ts | 6 +----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Renderer/RenderingTestHelpers.ts b/tests/Renderer/RenderingTestHelpers.ts index 84a08188bd..25d6df40cd 100644 --- a/tests/Renderer/RenderingTestHelpers.ts +++ b/tests/Renderer/RenderingTestHelpers.ts @@ -5,3 +5,7 @@ export const mockHTMLRenderer = async (text: string, element: HTMLSpanElement, _ // to ensure that description and tags are retained. element.innerHTML = text; }; + +export const mockTextRenderer = async (text: string, element: HTMLSpanElement, _path: string) => { + element.innerText = text; +}; diff --git a/tests/Renderer/TaskLineRenderer.test.ts b/tests/Renderer/TaskLineRenderer.test.ts index c204cd9811..acbdaf2929 100644 --- a/tests/Renderer/TaskLineRenderer.test.ts +++ b/tests/Renderer/TaskLineRenderer.test.ts @@ -17,7 +17,7 @@ import { verifyWithFileExtension } from '../TestingTools/ApprovalTestHelpers'; import { prettifyHTML } from '../TestingTools/HTMLHelpers'; import { TaskBuilder } from '../TestingTools/TaskBuilder'; import { fromLine } from '../TestingTools/TestHelpers'; -import { mockHTMLRenderer } from './RenderingTestHelpers'; +import { mockHTMLRenderer, mockTextRenderer } from './RenderingTestHelpers'; jest.mock('obsidian'); window.moment = moment; @@ -49,10 +49,6 @@ async function renderListItem( return await taskLineRenderer.renderTaskLine(task, 0); } -const mockTextRenderer = async (text: string, element: HTMLSpanElement, _path: string) => { - element.innerText = text; -}; - function getTextSpan(listItem: HTMLElement) { return listItem.children[1] as HTMLSpanElement; } From d822195e794cce6693a4733928c7232529b2c54e Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Sat, 5 Oct 2024 14:40:50 +0600 Subject: [PATCH 09/10] test: . make obsidianMarkdownRenderer() public --- src/Renderer/TaskLineRenderer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Renderer/TaskLineRenderer.ts b/src/Renderer/TaskLineRenderer.ts index a5297f51af..c0854f7050 100644 --- a/src/Renderer/TaskLineRenderer.ts +++ b/src/Renderer/TaskLineRenderer.ts @@ -59,7 +59,7 @@ export class TaskLineRenderer { private readonly taskLayoutOptions: TaskLayoutOptions; private readonly queryLayoutOptions: QueryLayoutOptions; - static async obsidianMarkdownRenderer( + public static async obsidianMarkdownRenderer( text: string, element: HTMLSpanElement, path: string, From b0c567f227f0cdbd8c1fe9bc576677e60898a267 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Sat, 5 Oct 2024 14:45:46 +0600 Subject: [PATCH 10/10] refactor: . add comments --- src/Renderer/QueryResultsRenderer.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Renderer/QueryResultsRenderer.ts b/src/Renderer/QueryResultsRenderer.ts index 5743c3ba45..338e4f33a0 100644 --- a/src/Renderer/QueryResultsRenderer.ts +++ b/src/Renderer/QueryResultsRenderer.ts @@ -46,7 +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;