From e95aa63a4880cd2d0f02b807592ea7d3ede5eb7c Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Thu, 11 Jul 2024 15:28:51 +0600 Subject: [PATCH 01/13] test: ! capture getAllTags() & parseFrontMatterTags() output --- .../convert_test_data_markdown_to_js.js | 4 +- tests/Obsidian/__test_data__/blockquote.ts | 2 + tests/Obsidian/__test_data__/callout.ts | 2 + .../Obsidian/__test_data__/callout_custom.ts | 2 + .../__test_data__/callout_labelled.ts | 2 + .../callouts_nested_issue_2890_labelled.ts | 2 + .../callouts_nested_issue_2890_unlabelled.ts | 2 + .../__test_data__/comments_html_style.ts | 2 + .../__test_data__/comments_markdown_style.ts | 2 + tests/Obsidian/__test_data__/empty_yaml.ts | 12 +++--- .../Obsidian/__test_data__/example_kanban.ts | 14 ++++--- .../inheritance_1parent1child.ts | 2 + ...ance_1parent1child1newroot_after_header.ts | 2 + ...tance_1parent1child1sibling_emptystring.ts | 2 + .../inheritance_1parent2children.ts | 2 + ...inheritance_1parent2children1grandchild.ts | 26 ++++++------ .../inheritance_1parent2children1sibling.ts | 2 + ...eritance_1parent2children2grandchildren.ts | 2 + ..._1parent2children2grandchildren1sibling.ts | 2 + ...randchildren1sibling_start_with_heading.ts | 42 ++++++++++--------- .../__test_data__/inheritance_2siblings.ts | 2 + .../inheritance_listitem_task.ts | 2 + .../inheritance_listitem_task_siblings.ts | 2 + .../inheritance_task_2listitem_3task.ts | 2 + .../inheritance_task_listitem.ts | 8 ++-- ...tance_task_listitem_mixed_grandchildren.ts | 16 +++---- .../inheritance_task_listitem_task.ts | 12 +++--- .../inheritance_task_mixed_children.ts | 2 + .../__test_data__/link_in_file_body.ts | 18 ++++---- ...k_in_file_body_with_custom_display_text.ts | 18 ++++---- .../Obsidian/__test_data__/link_in_heading.ts | 22 +++++----- tests/Obsidian/__test_data__/link_in_yaml.ts | 28 +++++++------ .../Obsidian/__test_data__/link_is_broken.ts | 18 ++++---- tests/Obsidian/__test_data__/list_statuses.ts | 2 + tests/Obsidian/__test_data__/list_styles.ts | 2 + .../multi_line_task_and_list_item.ts | 2 + .../__test_data__/multiple_headings.ts | 20 +++++---- tests/Obsidian/__test_data__/no_heading.ts | 8 ++-- tests/Obsidian/__test_data__/no_yaml.ts | 12 +++--- tests/Obsidian/__test_data__/one_task.ts | 8 ++-- tests/Obsidian/__test_data__/yaml_1_alias.ts | 14 ++++--- .../Obsidian/__test_data__/yaml_2_aliases.ts | 14 ++++--- .../__test_data__/yaml_complex_example.ts | 2 + .../yaml_complex_example_standardised.ts | 2 + .../yaml_custom_number_property.ts | 2 + ...eld_added_by_obsidian_but_not_populated.ts | 14 ++++--- ..._had_value_then_was_emptied_by_obsidian.ts | 14 ++++--- .../yaml_tags_has_multiple_values.ts | 14 ++++--- .../__test_data__/yaml_tags_is_empty.ts | 14 ++++--- .../__test_data__/yaml_tags_is_empty_list.ts | 14 ++++--- .../yaml_tags_with_one_value_on_new_line.ts | 14 ++++--- ...yaml_tags_with_one_value_on_single_line.ts | 14 ++++--- .../yaml_tags_with_two_values_on_one_line.ts | 2 + .../yaml_tags_with_two_values_on_two_lines.ts | 2 + 54 files changed, 288 insertions(+), 180 deletions(-) diff --git a/resources/sample_vaults/Tasks-Demo/_meta/templater_scripts/convert_test_data_markdown_to_js.js b/resources/sample_vaults/Tasks-Demo/_meta/templater_scripts/convert_test_data_markdown_to_js.js index 09cdf30efa..4dd1148c3a 100644 --- a/resources/sample_vaults/Tasks-Demo/_meta/templater_scripts/convert_test_data_markdown_to_js.js +++ b/resources/sample_vaults/Tasks-Demo/_meta/templater_scripts/convert_test_data_markdown_to_js.js @@ -7,7 +7,9 @@ async function convertMarkdownFileToTestFunction(filePath, tp) { const fileContents = await app.vault.read(tFile); const cachedMetadata = app.metadataCache.getFileCache(tFile); const obsidianApiVersion = tp.obsidian.apiVersion; - const data = { filePath, fileContents, cachedMetadata, obsidianApiVersion }; + const getAllTags = tp.obsidian.getAllTags(cachedMetadata); + const parseFrontMatterTags = tp.obsidian.parseFrontMatterTags(cachedMetadata.frontmatter); + const data = { filePath, fileContents, cachedMetadata, obsidianApiVersion, getAllTags, parseFrontMatterTags }; const filename = filePath.split('/')[1].replace('.md', ''); if (filename.includes(' ')) { diff --git a/tests/Obsidian/__test_data__/blockquote.ts b/tests/Obsidian/__test_data__/blockquote.ts index baeeed87ea..f85da8f29d 100644 --- a/tests/Obsidian/__test_data__/blockquote.ts +++ b/tests/Obsidian/__test_data__/blockquote.ts @@ -124,4 +124,6 @@ export const blockquote = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/callout.ts b/tests/Obsidian/__test_data__/callout.ts index f17943ccdf..f53efc45a4 100644 --- a/tests/Obsidian/__test_data__/callout.ts +++ b/tests/Obsidian/__test_data__/callout.ts @@ -145,4 +145,6 @@ export const callout = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/callout_custom.ts b/tests/Obsidian/__test_data__/callout_custom.ts index 1fa21c47c9..7c6c8553df 100644 --- a/tests/Obsidian/__test_data__/callout_custom.ts +++ b/tests/Obsidian/__test_data__/callout_custom.ts @@ -145,4 +145,6 @@ export const callout_custom = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/callout_labelled.ts b/tests/Obsidian/__test_data__/callout_labelled.ts index c9f9515078..2dd298e588 100644 --- a/tests/Obsidian/__test_data__/callout_labelled.ts +++ b/tests/Obsidian/__test_data__/callout_labelled.ts @@ -145,4 +145,6 @@ export const callout_labelled = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/callouts_nested_issue_2890_labelled.ts b/tests/Obsidian/__test_data__/callouts_nested_issue_2890_labelled.ts index db8fa973dc..70d22d4fe7 100644 --- a/tests/Obsidian/__test_data__/callouts_nested_issue_2890_labelled.ts +++ b/tests/Obsidian/__test_data__/callouts_nested_issue_2890_labelled.ts @@ -177,4 +177,6 @@ export const callouts_nested_issue_2890_labelled = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task', '#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/callouts_nested_issue_2890_unlabelled.ts b/tests/Obsidian/__test_data__/callouts_nested_issue_2890_unlabelled.ts index ea4fb45686..16d07f9f18 100644 --- a/tests/Obsidian/__test_data__/callouts_nested_issue_2890_unlabelled.ts +++ b/tests/Obsidian/__test_data__/callouts_nested_issue_2890_unlabelled.ts @@ -177,4 +177,6 @@ export const callouts_nested_issue_2890_unlabelled = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task', '#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/comments_html_style.ts b/tests/Obsidian/__test_data__/comments_html_style.ts index 332ab283a2..e894a5747f 100644 --- a/tests/Obsidian/__test_data__/comments_html_style.ts +++ b/tests/Obsidian/__test_data__/comments_html_style.ts @@ -159,4 +159,6 @@ export const comments_html_style = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/comments_markdown_style.ts b/tests/Obsidian/__test_data__/comments_markdown_style.ts index 908c8f070d..126479b5c1 100644 --- a/tests/Obsidian/__test_data__/comments_markdown_style.ts +++ b/tests/Obsidian/__test_data__/comments_markdown_style.ts @@ -208,4 +208,6 @@ export const comments_markdown_style = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task', '#i-am-parsed-by-obsidian', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/empty_yaml.ts b/tests/Obsidian/__test_data__/empty_yaml.ts index 946aab5bfa..3511469e4a 100644 --- a/tests/Obsidian/__test_data__/empty_yaml.ts +++ b/tests/Obsidian/__test_data__/empty_yaml.ts @@ -4,7 +4,6 @@ export const empty_yaml = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 5, @@ -17,12 +16,11 @@ export const empty_yaml = { offset: 34, }, }, + tag: '#task', }, ], headings: [ { - heading: 'empty_yaml', - level: 1, position: { start: { line: 3, @@ -35,6 +33,8 @@ export const empty_yaml = { offset: 21, }, }, + heading: 'empty_yaml', + level: 1, }, ], sections: [ @@ -86,8 +86,6 @@ export const empty_yaml = { ], listItems: [ { - parent: -5, - task: ' ', position: { start: { line: 5, @@ -100,8 +98,12 @@ export const empty_yaml = { offset: 55, }, }, + parent: -5, + task: ' ', }, ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/example_kanban.ts b/tests/Obsidian/__test_data__/example_kanban.ts index 8e6bd531c4..2801f7edb5 100644 --- a/tests/Obsidian/__test_data__/example_kanban.ts +++ b/tests/Obsidian/__test_data__/example_kanban.ts @@ -20,7 +20,6 @@ export const example_kanban = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 8, @@ -33,12 +32,11 @@ export const example_kanban = { offset: 55, }, }, + tag: '#task', }, ], headings: [ { - heading: 'Backlog', - level: 2, position: { start: { line: 6, @@ -51,6 +49,8 @@ export const example_kanban = { offset: 42, }, }, + heading: 'Backlog', + level: 2, }, ], sections: [ @@ -117,8 +117,6 @@ export const example_kanban = { ], listItems: [ { - parent: -8, - task: ' ', position: { start: { line: 8, @@ -131,12 +129,13 @@ export const example_kanban = { offset: 80, }, }, + parent: -8, + task: ' ', }, ], frontmatter: { 'kanban-plugin': 'basic', }, - frontmatterLinks: [], frontmatterPosition: { start: { line: 0, @@ -149,6 +148,9 @@ export const example_kanban = { offset: 30, }, }, + frontmatterLinks: [], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_1parent1child.ts b/tests/Obsidian/__test_data__/inheritance_1parent1child.ts index 956e57991f..3977660178 100644 --- a/tests/Obsidian/__test_data__/inheritance_1parent1child.ts +++ b/tests/Obsidian/__test_data__/inheritance_1parent1child.ts @@ -87,4 +87,6 @@ export const inheritance_1parent1child = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_1parent1child1newroot_after_header.ts b/tests/Obsidian/__test_data__/inheritance_1parent1child1newroot_after_header.ts index 54207aaba1..206d40d296 100644 --- a/tests/Obsidian/__test_data__/inheritance_1parent1child1newroot_after_header.ts +++ b/tests/Obsidian/__test_data__/inheritance_1parent1child1newroot_after_header.ts @@ -205,4 +205,6 @@ export const inheritance_1parent1child1newroot_after_header = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_1parent1child1sibling_emptystring.ts b/tests/Obsidian/__test_data__/inheritance_1parent1child1sibling_emptystring.ts index cb3c0158c5..d97ced692f 100644 --- a/tests/Obsidian/__test_data__/inheritance_1parent1child1sibling_emptystring.ts +++ b/tests/Obsidian/__test_data__/inheritance_1parent1child1sibling_emptystring.ts @@ -118,4 +118,6 @@ export const inheritance_1parent1child1sibling_emptystring = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_1parent2children.ts b/tests/Obsidian/__test_data__/inheritance_1parent2children.ts index 03eb099cc4..ac47625222 100644 --- a/tests/Obsidian/__test_data__/inheritance_1parent2children.ts +++ b/tests/Obsidian/__test_data__/inheritance_1parent2children.ts @@ -118,4 +118,6 @@ export const inheritance_1parent2children = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_1parent2children1grandchild.ts b/tests/Obsidian/__test_data__/inheritance_1parent2children1grandchild.ts index 6aad54f126..b5211f43fa 100644 --- a/tests/Obsidian/__test_data__/inheritance_1parent2children1grandchild.ts +++ b/tests/Obsidian/__test_data__/inheritance_1parent2children1grandchild.ts @@ -8,7 +8,6 @@ export const inheritance_1parent2children1grandchild = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 0, @@ -21,9 +20,9 @@ export const inheritance_1parent2children1grandchild = { offset: 11, }, }, + tag: '#task', }, { - tag: '#task', position: { start: { line: 1, @@ -36,9 +35,9 @@ export const inheritance_1parent2children1grandchild = { offset: 39, }, }, + tag: '#task', }, { - tag: '#task', position: { start: { line: 2, @@ -51,9 +50,9 @@ export const inheritance_1parent2children1grandchild = { offset: 68, }, }, + tag: '#task', }, { - tag: '#task', position: { start: { line: 3, @@ -66,6 +65,7 @@ export const inheritance_1parent2children1grandchild = { offset: 101, }, }, + tag: '#task', }, ], sections: [ @@ -87,8 +87,6 @@ export const inheritance_1parent2children1grandchild = { ], listItems: [ { - parent: -1, - task: ' ', position: { start: { line: 0, @@ -101,10 +99,10 @@ export const inheritance_1parent2children1grandchild = { offset: 23, }, }, + parent: -1, + task: ' ', }, { - parent: 0, - task: ' ', position: { start: { line: 1, @@ -117,10 +115,10 @@ export const inheritance_1parent2children1grandchild = { offset: 52, }, }, - }, - { parent: 0, task: ' ', + }, + { position: { start: { line: 2, @@ -133,10 +131,10 @@ export const inheritance_1parent2children1grandchild = { offset: 81, }, }, + parent: 0, + task: ' ', }, { - parent: 2, - task: ' ', position: { start: { line: 3, @@ -149,8 +147,12 @@ export const inheritance_1parent2children1grandchild = { offset: 114, }, }, + parent: 2, + task: ' ', }, ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task', '#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_1parent2children1sibling.ts b/tests/Obsidian/__test_data__/inheritance_1parent2children1sibling.ts index 29706c4380..28f416f632 100644 --- a/tests/Obsidian/__test_data__/inheritance_1parent2children1sibling.ts +++ b/tests/Obsidian/__test_data__/inheritance_1parent2children1sibling.ts @@ -150,4 +150,6 @@ export const inheritance_1parent2children1sibling = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task', '#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_1parent2children2grandchildren.ts b/tests/Obsidian/__test_data__/inheritance_1parent2children2grandchildren.ts index d4c7207e73..dbfad8a5fc 100644 --- a/tests/Obsidian/__test_data__/inheritance_1parent2children2grandchildren.ts +++ b/tests/Obsidian/__test_data__/inheritance_1parent2children2grandchildren.ts @@ -185,4 +185,6 @@ export const inheritance_1parent2children2grandchildren = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task', '#task', '#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_1parent2children2grandchildren1sibling.ts b/tests/Obsidian/__test_data__/inheritance_1parent2children2grandchildren1sibling.ts index 801257a5cc..b4b75e35b0 100644 --- a/tests/Obsidian/__test_data__/inheritance_1parent2children2grandchildren1sibling.ts +++ b/tests/Obsidian/__test_data__/inheritance_1parent2children2grandchildren1sibling.ts @@ -217,4 +217,6 @@ export const inheritance_1parent2children2grandchildren1sibling = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task', '#task', '#task', '#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_1parent2children2grandchildren1sibling_start_with_heading.ts b/tests/Obsidian/__test_data__/inheritance_1parent2children2grandchildren1sibling_start_with_heading.ts index 292e378e11..c00200cd47 100644 --- a/tests/Obsidian/__test_data__/inheritance_1parent2children2grandchildren1sibling_start_with_heading.ts +++ b/tests/Obsidian/__test_data__/inheritance_1parent2children2grandchildren1sibling_start_with_heading.ts @@ -12,7 +12,6 @@ export const inheritance_1parent2children2grandchildren1sibling_start_with_headi cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 2, @@ -25,9 +24,9 @@ export const inheritance_1parent2children2grandchildren1sibling_start_with_headi offset: 27, }, }, + tag: '#task', }, { - tag: '#task', position: { start: { line: 3, @@ -40,9 +39,9 @@ export const inheritance_1parent2children2grandchildren1sibling_start_with_headi offset: 55, }, }, + tag: '#task', }, { - tag: '#task', position: { start: { line: 4, @@ -55,9 +54,9 @@ export const inheritance_1parent2children2grandchildren1sibling_start_with_headi offset: 88, }, }, + tag: '#task', }, { - tag: '#task', position: { start: { line: 5, @@ -70,9 +69,9 @@ export const inheritance_1parent2children2grandchildren1sibling_start_with_headi offset: 117, }, }, + tag: '#task', }, { - tag: '#task', position: { start: { line: 6, @@ -85,9 +84,9 @@ export const inheritance_1parent2children2grandchildren1sibling_start_with_headi offset: 150, }, }, + tag: '#task', }, { - tag: '#task', position: { start: { line: 7, @@ -100,12 +99,11 @@ export const inheritance_1parent2children2grandchildren1sibling_start_with_headi offset: 175, }, }, + tag: '#task', }, ], headings: [ { - heading: 'Test heading', - level: 1, position: { start: { line: 0, @@ -118,6 +116,8 @@ export const inheritance_1parent2children2grandchildren1sibling_start_with_headi offset: 14, }, }, + heading: 'Test heading', + level: 1, }, ], sections: [ @@ -154,8 +154,6 @@ export const inheritance_1parent2children2grandchildren1sibling_start_with_headi ], listItems: [ { - parent: -2, - task: ' ', position: { start: { line: 2, @@ -168,10 +166,10 @@ export const inheritance_1parent2children2grandchildren1sibling_start_with_headi offset: 39, }, }, + parent: -2, + task: ' ', }, { - parent: 2, - task: ' ', position: { start: { line: 3, @@ -184,10 +182,10 @@ export const inheritance_1parent2children2grandchildren1sibling_start_with_headi offset: 68, }, }, + parent: 2, + task: ' ', }, { - parent: 3, - task: ' ', position: { start: { line: 4, @@ -200,10 +198,10 @@ export const inheritance_1parent2children2grandchildren1sibling_start_with_headi offset: 101, }, }, + parent: 3, + task: ' ', }, { - parent: 2, - task: ' ', position: { start: { line: 5, @@ -216,10 +214,10 @@ export const inheritance_1parent2children2grandchildren1sibling_start_with_headi offset: 130, }, }, + parent: 2, + task: ' ', }, { - parent: 5, - task: ' ', position: { start: { line: 6, @@ -232,10 +230,10 @@ export const inheritance_1parent2children2grandchildren1sibling_start_with_headi offset: 163, }, }, + parent: 5, + task: ' ', }, { - parent: -2, - task: ' ', position: { start: { line: 7, @@ -248,8 +246,12 @@ export const inheritance_1parent2children2grandchildren1sibling_start_with_headi offset: 183, }, }, + parent: -2, + task: ' ', }, ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task', '#task', '#task', '#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_2siblings.ts b/tests/Obsidian/__test_data__/inheritance_2siblings.ts index 578638aceb..00edb65504 100644 --- a/tests/Obsidian/__test_data__/inheritance_2siblings.ts +++ b/tests/Obsidian/__test_data__/inheritance_2siblings.ts @@ -87,4 +87,6 @@ export const inheritance_2siblings = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_listitem_task.ts b/tests/Obsidian/__test_data__/inheritance_listitem_task.ts index f512f0d7d0..9d2e775433 100644 --- a/tests/Obsidian/__test_data__/inheritance_listitem_task.ts +++ b/tests/Obsidian/__test_data__/inheritance_listitem_task.ts @@ -54,4 +54,6 @@ export const inheritance_listitem_task = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: [], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_listitem_task_siblings.ts b/tests/Obsidian/__test_data__/inheritance_listitem_task_siblings.ts index 6aea336108..9a7541bcb6 100644 --- a/tests/Obsidian/__test_data__/inheritance_listitem_task_siblings.ts +++ b/tests/Obsidian/__test_data__/inheritance_listitem_task_siblings.ts @@ -54,4 +54,6 @@ export const inheritance_listitem_task_siblings = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: [], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_task_2listitem_3task.ts b/tests/Obsidian/__test_data__/inheritance_task_2listitem_3task.ts index ed3ba8bd36..1b5ac5e96b 100644 --- a/tests/Obsidian/__test_data__/inheritance_task_2listitem_3task.ts +++ b/tests/Obsidian/__test_data__/inheritance_task_2listitem_3task.ts @@ -123,4 +123,6 @@ export const inheritance_task_2listitem_3task = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: [], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_task_listitem.ts b/tests/Obsidian/__test_data__/inheritance_task_listitem.ts index 2243e4bb83..240174b6dd 100644 --- a/tests/Obsidian/__test_data__/inheritance_task_listitem.ts +++ b/tests/Obsidian/__test_data__/inheritance_task_listitem.ts @@ -21,8 +21,6 @@ export const inheritance_task_listitem = { ], listItems: [ { - parent: -1, - task: ' ', position: { start: { line: 0, @@ -35,9 +33,10 @@ export const inheritance_task_listitem = { offset: 17, }, }, + parent: -1, + task: ' ', }, { - parent: 0, position: { start: { line: 1, @@ -50,8 +49,11 @@ export const inheritance_task_listitem = { offset: 39, }, }, + parent: 0, }, ], }, obsidianApiVersion: '1.6.5', + getAllTags: [], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_task_listitem_mixed_grandchildren.ts b/tests/Obsidian/__test_data__/inheritance_task_listitem_mixed_grandchildren.ts index 562fbdaaec..6b5915ce06 100644 --- a/tests/Obsidian/__test_data__/inheritance_task_listitem_mixed_grandchildren.ts +++ b/tests/Obsidian/__test_data__/inheritance_task_listitem_mixed_grandchildren.ts @@ -26,8 +26,6 @@ export const inheritance_task_listitem_mixed_grandchildren = { ], listItems: [ { - parent: -1, - task: ' ', position: { start: { line: 0, @@ -40,9 +38,10 @@ export const inheritance_task_listitem_mixed_grandchildren = { offset: 17, }, }, + parent: -1, + task: ' ', }, { - parent: 0, position: { start: { line: 1, @@ -55,9 +54,9 @@ export const inheritance_task_listitem_mixed_grandchildren = { offset: 39, }, }, + parent: 0, }, { - parent: 1, position: { start: { line: 2, @@ -70,10 +69,9 @@ export const inheritance_task_listitem_mixed_grandchildren = { offset: 72, }, }, + parent: 1, }, { - parent: 1, - task: ' ', position: { start: { line: 3, @@ -86,9 +84,10 @@ export const inheritance_task_listitem_mixed_grandchildren = { offset: 102, }, }, + parent: 1, + task: ' ', }, { - parent: 1, position: { start: { line: 4, @@ -101,8 +100,11 @@ export const inheritance_task_listitem_mixed_grandchildren = { offset: 135, }, }, + parent: 1, }, ], }, obsidianApiVersion: '1.6.5', + getAllTags: [], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_task_listitem_task.ts b/tests/Obsidian/__test_data__/inheritance_task_listitem_task.ts index b932becc7b..fc254f838f 100644 --- a/tests/Obsidian/__test_data__/inheritance_task_listitem_task.ts +++ b/tests/Obsidian/__test_data__/inheritance_task_listitem_task.ts @@ -21,8 +21,6 @@ export const inheritance_task_listitem_task = { ], listItems: [ { - parent: -1, - task: ' ', position: { start: { line: 0, @@ -35,9 +33,10 @@ export const inheritance_task_listitem_task = { offset: 17, }, }, + parent: -1, + task: ' ', }, { - parent: 0, position: { start: { line: 1, @@ -50,10 +49,9 @@ export const inheritance_task_listitem_task = { offset: 39, }, }, + parent: 0, }, { - parent: 1, - task: ' ', position: { start: { line: 2, @@ -66,8 +64,12 @@ export const inheritance_task_listitem_task = { offset: 69, }, }, + parent: 1, + task: ' ', }, ], }, obsidianApiVersion: '1.6.5', + getAllTags: [], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/inheritance_task_mixed_children.ts b/tests/Obsidian/__test_data__/inheritance_task_mixed_children.ts index c494ea7dd8..fcd47943b7 100644 --- a/tests/Obsidian/__test_data__/inheritance_task_mixed_children.ts +++ b/tests/Obsidian/__test_data__/inheritance_task_mixed_children.ts @@ -87,4 +87,6 @@ export const inheritance_task_mixed_children = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: [], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/link_in_file_body.ts b/tests/Obsidian/__test_data__/link_in_file_body.ts index 6bd5b370e0..6be9f66b67 100644 --- a/tests/Obsidian/__test_data__/link_in_file_body.ts +++ b/tests/Obsidian/__test_data__/link_in_file_body.ts @@ -9,9 +9,6 @@ export const link_in_file_body = { cachedMetadata: { links: [ { - link: 'yaml_tags_is_empty', - original: '[[yaml_tags_is_empty]]', - displayText: 'yaml_tags_is_empty', position: { start: { line: 2, @@ -24,11 +21,13 @@ export const link_in_file_body = { offset: 53, }, }, + link: 'yaml_tags_is_empty', + original: '[[yaml_tags_is_empty]]', + displayText: 'yaml_tags_is_empty', }, ], tags: [ { - tag: '#task', position: { start: { line: 4, @@ -41,12 +40,11 @@ export const link_in_file_body = { offset: 66, }, }, + tag: '#task', }, ], headings: [ { - heading: 'link_in_file_body', - level: 1, position: { start: { line: 0, @@ -59,6 +57,8 @@ export const link_in_file_body = { offset: 19, }, }, + heading: 'link_in_file_body', + level: 1, }, ], sections: [ @@ -110,8 +110,6 @@ export const link_in_file_body = { ], listItems: [ { - parent: -4, - task: ' ', position: { start: { line: 4, @@ -124,8 +122,12 @@ export const link_in_file_body = { offset: 94, }, }, + parent: -4, + task: ' ', }, ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/link_in_file_body_with_custom_display_text.ts b/tests/Obsidian/__test_data__/link_in_file_body_with_custom_display_text.ts index 784af71ad2..fc65c6d3ae 100644 --- a/tests/Obsidian/__test_data__/link_in_file_body_with_custom_display_text.ts +++ b/tests/Obsidian/__test_data__/link_in_file_body_with_custom_display_text.ts @@ -9,9 +9,6 @@ export const link_in_file_body_with_custom_display_text = { cachedMetadata: { links: [ { - link: 'yaml_tags_is_empty', - original: '[[yaml_tags_is_empty|a file and use custom display text]]', - displayText: 'a file and use custom display text', position: { start: { line: 2, @@ -24,11 +21,13 @@ export const link_in_file_body_with_custom_display_text = { offset: 113, }, }, + link: 'yaml_tags_is_empty', + original: '[[yaml_tags_is_empty|a file and use custom display text]]', + displayText: 'a file and use custom display text', }, ], tags: [ { - tag: '#task', position: { start: { line: 4, @@ -41,12 +40,11 @@ export const link_in_file_body_with_custom_display_text = { offset: 126, }, }, + tag: '#task', }, ], headings: [ { - heading: 'link_in_file_body_with_custom_display_text', - level: 1, position: { start: { line: 0, @@ -59,6 +57,8 @@ export const link_in_file_body_with_custom_display_text = { offset: 44, }, }, + heading: 'link_in_file_body_with_custom_display_text', + level: 1, }, ], sections: [ @@ -110,8 +110,6 @@ export const link_in_file_body_with_custom_display_text = { ], listItems: [ { - parent: -4, - task: ' ', position: { start: { line: 4, @@ -124,8 +122,12 @@ export const link_in_file_body_with_custom_display_text = { offset: 179, }, }, + parent: -4, + task: ' ', }, ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/link_in_heading.ts b/tests/Obsidian/__test_data__/link_in_heading.ts index 35662b17fe..bac06d7d72 100644 --- a/tests/Obsidian/__test_data__/link_in_heading.ts +++ b/tests/Obsidian/__test_data__/link_in_heading.ts @@ -9,9 +9,6 @@ export const link_in_heading = { cachedMetadata: { links: [ { - link: 'multiple_headings', - original: '[[multiple_headings]]', - displayText: 'multiple_headings', position: { start: { line: 2, @@ -24,11 +21,13 @@ export const link_in_heading = { offset: 53, }, }, + link: 'multiple_headings', + original: '[[multiple_headings]]', + displayText: 'multiple_headings', }, ], tags: [ { - tag: '#task', position: { start: { line: 4, @@ -41,12 +40,11 @@ export const link_in_heading = { offset: 66, }, }, + tag: '#task', }, ], headings: [ { - heading: 'link_in_heading', - level: 1, position: { start: { line: 0, @@ -59,10 +57,10 @@ export const link_in_heading = { offset: 17, }, }, + heading: 'link_in_heading', + level: 1, }, { - heading: 'I link to [[multiple_headings]]', - level: 2, position: { start: { line: 2, @@ -75,6 +73,8 @@ export const link_in_heading = { offset: 53, }, }, + heading: 'I link to [[multiple_headings]]', + level: 2, }, ], sections: [ @@ -126,8 +126,6 @@ export const link_in_heading = { ], listItems: [ { - parent: -4, - task: ' ', position: { start: { line: 4, @@ -140,8 +138,12 @@ export const link_in_heading = { offset: 92, }, }, + parent: -4, + task: ' ', }, ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/link_in_yaml.ts b/tests/Obsidian/__test_data__/link_in_yaml.ts index 300ac7da33..3ad098de94 100644 --- a/tests/Obsidian/__test_data__/link_in_yaml.ts +++ b/tests/Obsidian/__test_data__/link_in_yaml.ts @@ -11,7 +11,6 @@ export const link_in_yaml = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 6, @@ -24,12 +23,11 @@ export const link_in_yaml = { offset: 72, }, }, + tag: '#task', }, ], headings: [ { - heading: 'link_in_yaml', - level: 1, position: { start: { line: 4, @@ -42,6 +40,8 @@ export const link_in_yaml = { offset: 59, }, }, + heading: 'link_in_yaml', + level: 1, }, ], sections: [ @@ -93,8 +93,6 @@ export const link_in_yaml = { ], listItems: [ { - parent: -6, - task: ' ', position: { start: { line: 6, @@ -107,19 +105,13 @@ export const link_in_yaml = { offset: 95, }, }, + parent: -6, + task: ' ', }, ], frontmatter: { 'test-link': '[[yaml_tags_is_empty]]', }, - frontmatterLinks: [ - { - key: 'test-link', - link: 'yaml_tags_is_empty', - original: '[[yaml_tags_is_empty]]', - displayText: 'yaml_tags_is_empty', - }, - ], frontmatterPosition: { start: { line: 0, @@ -132,6 +124,16 @@ export const link_in_yaml = { offset: 43, }, }, + frontmatterLinks: [ + { + key: 'test-link', + link: 'yaml_tags_is_empty', + original: '[[yaml_tags_is_empty]]', + displayText: 'yaml_tags_is_empty', + }, + ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/link_is_broken.ts b/tests/Obsidian/__test_data__/link_is_broken.ts index 186eba5235..2cc8a3aff6 100644 --- a/tests/Obsidian/__test_data__/link_is_broken.ts +++ b/tests/Obsidian/__test_data__/link_is_broken.ts @@ -5,9 +5,6 @@ export const link_is_broken = { cachedMetadata: { links: [ { - link: 'broken link - do not fix me', - original: '[[broken link - do not fix me]]', - displayText: 'broken link - do not fix me', position: { start: { line: 2, @@ -20,11 +17,13 @@ export const link_is_broken = { offset: 86, }, }, + link: 'broken link - do not fix me', + original: '[[broken link - do not fix me]]', + displayText: 'broken link - do not fix me', }, ], tags: [ { - tag: '#task', position: { start: { line: 2, @@ -37,12 +36,11 @@ export const link_is_broken = { offset: 29, }, }, + tag: '#task', }, ], headings: [ { - heading: 'link_is_broken', - level: 1, position: { start: { line: 0, @@ -55,6 +53,8 @@ export const link_is_broken = { offset: 16, }, }, + heading: 'link_is_broken', + level: 1, }, ], sections: [ @@ -91,8 +91,6 @@ export const link_is_broken = { ], listItems: [ { - parent: -2, - task: ' ', position: { start: { line: 2, @@ -105,8 +103,12 @@ export const link_is_broken = { offset: 86, }, }, + parent: -2, + task: ' ', }, ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/list_statuses.ts b/tests/Obsidian/__test_data__/list_statuses.ts index 29a958d9a1..d06a41465c 100644 --- a/tests/Obsidian/__test_data__/list_statuses.ts +++ b/tests/Obsidian/__test_data__/list_statuses.ts @@ -170,4 +170,6 @@ export const list_statuses = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task', '#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/list_styles.ts b/tests/Obsidian/__test_data__/list_styles.ts index fc59245190..728632151e 100644 --- a/tests/Obsidian/__test_data__/list_styles.ts +++ b/tests/Obsidian/__test_data__/list_styles.ts @@ -329,4 +329,6 @@ export const list_styles = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task', '#task', '#task', '#task', '#task', '#task', '#task', '#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/multi_line_task_and_list_item.ts b/tests/Obsidian/__test_data__/multi_line_task_and_list_item.ts index fed5b7e227..f3919234d8 100644 --- a/tests/Obsidian/__test_data__/multi_line_task_and_list_item.ts +++ b/tests/Obsidian/__test_data__/multi_line_task_and_list_item.ts @@ -130,4 +130,6 @@ export const multi_line_task_and_list_item = { ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/multiple_headings.ts b/tests/Obsidian/__test_data__/multiple_headings.ts index 338b8c78f6..a618858d0b 100644 --- a/tests/Obsidian/__test_data__/multiple_headings.ts +++ b/tests/Obsidian/__test_data__/multiple_headings.ts @@ -11,7 +11,6 @@ export const multiple_headings = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 6, @@ -24,12 +23,11 @@ export const multiple_headings = { offset: 73, }, }, + tag: '#task', }, ], headings: [ { - heading: 'multiple_headings', - level: 1, position: { start: { line: 0, @@ -42,10 +40,10 @@ export const multiple_headings = { offset: 19, }, }, + heading: 'multiple_headings', + level: 1, }, { - heading: 'Level 2 heading', - level: 2, position: { start: { line: 2, @@ -58,10 +56,10 @@ export const multiple_headings = { offset: 39, }, }, + heading: 'Level 2 heading', + level: 2, }, { - heading: 'Level 3 heading', - level: 3, position: { start: { line: 4, @@ -74,6 +72,8 @@ export const multiple_headings = { offset: 60, }, }, + heading: 'Level 3 heading', + level: 3, }, ], sections: [ @@ -140,8 +140,6 @@ export const multiple_headings = { ], listItems: [ { - parent: -6, - task: ' ', position: { start: { line: 6, @@ -154,8 +152,12 @@ export const multiple_headings = { offset: 101, }, }, + parent: -6, + task: ' ', }, ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/no_heading.ts b/tests/Obsidian/__test_data__/no_heading.ts index 056c70017b..e6a3ede087 100644 --- a/tests/Obsidian/__test_data__/no_heading.ts +++ b/tests/Obsidian/__test_data__/no_heading.ts @@ -4,7 +4,6 @@ export const no_heading = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 0, @@ -17,6 +16,7 @@ export const no_heading = { offset: 11, }, }, + tag: '#task', }, ], sections: [ @@ -38,8 +38,6 @@ export const no_heading = { ], listItems: [ { - parent: -1, - task: ' ', position: { start: { line: 0, @@ -52,8 +50,12 @@ export const no_heading = { offset: 32, }, }, + parent: -1, + task: ' ', }, ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/no_yaml.ts b/tests/Obsidian/__test_data__/no_yaml.ts index b99f62be2c..55c73517a4 100644 --- a/tests/Obsidian/__test_data__/no_yaml.ts +++ b/tests/Obsidian/__test_data__/no_yaml.ts @@ -4,7 +4,6 @@ export const no_yaml = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 2, @@ -17,12 +16,11 @@ export const no_yaml = { offset: 22, }, }, + tag: '#task', }, ], headings: [ { - heading: 'no_yaml', - level: 1, position: { start: { line: 0, @@ -35,6 +33,8 @@ export const no_yaml = { offset: 9, }, }, + heading: 'no_yaml', + level: 1, }, ], sections: [ @@ -71,8 +71,6 @@ export const no_yaml = { ], listItems: [ { - parent: -2, - task: ' ', position: { start: { line: 2, @@ -85,8 +83,12 @@ export const no_yaml = { offset: 40, }, }, + parent: -2, + task: ' ', }, ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/one_task.ts b/tests/Obsidian/__test_data__/one_task.ts index af3e8177cd..e6777a9fb5 100644 --- a/tests/Obsidian/__test_data__/one_task.ts +++ b/tests/Obsidian/__test_data__/one_task.ts @@ -4,7 +4,6 @@ export const one_task = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 0, @@ -17,6 +16,7 @@ export const one_task = { offset: 11, }, }, + tag: '#task', }, ], sections: [ @@ -38,8 +38,6 @@ export const one_task = { ], listItems: [ { - parent: -1, - task: ' ', position: { start: { line: 0, @@ -52,8 +50,12 @@ export const one_task = { offset: 30, }, }, + parent: -1, + task: ' ', }, ], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/yaml_1_alias.ts b/tests/Obsidian/__test_data__/yaml_1_alias.ts index 2c27ecac96..ee595775ea 100644 --- a/tests/Obsidian/__test_data__/yaml_1_alias.ts +++ b/tests/Obsidian/__test_data__/yaml_1_alias.ts @@ -12,7 +12,6 @@ export const yaml_1_alias = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 7, @@ -25,12 +24,11 @@ export const yaml_1_alias = { offset: 62, }, }, + tag: '#task', }, ], headings: [ { - heading: 'yaml_1_alias', - level: 1, position: { start: { line: 5, @@ -43,6 +41,8 @@ export const yaml_1_alias = { offset: 49, }, }, + heading: 'yaml_1_alias', + level: 1, }, ], sections: [ @@ -94,8 +94,6 @@ export const yaml_1_alias = { ], listItems: [ { - parent: -7, - task: ' ', position: { start: { line: 7, @@ -108,12 +106,13 @@ export const yaml_1_alias = { offset: 85, }, }, + parent: -7, + task: ' ', }, ], frontmatter: { aliases: ['YAML Alias 1'], }, - frontmatterLinks: [], frontmatterPosition: { start: { line: 0, @@ -126,6 +125,9 @@ export const yaml_1_alias = { offset: 33, }, }, + frontmatterLinks: [], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/yaml_2_aliases.ts b/tests/Obsidian/__test_data__/yaml_2_aliases.ts index 05c7922469..54f1b90fd8 100644 --- a/tests/Obsidian/__test_data__/yaml_2_aliases.ts +++ b/tests/Obsidian/__test_data__/yaml_2_aliases.ts @@ -13,7 +13,6 @@ export const yaml_2_aliases = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 8, @@ -26,12 +25,11 @@ export const yaml_2_aliases = { offset: 81, }, }, + tag: '#task', }, ], headings: [ { - heading: 'yaml_2_aliases', - level: 1, position: { start: { line: 6, @@ -44,6 +42,8 @@ export const yaml_2_aliases = { offset: 68, }, }, + heading: 'yaml_2_aliases', + level: 1, }, ], sections: [ @@ -95,8 +95,6 @@ export const yaml_2_aliases = { ], listItems: [ { - parent: -8, - task: ' ', position: { start: { line: 8, @@ -109,12 +107,13 @@ export const yaml_2_aliases = { offset: 106, }, }, + parent: -8, + task: ' ', }, ], frontmatter: { aliases: ['YAML Alias 1', 'YAML Alias 2'], }, - frontmatterLinks: [], frontmatterPosition: { start: { line: 0, @@ -127,6 +126,9 @@ export const yaml_2_aliases = { offset: 50, }, }, + frontmatterLinks: [], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/yaml_complex_example.ts b/tests/Obsidian/__test_data__/yaml_complex_example.ts index 66cfba8a59..4b9964e092 100644 --- a/tests/Obsidian/__test_data__/yaml_complex_example.ts +++ b/tests/Obsidian/__test_data__/yaml_complex_example.ts @@ -187,4 +187,6 @@ export const yaml_complex_example = { frontmatterLinks: [], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#value1', '#value2', '#task'], + parseFrontMatterTags: ['#value1', '#value2'], }; diff --git a/tests/Obsidian/__test_data__/yaml_complex_example_standardised.ts b/tests/Obsidian/__test_data__/yaml_complex_example_standardised.ts index 7d28281810..f8d35dd8fc 100644 --- a/tests/Obsidian/__test_data__/yaml_complex_example_standardised.ts +++ b/tests/Obsidian/__test_data__/yaml_complex_example_standardised.ts @@ -185,4 +185,6 @@ export const yaml_complex_example_standardised = { frontmatterLinks: [], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#value1', '#value2', '#task'], + parseFrontMatterTags: ['#value1', '#value2'], }; diff --git a/tests/Obsidian/__test_data__/yaml_custom_number_property.ts b/tests/Obsidian/__test_data__/yaml_custom_number_property.ts index 4dc7130753..3f1d7f1e3b 100644 --- a/tests/Obsidian/__test_data__/yaml_custom_number_property.ts +++ b/tests/Obsidian/__test_data__/yaml_custom_number_property.ts @@ -88,4 +88,6 @@ export const yaml_custom_number_property = { frontmatterLinks: [], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/yaml_tags_field_added_by_obsidian_but_not_populated.ts b/tests/Obsidian/__test_data__/yaml_tags_field_added_by_obsidian_but_not_populated.ts index ea1d0d644f..5607246585 100644 --- a/tests/Obsidian/__test_data__/yaml_tags_field_added_by_obsidian_but_not_populated.ts +++ b/tests/Obsidian/__test_data__/yaml_tags_field_added_by_obsidian_but_not_populated.ts @@ -11,7 +11,6 @@ export const yaml_tags_field_added_by_obsidian_but_not_populated = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 6, @@ -24,12 +23,11 @@ export const yaml_tags_field_added_by_obsidian_but_not_populated = { offset: 81, }, }, + tag: '#task', }, ], headings: [ { - heading: 'yaml_tags_field_added_by_obsidian_but_not_populated', - level: 1, position: { start: { line: 4, @@ -42,6 +40,8 @@ export const yaml_tags_field_added_by_obsidian_but_not_populated = { offset: 68, }, }, + heading: 'yaml_tags_field_added_by_obsidian_but_not_populated', + level: 1, }, ], sections: [ @@ -93,8 +93,6 @@ export const yaml_tags_field_added_by_obsidian_but_not_populated = { ], listItems: [ { - parent: -6, - task: ' ', position: { start: { line: 6, @@ -107,12 +105,13 @@ export const yaml_tags_field_added_by_obsidian_but_not_populated = { offset: 143, }, }, + parent: -6, + task: ' ', }, ], frontmatter: { tags: null, }, - frontmatterLinks: [], frontmatterPosition: { start: { line: 0, @@ -125,6 +124,9 @@ export const yaml_tags_field_added_by_obsidian_but_not_populated = { offset: 13, }, }, + frontmatterLinks: [], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/yaml_tags_had_value_then_was_emptied_by_obsidian.ts b/tests/Obsidian/__test_data__/yaml_tags_had_value_then_was_emptied_by_obsidian.ts index dab63149e3..4a59557bcf 100644 --- a/tests/Obsidian/__test_data__/yaml_tags_had_value_then_was_emptied_by_obsidian.ts +++ b/tests/Obsidian/__test_data__/yaml_tags_had_value_then_was_emptied_by_obsidian.ts @@ -12,7 +12,6 @@ export const yaml_tags_had_value_then_was_emptied_by_obsidian = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 7, @@ -25,12 +24,11 @@ export const yaml_tags_had_value_then_was_emptied_by_obsidian = { offset: 82, }, }, + tag: '#task', }, ], headings: [ { - heading: 'yaml_tags_had_value_then_was_emptied_by_obsidian', - level: 1, position: { start: { line: 5, @@ -43,6 +41,8 @@ export const yaml_tags_had_value_then_was_emptied_by_obsidian = { offset: 69, }, }, + heading: 'yaml_tags_had_value_then_was_emptied_by_obsidian', + level: 1, }, ], sections: [ @@ -94,8 +94,6 @@ export const yaml_tags_had_value_then_was_emptied_by_obsidian = { ], listItems: [ { - parent: -7, - task: ' ', position: { start: { line: 7, @@ -108,12 +106,13 @@ export const yaml_tags_had_value_then_was_emptied_by_obsidian = { offset: 141, }, }, + parent: -7, + task: ' ', }, ], frontmatter: { tags: [], }, - frontmatterLinks: [], frontmatterPosition: { start: { line: 0, @@ -126,6 +125,9 @@ export const yaml_tags_had_value_then_was_emptied_by_obsidian = { offset: 16, }, }, + frontmatterLinks: [], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/yaml_tags_has_multiple_values.ts b/tests/Obsidian/__test_data__/yaml_tags_has_multiple_values.ts index 7bfe4b711f..bd4fc1af60 100644 --- a/tests/Obsidian/__test_data__/yaml_tags_has_multiple_values.ts +++ b/tests/Obsidian/__test_data__/yaml_tags_has_multiple_values.ts @@ -13,7 +13,6 @@ export const yaml_tags_has_multiple_values = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 8, @@ -26,12 +25,11 @@ export const yaml_tags_has_multiple_values = { offset: 87, }, }, + tag: '#task', }, ], headings: [ { - heading: 'yaml_tags_has_multiple_values', - level: 1, position: { start: { line: 6, @@ -44,6 +42,8 @@ export const yaml_tags_has_multiple_values = { offset: 74, }, }, + heading: 'yaml_tags_has_multiple_values', + level: 1, }, ], sections: [ @@ -95,8 +95,6 @@ export const yaml_tags_has_multiple_values = { ], listItems: [ { - parent: -8, - task: ' ', position: { start: { line: 8, @@ -109,12 +107,13 @@ export const yaml_tags_has_multiple_values = { offset: 127, }, }, + parent: -8, + task: ' ', }, ], frontmatter: { tags: ['multiple1', 'multiple2'], }, - frontmatterLinks: [], frontmatterPosition: { start: { line: 0, @@ -127,6 +126,9 @@ export const yaml_tags_has_multiple_values = { offset: 41, }, }, + frontmatterLinks: [], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#multiple1', '#multiple2', '#task'], + parseFrontMatterTags: ['#multiple1', '#multiple2'], }; diff --git a/tests/Obsidian/__test_data__/yaml_tags_is_empty.ts b/tests/Obsidian/__test_data__/yaml_tags_is_empty.ts index cbeddec2d0..33ddc7a3d5 100644 --- a/tests/Obsidian/__test_data__/yaml_tags_is_empty.ts +++ b/tests/Obsidian/__test_data__/yaml_tags_is_empty.ts @@ -11,7 +11,6 @@ export const yaml_tags_is_empty = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 6, @@ -24,12 +23,11 @@ export const yaml_tags_is_empty = { offset: 48, }, }, + tag: '#task', }, ], headings: [ { - heading: 'yaml_tags_is_empty', - level: 1, position: { start: { line: 4, @@ -42,6 +40,8 @@ export const yaml_tags_is_empty = { offset: 35, }, }, + heading: 'yaml_tags_is_empty', + level: 1, }, ], sections: [ @@ -93,8 +93,6 @@ export const yaml_tags_is_empty = { ], listItems: [ { - parent: -6, - task: ' ', position: { start: { line: 6, @@ -107,12 +105,13 @@ export const yaml_tags_is_empty = { offset: 77, }, }, + parent: -6, + task: ' ', }, ], frontmatter: { tags: null, }, - frontmatterLinks: [], frontmatterPosition: { start: { line: 0, @@ -125,6 +124,9 @@ export const yaml_tags_is_empty = { offset: 13, }, }, + frontmatterLinks: [], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/yaml_tags_is_empty_list.ts b/tests/Obsidian/__test_data__/yaml_tags_is_empty_list.ts index 635962d90d..382f104784 100644 --- a/tests/Obsidian/__test_data__/yaml_tags_is_empty_list.ts +++ b/tests/Obsidian/__test_data__/yaml_tags_is_empty_list.ts @@ -11,7 +11,6 @@ export const yaml_tags_is_empty_list = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 6, @@ -24,12 +23,11 @@ export const yaml_tags_is_empty_list = { offset: 56, }, }, + tag: '#task', }, ], headings: [ { - heading: 'yaml_tags_is_empty_list', - level: 1, position: { start: { line: 4, @@ -42,6 +40,8 @@ export const yaml_tags_is_empty_list = { offset: 43, }, }, + heading: 'yaml_tags_is_empty_list', + level: 1, }, ], sections: [ @@ -93,8 +93,6 @@ export const yaml_tags_is_empty_list = { ], listItems: [ { - parent: -6, - task: ' ', position: { start: { line: 6, @@ -107,12 +105,13 @@ export const yaml_tags_is_empty_list = { offset: 90, }, }, + parent: -6, + task: ' ', }, ], frontmatter: { tags: [], }, - frontmatterLinks: [], frontmatterPosition: { start: { line: 0, @@ -125,6 +124,9 @@ export const yaml_tags_is_empty_list = { offset: 16, }, }, + frontmatterLinks: [], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#task'], + parseFrontMatterTags: null, }; diff --git a/tests/Obsidian/__test_data__/yaml_tags_with_one_value_on_new_line.ts b/tests/Obsidian/__test_data__/yaml_tags_with_one_value_on_new_line.ts index 93d47f02a8..74c2229e8a 100644 --- a/tests/Obsidian/__test_data__/yaml_tags_with_one_value_on_new_line.ts +++ b/tests/Obsidian/__test_data__/yaml_tags_with_one_value_on_new_line.ts @@ -13,7 +13,6 @@ export const yaml_tags_with_one_value_on_new_line = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 8, @@ -26,12 +25,11 @@ export const yaml_tags_with_one_value_on_new_line = { offset: 93, }, }, + tag: '#task', }, ], headings: [ { - heading: 'yaml_tags_with_one_value_on_new_line', - level: 1, position: { start: { line: 6, @@ -44,6 +42,8 @@ export const yaml_tags_with_one_value_on_new_line = { offset: 80, }, }, + heading: 'yaml_tags_with_one_value_on_new_line', + level: 1, }, ], sections: [ @@ -95,8 +95,6 @@ export const yaml_tags_with_one_value_on_new_line = { ], listItems: [ { - parent: -8, - task: ' ', position: { start: { line: 8, @@ -109,12 +107,13 @@ export const yaml_tags_with_one_value_on_new_line = { offset: 140, }, }, + parent: -8, + task: ' ', }, ], frontmatter: { tags: ['single-value-new-line'], }, - frontmatterLinks: [], frontmatterPosition: { start: { line: 0, @@ -127,6 +126,9 @@ export const yaml_tags_with_one_value_on_new_line = { offset: 39, }, }, + frontmatterLinks: [], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#single-value-new-line', '#task'], + parseFrontMatterTags: ['#single-value-new-line'], }; diff --git a/tests/Obsidian/__test_data__/yaml_tags_with_one_value_on_single_line.ts b/tests/Obsidian/__test_data__/yaml_tags_with_one_value_on_single_line.ts index 180c9a13b8..4e89e8c036 100644 --- a/tests/Obsidian/__test_data__/yaml_tags_with_one_value_on_single_line.ts +++ b/tests/Obsidian/__test_data__/yaml_tags_with_one_value_on_single_line.ts @@ -11,7 +11,6 @@ export const yaml_tags_with_one_value_on_single_line = { cachedMetadata: { tags: [ { - tag: '#task', position: { start: { line: 6, @@ -24,12 +23,11 @@ export const yaml_tags_with_one_value_on_single_line = { offset: 94, }, }, + tag: '#task', }, ], headings: [ { - heading: 'yaml_tags_with_one_value_on_single_line', - level: 1, position: { start: { line: 4, @@ -42,6 +40,8 @@ export const yaml_tags_with_one_value_on_single_line = { offset: 81, }, }, + heading: 'yaml_tags_with_one_value_on_single_line', + level: 1, }, ], sections: [ @@ -93,8 +93,6 @@ export const yaml_tags_with_one_value_on_single_line = { ], listItems: [ { - parent: -6, - task: ' ', position: { start: { line: 6, @@ -107,12 +105,13 @@ export const yaml_tags_with_one_value_on_single_line = { offset: 144, }, }, + parent: -6, + task: ' ', }, ], frontmatter: { tags: 'single-value-single-line', }, - frontmatterLinks: [], frontmatterPosition: { start: { line: 0, @@ -125,6 +124,9 @@ export const yaml_tags_with_one_value_on_single_line = { offset: 38, }, }, + frontmatterLinks: [], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#single-value-single-line', '#task'], + parseFrontMatterTags: ['#single-value-single-line'], }; diff --git a/tests/Obsidian/__test_data__/yaml_tags_with_two_values_on_one_line.ts b/tests/Obsidian/__test_data__/yaml_tags_with_two_values_on_one_line.ts index 06cbd0edf0..c3896eb900 100644 --- a/tests/Obsidian/__test_data__/yaml_tags_with_two_values_on_one_line.ts +++ b/tests/Obsidian/__test_data__/yaml_tags_with_two_values_on_one_line.ts @@ -127,4 +127,6 @@ export const yaml_tags_with_two_values_on_one_line = { frontmatterLinks: [], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#value-1-of-2-on-one-line', '#value-2-of-2-on-one-line', '#task'], + parseFrontMatterTags: ['#value-1-of-2-on-one-line', '#value-2-of-2-on-one-line'], }; diff --git a/tests/Obsidian/__test_data__/yaml_tags_with_two_values_on_two_lines.ts b/tests/Obsidian/__test_data__/yaml_tags_with_two_values_on_two_lines.ts index 5fb326b54c..8b78df9105 100644 --- a/tests/Obsidian/__test_data__/yaml_tags_with_two_values_on_two_lines.ts +++ b/tests/Obsidian/__test_data__/yaml_tags_with_two_values_on_two_lines.ts @@ -129,4 +129,6 @@ export const yaml_tags_with_two_values_on_two_lines = { frontmatterLinks: [], }, obsidianApiVersion: '1.6.5', + getAllTags: ['#value-1-of-2-on-two-lines', '#value-2-of-2-on-two-lines', '#task'], + parseFrontMatterTags: ['#value-1-of-2-on-two-lines', '#value-2-of-2-on-two-lines'], }; From a0c925e9f50707184eb8ed2eec3be17651abd4b3 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Thu, 11 Jul 2024 15:36:32 +0600 Subject: [PATCH 02/13] test: - add first test for task.file.tags --- tests/Scripting/TasksFile.test.ts | 4 ++-- tests/__mocks__/obsidian.ts | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/Scripting/TasksFile.test.ts b/tests/Scripting/TasksFile.test.ts index 9f551f7429..e8f909851f 100644 --- a/tests/Scripting/TasksFile.test.ts +++ b/tests/Scripting/TasksFile.test.ts @@ -106,13 +106,13 @@ describe('TasksFile - reading frontmatter', () => { }); describe('TasksFile - reading tags', () => { - it.failing('should read a tag from the frontmatter', () => { + it('should read a tag from the frontmatter', () => { // Fails with 'TypeError: (0 , obsidian_1.getAllTags) is not a function' // It looks like Obsidian's getAllTags() cannot be called outside of a vault. const data = yaml_tags_with_one_value_on_new_line; const cachedMetadata = data.cachedMetadata as any as CachedMetadata; const tasksFile = new TasksFile(data.filePath, cachedMetadata); - expect(tasksFile.tags).toEqual(['#single-value-new-line']); + expect(tasksFile.tags).toEqual(['#single-value-new-line', '#task']); }); }); diff --git a/tests/__mocks__/obsidian.ts b/tests/__mocks__/obsidian.ts index e40666879b..a0a2f9f60b 100644 --- a/tests/__mocks__/obsidian.ts +++ b/tests/__mocks__/obsidian.ts @@ -1,3 +1,6 @@ +import type { CachedMetadata } from 'obsidian'; +import { yaml_tags_with_one_value_on_new_line } from '../Obsidian/__test_data__/yaml_tags_with_one_value_on_new_line'; + export {}; export class MenuItem { @@ -122,6 +125,10 @@ function caseInsensitiveSubstringSearch(searchTerm: string, phrase: string): Sea : null; } +export function getAllTags(_cachedMetadata: CachedMetadata): string[] { + return yaml_tags_with_one_value_on_new_line.getAllTags; +} + /** * A fake implementation of prepareSimpleSearch(), * so we can write tests of code that calls that function. From 683c666c837225f8c23f8b7cb6a73ae55b7d3b85 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Thu, 11 Jul 2024 15:41:12 +0600 Subject: [PATCH 03/13] test: - add control over mock data --- tests/Scripting/TasksFile.test.ts | 4 ++-- tests/__mocks__/obsidian.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/Scripting/TasksFile.test.ts b/tests/Scripting/TasksFile.test.ts index e8f909851f..0a0146cde4 100644 --- a/tests/Scripting/TasksFile.test.ts +++ b/tests/Scripting/TasksFile.test.ts @@ -1,5 +1,6 @@ import type { CachedMetadata } from 'obsidian'; import { TasksFile } from '../../src/Scripting/TasksFile'; +import { setCurrentCacheFile } from '../__mocks__/obsidian'; import { no_yaml } from '../Obsidian/__test_data__/no_yaml'; import { empty_yaml } from '../Obsidian/__test_data__/empty_yaml'; import { yaml_tags_has_multiple_values } from '../Obsidian/__test_data__/yaml_tags_has_multiple_values'; @@ -107,8 +108,7 @@ describe('TasksFile - reading frontmatter', () => { describe('TasksFile - reading tags', () => { it('should read a tag from the frontmatter', () => { - // Fails with 'TypeError: (0 , obsidian_1.getAllTags) is not a function' - // It looks like Obsidian's getAllTags() cannot be called outside of a vault. + setCurrentCacheFile(yaml_tags_with_one_value_on_new_line); const data = yaml_tags_with_one_value_on_new_line; const cachedMetadata = data.cachedMetadata as any as CachedMetadata; const tasksFile = new TasksFile(data.filePath, cachedMetadata); diff --git a/tests/__mocks__/obsidian.ts b/tests/__mocks__/obsidian.ts index a0a2f9f60b..1ca0f6fa86 100644 --- a/tests/__mocks__/obsidian.ts +++ b/tests/__mocks__/obsidian.ts @@ -1,5 +1,4 @@ import type { CachedMetadata } from 'obsidian'; -import { yaml_tags_with_one_value_on_new_line } from '../Obsidian/__test_data__/yaml_tags_with_one_value_on_new_line'; export {}; @@ -125,8 +124,14 @@ function caseInsensitiveSubstringSearch(searchTerm: string, phrase: string): Sea : null; } +export let mockGetAllTagsData: any = {}; + +export function setCurrentCacheFile(mockData: any) { + mockGetAllTagsData = mockData.getAllTags; +} + export function getAllTags(_cachedMetadata: CachedMetadata): string[] { - return yaml_tags_with_one_value_on_new_line.getAllTags; + return mockGetAllTagsData; } /** From 6f4a837c63258828be04b388b3af2a771da49660 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Thu, 11 Jul 2024 15:46:38 +0600 Subject: [PATCH 04/13] test: . extract getTasksFileFromMockData() --- tests/Scripting/TasksFile.test.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/Scripting/TasksFile.test.ts b/tests/Scripting/TasksFile.test.ts index 0a0146cde4..7c67f4f9c1 100644 --- a/tests/Scripting/TasksFile.test.ts +++ b/tests/Scripting/TasksFile.test.ts @@ -54,6 +54,12 @@ describe('TasksFile', () => { }); }); +function getTasksFileFromMockData(data: any) { + setCurrentCacheFile(data); + const cachedMetadata = data.cachedMetadata as any as CachedMetadata; + return new TasksFile(data.filePath, cachedMetadata); +} + describe('TasksFile - reading frontmatter', () => { it('should read file if not given CachedMetadata', () => { const tasksFile = new TasksFile('some path.md', {}); @@ -108,10 +114,7 @@ describe('TasksFile - reading frontmatter', () => { describe('TasksFile - reading tags', () => { it('should read a tag from the frontmatter', () => { - setCurrentCacheFile(yaml_tags_with_one_value_on_new_line); - const data = yaml_tags_with_one_value_on_new_line; - const cachedMetadata = data.cachedMetadata as any as CachedMetadata; - const tasksFile = new TasksFile(data.filePath, cachedMetadata); + const tasksFile = getTasksFileFromMockData(yaml_tags_with_one_value_on_new_line); expect(tasksFile.tags).toEqual(['#single-value-new-line', '#task']); }); From 0c82592c9702349dc0330c4c9092724f6be323c3 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Thu, 11 Jul 2024 15:48:34 +0600 Subject: [PATCH 05/13] test: - reuse getTasksFileFromMockData() --- tests/Scripting/TasksFile.test.ts | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/tests/Scripting/TasksFile.test.ts b/tests/Scripting/TasksFile.test.ts index 7c67f4f9c1..f4979a47e9 100644 --- a/tests/Scripting/TasksFile.test.ts +++ b/tests/Scripting/TasksFile.test.ts @@ -69,28 +69,19 @@ describe('TasksFile - reading frontmatter', () => { }); it('should read file with no yaml metadata', () => { - const data = no_yaml; - const cachedMetadata = data.cachedMetadata as any as CachedMetadata; - const tasksFile = new TasksFile(data.filePath, cachedMetadata); - + const tasksFile = getTasksFileFromMockData(no_yaml); expect(tasksFile.cachedMetadata.frontmatter).toBeUndefined(); expect(tasksFile.frontmatter).toEqual({}); }); it('should read file with empty yaml metadata', () => { - const data = empty_yaml; - const cachedMetadata = data.cachedMetadata as any as CachedMetadata; - const tasksFile = new TasksFile(data.filePath, cachedMetadata); - + const tasksFile = getTasksFileFromMockData(empty_yaml); expect(tasksFile.cachedMetadata.frontmatter).toBeUndefined(); expect(tasksFile.frontmatter).toEqual({}); }); it('should read file with multiple tags in yaml metadata', () => { - const data = yaml_tags_has_multiple_values; - const cachedMetadata = data.cachedMetadata as any as CachedMetadata; - const tasksFile = new TasksFile(data.filePath, cachedMetadata); - + const tasksFile = getTasksFileFromMockData(yaml_tags_has_multiple_values); expect(tasksFile.cachedMetadata.frontmatter?.tags).toEqual(['multiple1', 'multiple2']); expect(tasksFile.frontmatter.tags).toEqual(['multiple1', 'multiple2']); }); @@ -104,10 +95,7 @@ describe('TasksFile - reading frontmatter', () => { // Date // Date & time it('should read file with custom number property', () => { - const data = yaml_custom_number_property; - const cachedMetadata = data.cachedMetadata as any as CachedMetadata; - const tasksFile = new TasksFile(data.filePath, cachedMetadata); - + const tasksFile = getTasksFileFromMockData(yaml_custom_number_property); expect(tasksFile.frontmatter?.custom_number_prop).toEqual(42); }); }); @@ -115,7 +103,6 @@ describe('TasksFile - reading frontmatter', () => { describe('TasksFile - reading tags', () => { it('should read a tag from the frontmatter', () => { const tasksFile = getTasksFileFromMockData(yaml_tags_with_one_value_on_new_line); - expect(tasksFile.tags).toEqual(['#single-value-new-line', '#task']); }); }); From acdaefcd84e278a42fa92e8a6b3e8188be5298f7 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Thu, 11 Jul 2024 16:10:41 +0600 Subject: [PATCH 06/13] refactor: - store TasksFile.frontmatter and TasksFile.cachedMetadata.frontmatter as independent objects --- src/Scripting/TasksFile.ts | 6 +++++- tests/Scripting/TasksFile.test.ts | 15 ++++++++++++++- tests/ui/EditableTask.test.ts | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Scripting/TasksFile.ts b/src/Scripting/TasksFile.ts index ff9814873f..6dc079b53d 100644 --- a/src/Scripting/TasksFile.ts +++ b/src/Scripting/TasksFile.ts @@ -6,10 +6,14 @@ import { type CachedMetadata, type FrontMatterCache, getAllTags, parseFrontMatte export class TasksFile { private readonly _path: string; private readonly _cachedMetadata: CachedMetadata; + private readonly _frontmatter: FrontMatterCache; constructor(path: string, cachedMetadata: CachedMetadata = {}) { this._path = path; this._cachedMetadata = cachedMetadata; + this._frontmatter = cachedMetadata.frontmatter + ? JSON.parse(JSON.stringify(cachedMetadata.frontmatter)) + : ({} as FrontMatterCache); } /** @@ -71,7 +75,7 @@ export class TasksFile { * or if the markdown file has no frontmatter or empty frontmatter. */ public get frontmatter(): FrontMatterCache { - return this._cachedMetadata.frontmatter ?? ({} as FrontMatterCache); + return this._frontmatter; } /** diff --git a/tests/Scripting/TasksFile.test.ts b/tests/Scripting/TasksFile.test.ts index f4979a47e9..e82f7be21c 100644 --- a/tests/Scripting/TasksFile.test.ts +++ b/tests/Scripting/TasksFile.test.ts @@ -80,10 +80,23 @@ describe('TasksFile - reading frontmatter', () => { expect(tasksFile.frontmatter).toEqual({}); }); - it('should read file with multiple tags in yaml metadata', () => { + it('should provide an independent copy of frontmatter', () => { const tasksFile = getTasksFileFromMockData(yaml_tags_has_multiple_values); + + expect(tasksFile.frontmatter).not.toBe(tasksFile.cachedMetadata.frontmatter); + expect(tasksFile.frontmatter).toEqual(tasksFile.cachedMetadata.frontmatter); + expect(tasksFile.cachedMetadata.frontmatter?.tags).toEqual(['multiple1', 'multiple2']); expect(tasksFile.frontmatter.tags).toEqual(['multiple1', 'multiple2']); + + tasksFile.frontmatter.tags.push('newTag'); + expect(tasksFile.cachedMetadata.frontmatter?.tags).toEqual(['multiple1', 'multiple2']); + expect(tasksFile.frontmatter.tags).toEqual(['multiple1', 'multiple2', 'newTag']); + }); + + it('should read file with multiple tags in yaml metadata', () => { + const tasksFile = getTasksFileFromMockData(yaml_tags_has_multiple_values); + expect(tasksFile.cachedMetadata.frontmatter?.tags).toEqual(['multiple1', 'multiple2']); }); // See property types: https://help.obsidian.md/Editing+and+formatting/Properties#Property+types diff --git a/tests/ui/EditableTask.test.ts b/tests/ui/EditableTask.test.ts index d694840572..cddc6182a3 100644 --- a/tests/ui/EditableTask.test.ts +++ b/tests/ui/EditableTask.test.ts @@ -195,6 +195,7 @@ describe('EditableTask tests', () => { "_sectionStart": 5, "_tasksFile": TasksFile { "_cachedMetadata": {}, + "_frontmatter": {}, "_path": "some/folder/fileName.md", }, }, From 9c6e31f9f1cce218fe74d83b23b2eac812a452c6 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Thu, 11 Jul 2024 16:24:15 +0600 Subject: [PATCH 07/13] refactor: - add # prefix to task.file.frontmatter.tags --- src/Scripting/TasksFile.ts | 10 +++++++--- tests/Scripting/TasksFile.test.ts | 5 ++--- tests/__mocks__/obsidian.ts | 8 ++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Scripting/TasksFile.ts b/src/Scripting/TasksFile.ts index 6dc079b53d..4032844cf0 100644 --- a/src/Scripting/TasksFile.ts +++ b/src/Scripting/TasksFile.ts @@ -11,9 +11,13 @@ export class TasksFile { constructor(path: string, cachedMetadata: CachedMetadata = {}) { this._path = path; this._cachedMetadata = cachedMetadata; - this._frontmatter = cachedMetadata.frontmatter - ? JSON.parse(JSON.stringify(cachedMetadata.frontmatter)) - : ({} as FrontMatterCache); + this._frontmatter = {} as FrontMatterCache; + if (cachedMetadata.frontmatter) { + this._frontmatter = cachedMetadata.frontmatter + ? JSON.parse(JSON.stringify(cachedMetadata.frontmatter)) + : ({} as FrontMatterCache); + this._frontmatter.tags = parseFrontMatterTags(this._cachedMetadata.frontmatter); + } } /** diff --git a/tests/Scripting/TasksFile.test.ts b/tests/Scripting/TasksFile.test.ts index e82f7be21c..d3c2aee03d 100644 --- a/tests/Scripting/TasksFile.test.ts +++ b/tests/Scripting/TasksFile.test.ts @@ -84,14 +84,13 @@ describe('TasksFile - reading frontmatter', () => { const tasksFile = getTasksFileFromMockData(yaml_tags_has_multiple_values); expect(tasksFile.frontmatter).not.toBe(tasksFile.cachedMetadata.frontmatter); - expect(tasksFile.frontmatter).toEqual(tasksFile.cachedMetadata.frontmatter); expect(tasksFile.cachedMetadata.frontmatter?.tags).toEqual(['multiple1', 'multiple2']); - expect(tasksFile.frontmatter.tags).toEqual(['multiple1', 'multiple2']); + expect(tasksFile.frontmatter.tags).toEqual(['#multiple1', '#multiple2']); tasksFile.frontmatter.tags.push('newTag'); expect(tasksFile.cachedMetadata.frontmatter?.tags).toEqual(['multiple1', 'multiple2']); - expect(tasksFile.frontmatter.tags).toEqual(['multiple1', 'multiple2', 'newTag']); + expect(tasksFile.frontmatter.tags).toEqual(['#multiple1', '#multiple2', 'newTag']); }); it('should read file with multiple tags in yaml metadata', () => { diff --git a/tests/__mocks__/obsidian.ts b/tests/__mocks__/obsidian.ts index 1ca0f6fa86..d0a2a0d821 100644 --- a/tests/__mocks__/obsidian.ts +++ b/tests/__mocks__/obsidian.ts @@ -127,11 +127,15 @@ function caseInsensitiveSubstringSearch(searchTerm: string, phrase: string): Sea export let mockGetAllTagsData: any = {}; export function setCurrentCacheFile(mockData: any) { - mockGetAllTagsData = mockData.getAllTags; + mockGetAllTagsData = mockData; } export function getAllTags(_cachedMetadata: CachedMetadata): string[] { - return mockGetAllTagsData; + return mockGetAllTagsData.getAllTags; +} + +export function parseFrontMatterTags(_frontmatter: any | null): string[] | null { + return mockGetAllTagsData.parseFrontMatterTags; } /** From 141935756fb7d17fe13e9c7cb4afa16b0759c973 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Thu, 11 Jul 2024 16:27:24 +0600 Subject: [PATCH 08/13] refactor: - simplify constructor --- src/Scripting/TasksFile.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Scripting/TasksFile.ts b/src/Scripting/TasksFile.ts index 4032844cf0..3240c59ee1 100644 --- a/src/Scripting/TasksFile.ts +++ b/src/Scripting/TasksFile.ts @@ -12,11 +12,10 @@ export class TasksFile { this._path = path; this._cachedMetadata = cachedMetadata; this._frontmatter = {} as FrontMatterCache; - if (cachedMetadata.frontmatter) { - this._frontmatter = cachedMetadata.frontmatter - ? JSON.parse(JSON.stringify(cachedMetadata.frontmatter)) - : ({} as FrontMatterCache); - this._frontmatter.tags = parseFrontMatterTags(this._cachedMetadata.frontmatter); + const rawFrontmatter = cachedMetadata.frontmatter; + if (rawFrontmatter !== undefined) { + this._frontmatter = JSON.parse(JSON.stringify(rawFrontmatter)); + this._frontmatter.tags = parseFrontMatterTags(rawFrontmatter); } } From aa5780e5108d6d9d32548176b4d675dc57c974d0 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Thu, 11 Jul 2024 16:28:44 +0600 Subject: [PATCH 09/13] refactor: - move default value to field declaration --- src/Scripting/TasksFile.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Scripting/TasksFile.ts b/src/Scripting/TasksFile.ts index 3240c59ee1..8f506d3b09 100644 --- a/src/Scripting/TasksFile.ts +++ b/src/Scripting/TasksFile.ts @@ -6,12 +6,12 @@ import { type CachedMetadata, type FrontMatterCache, getAllTags, parseFrontMatte export class TasksFile { private readonly _path: string; private readonly _cachedMetadata: CachedMetadata; - private readonly _frontmatter: FrontMatterCache; + private readonly _frontmatter: FrontMatterCache = {} as FrontMatterCache; constructor(path: string, cachedMetadata: CachedMetadata = {}) { this._path = path; this._cachedMetadata = cachedMetadata; - this._frontmatter = {} as FrontMatterCache; + const rawFrontmatter = cachedMetadata.frontmatter; if (rawFrontmatter !== undefined) { this._frontmatter = JSON.parse(JSON.stringify(rawFrontmatter)); From ce27822612a0b9318bd99a6c9fe35790414fdc95 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Thu, 11 Jul 2024 16:29:36 +0600 Subject: [PATCH 10/13] test: . improve mocks --- tests/__mocks__/obsidian.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/__mocks__/obsidian.ts b/tests/__mocks__/obsidian.ts index d0a2a0d821..20d5664253 100644 --- a/tests/__mocks__/obsidian.ts +++ b/tests/__mocks__/obsidian.ts @@ -124,18 +124,18 @@ function caseInsensitiveSubstringSearch(searchTerm: string, phrase: string): Sea : null; } -export let mockGetAllTagsData: any = {}; +let mockedFileData: any = {}; export function setCurrentCacheFile(mockData: any) { - mockGetAllTagsData = mockData; + mockedFileData = mockData; } export function getAllTags(_cachedMetadata: CachedMetadata): string[] { - return mockGetAllTagsData.getAllTags; + return mockedFileData.getAllTags; } export function parseFrontMatterTags(_frontmatter: any | null): string[] | null { - return mockGetAllTagsData.parseFrontMatterTags; + return mockedFileData.parseFrontMatterTags; } /** From 3caf6bcf75bceb255e6ed780bedb47bdad3d467c Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Thu, 11 Jul 2024 16:46:16 +0600 Subject: [PATCH 11/13] refactor: - tasksFile.tags returns unique tags --- src/Scripting/TasksFile.ts | 3 ++- tests/Scripting/TasksFile.test.ts | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Scripting/TasksFile.ts b/src/Scripting/TasksFile.ts index 8f506d3b09..74c3da24f3 100644 --- a/src/Scripting/TasksFile.ts +++ b/src/Scripting/TasksFile.ts @@ -36,7 +36,8 @@ export class TasksFile { * @todo Review presence of global filter tag in the results. */ get tags(): string[] { - return getAllTags(this.cachedMetadata) ?? []; + const strings = getAllTags(this.cachedMetadata) ?? []; + return [...new Set(strings)]; } /** diff --git a/tests/Scripting/TasksFile.test.ts b/tests/Scripting/TasksFile.test.ts index d3c2aee03d..b5b82bf66b 100644 --- a/tests/Scripting/TasksFile.test.ts +++ b/tests/Scripting/TasksFile.test.ts @@ -1,6 +1,7 @@ import type { CachedMetadata } from 'obsidian'; import { TasksFile } from '../../src/Scripting/TasksFile'; import { setCurrentCacheFile } from '../__mocks__/obsidian'; +import { callouts_nested_issue_2890_unlabelled } from '../Obsidian/__test_data__/callouts_nested_issue_2890_unlabelled'; import { no_yaml } from '../Obsidian/__test_data__/no_yaml'; import { empty_yaml } from '../Obsidian/__test_data__/empty_yaml'; import { yaml_tags_has_multiple_values } from '../Obsidian/__test_data__/yaml_tags_has_multiple_values'; @@ -117,4 +118,9 @@ describe('TasksFile - reading tags', () => { const tasksFile = getTasksFileFromMockData(yaml_tags_with_one_value_on_new_line); expect(tasksFile.tags).toEqual(['#single-value-new-line', '#task']); }); + + it('should read tags from body of file without duplication', () => { + const tasksFile = getTasksFileFromMockData(callouts_nested_issue_2890_unlabelled); + expect(tasksFile.tags).toEqual(['#task']); + }); }); From dde40a8b131e45ed728a3e09f34e3ce2ae5e2068 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Thu, 11 Jul 2024 16:50:05 +0600 Subject: [PATCH 12/13] test: - show difference between tasksFile.tags and tasksFile.frontmatter.tags --- tests/Scripting/TasksFile.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Scripting/TasksFile.test.ts b/tests/Scripting/TasksFile.test.ts index b5b82bf66b..4f2ede64a2 100644 --- a/tests/Scripting/TasksFile.test.ts +++ b/tests/Scripting/TasksFile.test.ts @@ -114,9 +114,10 @@ describe('TasksFile - reading frontmatter', () => { }); describe('TasksFile - reading tags', () => { - it('should read a tag from the frontmatter', () => { + it('should read a tag from body and the frontmatter', () => { const tasksFile = getTasksFileFromMockData(yaml_tags_with_one_value_on_new_line); expect(tasksFile.tags).toEqual(['#single-value-new-line', '#task']); + expect(tasksFile.frontmatter.tags).toEqual(['#single-value-new-line']); }); it('should read tags from body of file without duplication', () => { From 80325a6a8cd4c24ff8b525b61350017f908c7ee1 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Thu, 11 Jul 2024 16:55:57 +0600 Subject: [PATCH 13/13] refactor: . rename variable --- src/Scripting/TasksFile.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Scripting/TasksFile.ts b/src/Scripting/TasksFile.ts index 74c3da24f3..f2111eaab2 100644 --- a/src/Scripting/TasksFile.ts +++ b/src/Scripting/TasksFile.ts @@ -36,8 +36,8 @@ export class TasksFile { * @todo Review presence of global filter tag in the results. */ get tags(): string[] { - const strings = getAllTags(this.cachedMetadata) ?? []; - return [...new Set(strings)]; + const tags = getAllTags(this.cachedMetadata) ?? []; + return [...new Set(tags)]; } /**