Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: demo property custom searches #2981

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion resources/sample_vaults/Tasks-Demo/.obsidian/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"sample_checkbox_property": "checkbox",
"sample_number_property": "number",
"sample_link_list_property": "multitext",
"sample_link_property": "text"
"sample_link_property": "text",
"creation date": "datetime"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ sample_text_property:
sample_link_property:
sample_link_list_property:
aliases:
tags:
tags:
creation date:
---
# yaml_all_property_types_empty

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ aliases:
- YAML All Property Types Populated
tags:
- sample/tag/value
creation date: 2024-05-25T15:17:00
---

# yaml_all_property_types_populated
Expand Down
34 changes: 1 addition & 33 deletions tests/Obsidian/Cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
* @jest-environment jsdom
*/
import moment from 'moment/moment';
import type { CachedMetadata } from 'obsidian';
import { logging } from '../../src/lib/logging';
import { getTasksFromFileContent2 } from '../../src/Obsidian/Cache';
import type { ListItem } from '../../src/Task/ListItem';
import { setCurrentCacheFile } from '../__mocks__/obsidian';
import { getTasksFileFromMockData, listPathAndData } from '../TestingTools/MockDataHelpers';
import { inheritance_1parent1child } from './__test_data__/inheritance_1parent1child';
import { inheritance_1parent1child1newroot_after_header } from './__test_data__/inheritance_1parent1child1newroot_after_header';
Expand All @@ -32,38 +28,10 @@ import { callout_labelled } from './__test_data__/callout_labelled';
import { callout_custom } from './__test_data__/callout_custom';
import { callouts_nested_issue_2890_unlabelled } from './__test_data__/callouts_nested_issue_2890_unlabelled';
import { allCacheSampleData } from './AllCacheSampleData';
import { readTasksFromSimulatedFile } from './SimulatedFile';

window.moment = moment;

function errorReporter() {
return;
}

interface SimulatedFile {
cachedMetadata: CachedMetadata;
filePath: string;
fileContents: string;
}

/**
For explanations on how to test code that is using Obsidian API
refer to https://publish.obsidian.md/tasks-contributing/Testing/Using+Obsidian+API+in+tests

TODO: Make the order of values in the generated code stable.
*/
function readTasksFromSimulatedFile(testData: SimulatedFile) {
const logger = logging.getLogger('testCache');
setCurrentCacheFile(testData);
return getTasksFromFileContent2(
testData.filePath,
testData.fileContents,
testData.cachedMetadata.listItems!,
logger,
testData.cachedMetadata,
errorReporter,
);
}

