mirror of
https://github.com/callumalpass/tasknotes.git
synced 2026-07-22 12:50:26 +00:00
Ensures the fix for #776 doesn't regress by testing that: - Valid string tags work correctly - Non-string values (numbers, booleans, objects, arrays) are safely skipped - Mixed arrays with both string and non-string values are handled - Empty arrays and all-non-string arrays return false appropriately
119 lines
No EOL
2.8 KiB
TypeScript
119 lines
No EOL
2.8 KiB
TypeScript
import { MinimalNativeCache } from '../../src/utils/MinimalNativeCache';
|
|
import { TaskNotesSettings } from '../../src/types/settings';
|
|
|
|
// Mock FilterUtils
|
|
jest.mock('../../src/utils/FilterUtils', () => ({
|
|
FilterUtils: {
|
|
matchesHierarchicalTagExact: jest.fn((tag: string, taskTag: string) => {
|
|
return tag.toLowerCase() === taskTag.toLowerCase();
|
|
}),
|
|
},
|
|
}));
|
|
|
|
describe('MinimalNativeCache - isTaskFile with non-string tags', () => {
|
|
let cache: MinimalNativeCache;
|
|
let mockApp: any;
|
|
let settings: TaskNotesSettings;
|
|
|
|
beforeEach(() => {
|
|
mockApp = {
|
|
metadataCache: {
|
|
on: jest.fn(),
|
|
},
|
|
vault: {
|
|
on: jest.fn(),
|
|
},
|
|
};
|
|
|
|
settings = {
|
|
taskTag: 'task',
|
|
taskIdentificationMethod: 'tag',
|
|
excludedFolders: '',
|
|
disableNoteIndexing: false,
|
|
storeTitleInFilename: false,
|
|
} as TaskNotesSettings;
|
|
|
|
cache = new MinimalNativeCache(mockApp, settings);
|
|
});
|
|
|
|
test('handles frontmatter with valid string tags', () => {
|
|
const frontmatter = {
|
|
tags: ['task', 'project', 'important'],
|
|
};
|
|
|
|
const result = (cache as any).isTaskFile(frontmatter);
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test('handles frontmatter with number in tags array', () => {
|
|
const frontmatter = {
|
|
tags: ['task', 123, 'project'],
|
|
};
|
|
|
|
const result = (cache as any).isTaskFile(frontmatter);
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test('handles frontmatter with boolean in tags array', () => {
|
|
const frontmatter = {
|
|
tags: [true, 'task', false],
|
|
};
|
|
|
|
const result = (cache as any).isTaskFile(frontmatter);
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test('handles frontmatter with mixed non-string types', () => {
|
|
const frontmatter = {
|
|
tags: [123, true, 'task', null, undefined, 'project'],
|
|
};
|
|
|
|
const result = (cache as any).isTaskFile(frontmatter);
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test('returns false when all tags are non-strings', () => {
|
|
const frontmatter = {
|
|
tags: [123, true, null, undefined, 456],
|
|
};
|
|
|
|
const result = (cache as any).isTaskFile(frontmatter);
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test('handles frontmatter with object in tags array', () => {
|
|
const frontmatter = {
|
|
tags: [{ nested: 'value' }, 'task'],
|
|
};
|
|
|
|
const result = (cache as any).isTaskFile(frontmatter);
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test('handles frontmatter with array in tags array', () => {
|
|
const frontmatter = {
|
|
tags: [['nested', 'array'], 'task'],
|
|
};
|
|
|
|
const result = (cache as any).isTaskFile(frontmatter);
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test('handles empty tags array', () => {
|
|
const frontmatter = {
|
|
tags: [],
|
|
};
|
|
|
|
const result = (cache as any).isTaskFile(frontmatter);
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test('handles nested tag hierarchy with non-strings', () => {
|
|
const frontmatter = {
|
|
tags: ['task', 123, 'other/tag'],
|
|
};
|
|
|
|
const result = (cache as any).isTaskFile(frontmatter);
|
|
expect(result).toBe(true);
|
|
});
|
|
}); |