diff --git a/src/Query/QueryResult.ts b/src/Query/QueryResult.ts index 7c78280fbd..1776d32549 100644 --- a/src/Query/QueryResult.ts +++ b/src/Query/QueryResult.ts @@ -44,7 +44,7 @@ export class QueryResult { } static fromError(message: string): QueryResult { - const result = new QueryResult(new TaskGroups([], [], new SearchInfo(undefined, [])), 0); + const result = new QueryResult(new TaskGroups([], [], SearchInfo.fromAllTasks([])), 0); result._searchErrorMessage = message; return result; } diff --git a/src/Query/SearchInfo.ts b/src/Query/SearchInfo.ts index 9a87c327fa..d38e4073c0 100644 --- a/src/Query/SearchInfo.ts +++ b/src/Query/SearchInfo.ts @@ -18,7 +18,7 @@ export class SearchInfo { this.allTasks = [...allTasks]; } - public static fromAllTasks(tasks: Task[]) { + public static fromAllTasks(tasks: Task[]): SearchInfo { return new SearchInfo(undefined, tasks); } } diff --git a/tests/CustomMatchers/CustomMatchersForFilters.test.ts b/tests/CustomMatchers/CustomMatchersForFilters.test.ts index ff626a0f7c..477f63bbf3 100644 --- a/tests/CustomMatchers/CustomMatchersForFilters.test.ts +++ b/tests/CustomMatchers/CustomMatchersForFilters.test.ts @@ -9,7 +9,7 @@ describe('CustomMatchersForFilters', () => { it('should check filter with supplied SearchInfo', () => { // Arrange const task = new TaskBuilder().build(); - const initialSearchInfo = new SearchInfo(undefined, [task]); + const initialSearchInfo = SearchInfo.fromAllTasks([task]); const checkSearchInfoPassedThrough = (_task: Task, searchInfo: SearchInfo) => { return Object.is(initialSearchInfo, searchInfo); }; diff --git a/tests/CustomMatchers/CustomMatchersForFilters.ts b/tests/CustomMatchers/CustomMatchersForFilters.ts index b58d283e49..7381e468c7 100644 --- a/tests/CustomMatchers/CustomMatchersForFilters.ts +++ b/tests/CustomMatchers/CustomMatchersForFilters.ts @@ -171,7 +171,7 @@ with filter: "${filter.instruction}"`, } export function toMatchTask(filter: FilterOrErrorMessage, task: Task) { - return toMatchTaskWithSearchInfo(filter, task, new SearchInfo(undefined, [task])); + return toMatchTaskWithSearchInfo(filter, task, SearchInfo.fromAllTasks([task])); } export function toMatchTaskFromLine(filter: FilterOrErrorMessage, line: string) { diff --git a/tests/CustomMatchers/CustomMatchersForGrouping.ts b/tests/CustomMatchers/CustomMatchersForGrouping.ts index 57fc09b92b..b0e2406d5e 100644 --- a/tests/CustomMatchers/CustomMatchersForGrouping.ts +++ b/tests/CustomMatchers/CustomMatchersForGrouping.ts @@ -55,7 +55,7 @@ export function toSupportGroupingWithProperty(field: Field, property: string) { * @param tasks */ export function groupHeadingsForTask(grouper: Grouper, tasks: Task[]) { - const groups = new TaskGroups([grouper], tasks, new SearchInfo(undefined, tasks)); + const groups = new TaskGroups([grouper], tasks, SearchInfo.fromAllTasks(tasks)); const headings: string[] = []; groups.groups.forEach((taskGroup) => { @@ -99,7 +99,7 @@ export function toGroupTask(grouper: Grouper | null, task: Task, expectedGroupNa }; } - expect(grouper!.grouper(task, new SearchInfo(undefined, [task]))).toEqual(expectedGroupNames); + expect(grouper!.grouper(task, SearchInfo.fromAllTasks([task]))).toEqual(expectedGroupNames); } /** diff --git a/tests/DocumentationSamples/DocsSamplesForStatuses.test.ts b/tests/DocumentationSamples/DocsSamplesForStatuses.test.ts index 14ebd85b5a..94aa87db5a 100644 --- a/tests/DocumentationSamples/DocsSamplesForStatuses.test.ts +++ b/tests/DocumentationSamples/DocsSamplesForStatuses.test.ts @@ -228,7 +228,7 @@ function verifyTransitionsAsMarkdownTable(statuses: Status[]) { function filterAllStatuses(filter: FilterOrErrorMessage) { const cells: string[] = [`Matches \`${filter!.instruction}\``]; - const searchInfo = new SearchInfo(undefined, tasks); + const searchInfo = SearchInfo.fromAllTasks(tasks); tasks.forEach((task) => { const matchedText = filter!.filter?.filterFunction(task, searchInfo) ? 'YES' : 'no'; cells.push(matchedText); @@ -251,7 +251,7 @@ function verifyTransitionsAsMarkdownTable(statuses: Status[]) { function showGroupNamesForAllTasks(groupName: string, grouperFunction: GrouperFunction) { const cells: string[] = ['Name for `group by ' + groupName + '`']; tasks.forEach((task) => { - const groupNamesForTask = grouperFunction(task, new SearchInfo(undefined, [task])); + const groupNamesForTask = grouperFunction(task, SearchInfo.fromAllTasks([task])); const names = groupNamesForTask.join(','); cells.push(names); }); diff --git a/tests/Query.test.ts b/tests/Query.test.ts index 78311586eb..ccbf1eaa16 100644 --- a/tests/Query.test.ts +++ b/tests/Query.test.ts @@ -209,7 +209,7 @@ describe('Query parsing', () => { expect(query.filters.length).toEqual(1); expect(query.filters[0]).toBeDefined(); // If the boolean query and its sub-query are parsed correctly, the expression should always be true - expect(query.filters[0].filterFunction(task, new SearchInfo(undefined, [task]))).toBeTruthy(); + expect(query.filters[0].filterFunction(task, SearchInfo.fromAllTasks([task]))).toBeTruthy(); }); }); @@ -619,7 +619,7 @@ describe('Query', () => { // Act let filteredTasks = [...tasks]; - const searchInfo = new SearchInfo(undefined, tasks); + const searchInfo = SearchInfo.fromAllTasks(tasks); query.filters.forEach((filter) => { filteredTasks = filteredTasks.filter((task) => filter.filterFunction(task, searchInfo)); }); @@ -1063,7 +1063,7 @@ describe('Query', () => { ); // Act, Assert - const searchInfo = new SearchInfo(undefined, allTasks); + const searchInfo = SearchInfo.fromAllTasks(allTasks); expect(filter).toMatchTaskWithSearchInfo(same1, searchInfo); expect(filter).toMatchTaskWithSearchInfo(same2, searchInfo); expect(filter).not.toMatchTaskWithSearchInfo(different, searchInfo); diff --git a/tests/Query/Filter/FunctionField.test.ts b/tests/Query/Filter/FunctionField.test.ts index 37f3110b13..122a14be66 100644 --- a/tests/Query/Filter/FunctionField.test.ts +++ b/tests/Query/Filter/FunctionField.test.ts @@ -45,7 +45,7 @@ describe('FunctionField - filtering', () => { expect(filter).toBeValid(); const t = () => { const task = new TaskBuilder().build(); - filter.filterFunction!(task, new SearchInfo(undefined, [task])); + filter.filterFunction!(task, SearchInfo.fromAllTasks([task])); }; expect(t).toThrow(Error); expect(t).toThrowError('filtering function must return true or false. This returned "undefined".'); diff --git a/tests/Query/Filter/TagsField.test.ts b/tests/Query/Filter/TagsField.test.ts index de524793df..e3b30c6d14 100644 --- a/tests/Query/Filter/TagsField.test.ts +++ b/tests/Query/Filter/TagsField.test.ts @@ -653,7 +653,7 @@ describe('grouping by tag', () => { // Act const grouping: Grouper[] = [new TagsField().createGrouperFromLine('group by tags reverse')!]; - const groups = new TaskGroups(grouping, inputs, new SearchInfo(undefined, inputs)); + const groups = new TaskGroups(grouping, inputs, SearchInfo.fromAllTasks(inputs)); // Assert expect(groups.toString()).toMatchInlineSnapshot(` diff --git a/tests/Query/QueryResult.test.ts b/tests/Query/QueryResult.test.ts index a407f9699a..cd796b6395 100644 --- a/tests/Query/QueryResult.test.ts +++ b/tests/Query/QueryResult.test.ts @@ -12,7 +12,7 @@ describe('QueryResult', () => { function createUngroupedQueryResultWithLimit(tasks: Task[], totalTasksCountBeforeLimit: number) { const groupers: Grouper[] = []; - const groups = new TaskGroups(groupers, tasks, new SearchInfo(undefined, tasks)); + const groups = new TaskGroups(groupers, tasks, SearchInfo.fromAllTasks(tasks)); return new QueryResult(groups, totalTasksCountBeforeLimit); } @@ -20,7 +20,7 @@ describe('QueryResult', () => { // Arrange const groupers: Grouper[] = []; const tasks: Task[] = []; - const groups = new TaskGroups(groupers, tasks, new SearchInfo(undefined, tasks)); + const groups = new TaskGroups(groupers, tasks, SearchInfo.fromAllTasks(tasks)); // Act const queryResult = new QueryResult(groups, 0); diff --git a/tests/Query/SearchInfo.test.ts b/tests/Query/SearchInfo.test.ts index f660ecd05b..f8806c9f53 100644 --- a/tests/Query/SearchInfo.test.ts +++ b/tests/Query/SearchInfo.test.ts @@ -16,7 +16,7 @@ describe('SearchInfo', () => { it('should not be able to modify SearchInfo.allTasks indirectly', () => { const tasks = [new TaskBuilder().build()]; - const searchInfo = new SearchInfo(undefined, tasks); + const searchInfo = SearchInfo.fromAllTasks(tasks); // Check that updating the original list of tasks does not change the tasks saved in searchInfo.allTasks tasks.push(new TaskBuilder().description('I should not be added to searchInfo.allTasks').build()); diff --git a/tests/Scripting/ScriptingReference/VerifyFunctionFieldSamples.ts b/tests/Scripting/ScriptingReference/VerifyFunctionFieldSamples.ts index 331d73f04e..c61d108e3c 100644 --- a/tests/Scripting/ScriptingReference/VerifyFunctionFieldSamples.ts +++ b/tests/Scripting/ScriptingReference/VerifyFunctionFieldSamples.ts @@ -91,7 +91,7 @@ export function verifyFunctionFieldFilterSamplesOnTasks(filters: QueryInstructio const filterFunction = filterOrErrorMessage.filterFunction!; const matchingTasks: string[] = []; - const searchInfo = new SearchInfo(undefined, tasks); + const searchInfo = SearchInfo.fromAllTasks(tasks); for (const task of tasks) { const matches = filterFunction(task, searchInfo); if (matches) { diff --git a/tests/TaskGroups.test.ts b/tests/TaskGroups.test.ts index af2dd4343a..9c37ecd9f9 100644 --- a/tests/TaskGroups.test.ts +++ b/tests/TaskGroups.test.ts @@ -18,7 +18,7 @@ import { fromLine } from './TestHelpers'; window.moment = moment; function makeTasksGroups(grouping: Grouper[], inputs: Task[]): any { - return new TaskGroups(grouping, inputs, new SearchInfo(undefined, inputs)); + return new TaskGroups(grouping, inputs, SearchInfo.fromAllTasks(inputs)); } describe('Grouping tasks', () => { diff --git a/tests/TestingTools/FilterTestHelpers.ts b/tests/TestingTools/FilterTestHelpers.ts index f0b15dea17..1d7b4ebec7 100644 --- a/tests/TestingTools/FilterTestHelpers.ts +++ b/tests/TestingTools/FilterTestHelpers.ts @@ -28,7 +28,7 @@ export function testFilter(filter: FilterOrErrorMessage, taskBuilder: TaskBuilde export function testTaskFilter(filter: FilterOrErrorMessage, task: Task, expected: boolean) { expect(filter.filterFunction).toBeDefined(); expect(filter.error).toBeUndefined(); - expect(filter.filterFunction!(task, new SearchInfo(undefined, [task]))).toEqual(expected); + expect(filter.filterFunction!(task, SearchInfo.fromAllTasks([task]))).toEqual(expected); } /** @@ -50,7 +50,7 @@ export function testTaskFilterViaQuery(filter: string, task: Task, expected: boo // Act let filteredTasks = [...tasks]; - const searchInfo = new SearchInfo(undefined, tasks); + const searchInfo = SearchInfo.fromAllTasks(tasks); query.filters.forEach((filter) => { filteredTasks = filteredTasks.filter((task) => filter.filterFunction(task, searchInfo)); }); @@ -85,7 +85,7 @@ export function shouldSupportFiltering( // Act let filteredTasks = [...tasks]; - const searchInfo = new SearchInfo(undefined, tasks); + const searchInfo = SearchInfo.fromAllTasks(tasks); query.filters.forEach((filter) => { filteredTasks = filteredTasks.filter((task) => filter.filterFunction(task, searchInfo)); });