function testRootAndChildren(root: ListItem, children: ListItem[]) {
expect(root.parent).toEqual(null);

Expand Down
33 changes: 33 additions & 0 deletions tests/Obsidian/SimulatedFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { CachedMetadata } from 'obsidian';
import { logging } from '../../src/lib/logging';
import { getTasksFromFileContent2 } from '../../src/Obsidian/Cache';
import { setCurrentCacheFile } from '../__mocks__/obsidian';

export interface SimulatedFile {
cachedMetadata: CachedMetadata;
filePath: string;
fileContents: string;
}

/**
For explanations on how to test code that is using Obsidian API
refer to https://publish.obsidian.md/tasks-contributing/Testing/Using+Obsidian+API+in+tests

TODO: Make the order of values in the generated code stable.
*/
export function readTasksFromSimulatedFile(testData: SimulatedFile) {
const logger = logging.getLogger('testCache');
setCurrentCacheFile(testData);
return getTasksFromFileContent2(
testData.filePath,
testData.fileContents,
testData.cachedMetadata.listItems!,
logger,
testData.cachedMetadata,
errorReporter,
);
}

function errorReporter() {
return;
}
54 changes: 28 additions & 26 deletions tests/Obsidian/__test_data__/yaml_all_property_types_empty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const yaml_all_property_types_empty = {
'sample_link_property: \n' +
'sample_link_list_property: \n' +
'aliases: \n' +
'tags:\n' +
'tags: \n' +
'creation date:\n' +
'---\n' +
'# yaml_all_property_types_empty\n' +
'\n' +
Expand All @@ -21,14 +22,14 @@ export const yaml_all_property_types_empty = {
{
position: {
start: {
line: 14,
line: 15,
col: 6,
offset: 267,
offset: 283,
},
end: {
line: 14,
line: 15,
col: 11,
offset: 272,
offset: 288,
},
},
tag: '#task',
Expand All @@ -38,14 +39,14 @@ export const yaml_all_property_types_empty = {
{
position: {
start: {
line: 12,
line: 13,
col: 0,
offset: 228,
offset: 244,
},
end: {
line: 12,
line: 13,
col: 31,
offset: 259,
offset: 275,
},
},
heading: 'yaml_all_property_types_empty',
Expand All @@ -62,39 +63,39 @@ export const yaml_all_property_types_empty = {
offset: 0,
},
end: {
line: 11,
line: 12,
col: 3,
offset: 227,
offset: 243,
},
},
},
{
type: 'heading',
position: {
start: {
line: 12,
line: 13,
col: 0,
offset: 228,
offset: 244,
},
end: {
line: 12,
line: 13,
col: 31,
offset: 259,
offset: 275,
},
},
},
{
type: 'list',
position: {
start: {
line: 14,
line: 15,
col: 0,
offset: 261,
offset: 277,
},
end: {
line: 14,
line: 15,
col: 51,
offset: 312,
offset: 328,
},
},
},
Expand All @@ -103,17 +104,17 @@ export const yaml_all_property_types_empty = {
{
position: {
start: {
line: 14,
line: 15,
col: 0,
offset: 261,
offset: 277,
},
end: {
line: 14,
line: 15,
col: 51,
offset: 312,
offset: 328,
},
},
parent: -14,
parent: -15,
task: ' ',
},
],
Expand All @@ -128,6 +129,7 @@ export const yaml_all_property_types_empty = {
sample_link_list_property: null,
aliases: null,
tags: null,
'creation date': null,
},
frontmatterPosition: {
start: {
Expand All @@ -136,9 +138,9 @@ export const yaml_all_property_types_empty = {
offset: 0,
},
end: {
line: 11,
line: 12,
col: 3,
offset: 227,
offset: 243,
},
},
frontmatterLinks: [],
Expand Down
52 changes: 27 additions & 25 deletions tests/Obsidian/__test_data__/yaml_all_property_types_populated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const yaml_all_property_types_populated = {
' - YAML All Property Types Populated\n' +
'tags:\n' +
' - sample/tag/value\n' +
'creation date: 2024-05-25T15:17:00\n' +
'---\n' +
'\n' +
'# yaml_all_property_types_populated\n' +
Expand All @@ -29,14 +30,14 @@ export const yaml_all_property_types_populated = {
{
position: {
start: {
line: 22,
line: 23,
col: 6,
offset: 534,
offset: 569,
},
end: {
line: 22,
line: 23,
col: 11,
offset: 539,
offset: 574,
},
},
tag: '#task',
Expand All @@ -46,14 +47,14 @@ export const yaml_all_property_types_populated = {
{
position: {
start: {
line: 20,
line: 21,
col: 0,
offset: 491,
offset: 526,
},
end: {
line: 20,
line: 21,
col: 35,
offset: 526,
offset: 561,
},
},
heading: 'yaml_all_property_types_populated',
Expand All @@ -70,39 +71,39 @@ export const yaml_all_property_types_populated = {
offset: 0,
},
end: {
line: 18,
line: 19,
col: 3,
offset: 489,
offset: 524,
},
},
},
{
type: 'heading',
position: {
start: {
line: 20,
line: 21,
col: 0,
offset: 491,
offset: 526,
},
end: {
line: 20,
line: 21,
col: 35,
offset: 526,
offset: 561,
},
},
},
{
type: 'list',
position: {
start: {
line: 22,
line: 23,
col: 0,
offset: 528,
offset: 563,
},
end: {
line: 22,
line: 23,
col: 55,
offset: 583,
offset: 618,
},
},
},
Expand All @@ -111,17 +112,17 @@ export const yaml_all_property_types_populated = {
{
position: {
start: {
line: 22,
line: 23,
col: 0,
offset: 528,
offset: 563,
},
end: {
line: 22,
line: 23,
col: 55,
offset: 583,
offset: 618,
},
},
parent: -22,
parent: -23,
task: ' ',
},
],
Expand All @@ -136,6 +137,7 @@ export const yaml_all_property_types_populated = {
sample_link_list_property: ['[[yaml_all_property_types_populated]]', '[[yaml_all_property_types_empty]]'],
aliases: ['YAML All Property Types Populated'],
tags: ['sample/tag/value'],
'creation date': '2024-05-25T15:17:00',
},
frontmatterPosition: {
start: {
Expand All @@ -144,9 +146,9 @@ export const yaml_all_property_types_populated = {
offset: 0,
},
end: {
line: 18,
line: 19,
col: 3,
offset: 489,
offset: 524,
},
},
frontmatterLinks: [
Expand Down
Loading