Skip to content

Commit 56ba5a5

Browse files
committed
test: - Make toMatchTaskWithPath() examples more realistic
1 parent 5ef3145 commit 56ba5a5

File tree

5 files changed

+31
-27
lines changed

5 files changed

+31
-27
lines changed

tests/CustomMatchers/CustomMatchersForFilters.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ export function toMatchTaskWithHeading(filter: FilterOrErrorMessage, heading: st
205205
}
206206

207207
export function toMatchTaskWithPath(filter: FilterOrErrorMessage, path: string) {
208+
// Validate the path supplied. Obsidian vault paths do not begin with a '/',
209+
// so check for any unrealistic examples in tests:
210+
expect(path[0]).not.toBe('/');
211+
208212
const builder = new TaskBuilder();
209213
const task = builder.path(path).build();
210214
return toMatchTask(filter, task);

tests/Query/Filter/FilenameField.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ describe('filename', () => {
3232
// Assert
3333
expect(filter).toBeValid();
3434
expect(filter).not.toMatchTaskWithPath('');
35-
expect(filter).toMatchTaskWithPath('/some/path/SeArch_Text.md');
36-
expect(filter).not.toMatchTaskWithPath('/other/search_text/file.md'); // Ignores text in folder names
35+
expect(filter).toMatchTaskWithPath('some/path/SeArch_Text.md');
36+
expect(filter).not.toMatchTaskWithPath('other/search_text/file.md'); // Ignores text in folder names
3737
});
3838

3939
it('by filename (does not include)', () => {
@@ -43,8 +43,8 @@ describe('filename', () => {
4343
// Assert
4444
expect(filter).toBeValid();
4545
expect(filter).toMatchTaskWithPath('');
46-
expect(filter).toMatchTaskWithPath('/other/search_text/file.md'); // Ignores text in folder names
47-
expect(filter).not.toMatchTaskWithPath('/SoMe/PaTh/SeArcH_Text.md');
46+
expect(filter).toMatchTaskWithPath('other/search_text/file.md'); // Ignores text in folder names
47+
expect(filter).not.toMatchTaskWithPath('SoMe/PaTh/SeArcH_Text.md');
4848
});
4949

5050
it('by filename (regex matches)', () => {
@@ -53,8 +53,8 @@ describe('filename', () => {
5353

5454
// Assert
5555
expect(filter).toBeValid();
56-
expect(filter).toMatchTaskWithPath('/some/path/wibble.md');
57-
expect(filter).not.toMatchTaskWithPath('/some/wibble/filename.md');
56+
expect(filter).toMatchTaskWithPath('some/path/wibble.md');
57+
expect(filter).not.toMatchTaskWithPath('some/wibble/filename.md');
5858
});
5959

6060
it('by filename (regex does not match)', () => {
@@ -65,8 +65,8 @@ describe('filename', () => {
6565

6666
// Assert
6767
expect(filter).toBeValid();
68-
expect(filter).toMatchTaskWithPath('/some/wobble/path name.md');
69-
expect(filter).not.toMatchTaskWithPath('/some/path/wibble.md');
68+
expect(filter).toMatchTaskWithPath('some/wobble/path name.md');
69+
expect(filter).not.toMatchTaskWithPath('some/path/wibble.md');
7070
});
7171
});
7272

tests/Query/Filter/FolderField.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ describe('folder', () => {
2626
// Assert
2727
expect(filter).toBeValid();
2828
expect(filter).not.toMatchTaskWithPath('');
29-
expect(filter).toMatchTaskWithPath('/some/SeArch_Text/some file name.md');
30-
expect(filter).not.toMatchTaskWithPath('/other/folder/search_text.md'); // Ignores text in file names
29+
expect(filter).toMatchTaskWithPath('some/SeArch_Text/some file name.md');
30+
expect(filter).not.toMatchTaskWithPath('other/folder/search_text.md'); // Ignores text in file names
3131
});
3232
});
3333

tests/Query/Filter/PathField.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ describe('path', () => {
4343

4444
// Assert
4545
expect(filter).toBeValid();
46-
expect(filter).toMatchTaskWithPath('/some/path/wibble.md');
47-
expect(filter).toMatchTaskWithPath('/some/path/wobble.md');
46+
expect(filter).toMatchTaskWithPath('some/path/wibble.md');
47+
expect(filter).toMatchTaskWithPath('some/path/wobble.md');
4848
expect(filter).not.toMatchTaskWithPath('');
49-
expect(filter).not.toMatchTaskWithPath('/some/path/WobblE.md'); // confirm case-sensitive
50-
expect(filter).not.toMatchTaskWithPath('/other/path/file.md');
49+
expect(filter).not.toMatchTaskWithPath('some/path/WobblE.md'); // confirm case-sensitive
50+
expect(filter).not.toMatchTaskWithPath('other/path/file.md');
5151
});
5252

5353
it('by path (regex matches) with flags', () => {
@@ -56,11 +56,11 @@ describe('path', () => {
5656

5757
// Assert
5858
expect(filter).toBeValid();
59-
expect(filter).toMatchTaskWithPath('/some/path/wibble.md');
60-
expect(filter).toMatchTaskWithPath('/some/path/wobble.md');
59+
expect(filter).toMatchTaskWithPath('some/path/wibble.md');
60+
expect(filter).toMatchTaskWithPath('some/path/wobble.md');
6161
expect(filter).not.toMatchTaskWithPath('');
62-
expect(filter).toMatchTaskWithPath('/some/path/WobblE.md'); // confirm case-insensitive (flag)
63-
expect(filter).not.toMatchTaskWithPath('/other/path/file.md');
62+
expect(filter).toMatchTaskWithPath('some/path/WobblE.md'); // confirm case-insensitive (flag)
63+
expect(filter).not.toMatchTaskWithPath('other/path/file.md');
6464
});
6565

6666
it('by path (regex does not match)', () => {
@@ -69,11 +69,11 @@ describe('path', () => {
6969

7070
// Assert
7171
expect(filter).toBeValid();
72-
expect(filter).not.toMatchTaskWithPath('/some/path/wibble.md');
73-
expect(filter).not.toMatchTaskWithPath('/some/path/wobble.md');
72+
expect(filter).not.toMatchTaskWithPath('some/path/wibble.md');
73+
expect(filter).not.toMatchTaskWithPath('some/path/wobble.md');
7474
expect(filter).toMatchTaskWithPath('');
75-
expect(filter).toMatchTaskWithPath('/some/path/WobblE.md'); // confirm case-sensitive
76-
expect(filter).toMatchTaskWithPath('/other/path/file.md');
75+
expect(filter).toMatchTaskWithPath('some/path/WobblE.md'); // confirm case-sensitive
76+
expect(filter).toMatchTaskWithPath('other/path/file.md');
7777
});
7878
});
7979

@@ -88,8 +88,8 @@ describe('should use whole path with un-escaped slashes in query', () => {
8888
});
8989

9090
it('should match the requested path', () => {
91-
expect(filterWithUnescapedSlashes).toMatchTaskWithPath('/a/b/c/d/e.md');
92-
expect(filterWithUnescapedSlashes).not.toMatchTaskWithPath('/a/b.md');
91+
expect(filterWithUnescapedSlashes).toMatchTaskWithPath('a/b/c/d/e.md');
92+
expect(filterWithUnescapedSlashes).not.toMatchTaskWithPath('a/b.md');
9393
});
9494
});
9595

tests/Query/Filter/RootField.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ describe('root', () => {
2626
// Assert
2727
expect(filter).toBeValid();
2828
expect(filter).not.toMatchTaskWithPath('');
29-
expect(filter).toMatchTaskWithPath('/SeArch_Text/some folder name/some file name.md');
30-
expect(filter).not.toMatchTaskWithPath('/some root folder/SeArch_Text/search_text.md'); // Ignores text in child folder names
31-
expect(filter).not.toMatchTaskWithPath('/some root folder/folder/search_text.md'); // Ignores text in file names
29+
expect(filter).toMatchTaskWithPath('SeArch_Text/some folder name/some file name.md');
30+
expect(filter).not.toMatchTaskWithPath('some root folder/SeArch_Text/search_text.md'); // Ignores text in child folder names
31+
expect(filter).not.toMatchTaskWithPath('some root folder/folder/search_text.md'); // Ignores text in file names
3232
});
3333
});
3434

0 commit comments

Comments
 (0)