Files
privacy.sexy/tests/unit/shared/Stubs/CategoryCollectionStateStub.ts
undergroundwires 6142f3a297 Extend search by including documentation content
This commit broadens the search functionality within privacy.sexy by
including documentation text in the search scope. Users can now find
scripts and categories not only by their names but also by content in
their documentation. This improvement aims to make the discovery of
relevant scripts and information more intuitive and comprehensive.

Key changes:

- Documentation text is now searchable, enhancing the ability to
  discover scripts and categories based on content details.

Other supporting changes:

- Remove interface prefixes (`I`) from related interfaces to adhere to
  naming conventions, enhancing code readability.
- Refactor filtering to separate actual filtering logic from filter
  state management, improving the structure for easier maintenance.
- Improve test coverage to ensure relability of existing and new search
  capabilities.
- Test coverage expanded to ensure the reliability of the new search
  capabilities.
2024-02-14 12:10:49 +01:00

77 lines
2.7 KiB
TypeScript

import { IApplicationCode } from '@/application/Context/State/Code/IApplicationCode';
import { ICategoryCollectionState } from '@/application/Context/State/ICategoryCollectionState';
import { OperatingSystem } from '@/domain/OperatingSystem';
import { IScript } from '@/domain/IScript';
import { ScriptStub } from '@tests/unit/shared/Stubs/ScriptStub';
import { ICategoryCollection } from '@/domain/ICategoryCollection';
import { UserSelection } from '@/application/Context/State/Selection/UserSelection';
import { SelectedScript } from '@/application/Context/State/Selection/Script/SelectedScript';
import { FilterContext } from '@/application/Context/State/Filter/FilterContext';
import { CategoryCollectionStub } from './CategoryCollectionStub';
import { UserSelectionStub } from './UserSelectionStub';
import { FilterContextStub } from './FilterContextStub';
import { ApplicationCodeStub } from './ApplicationCodeStub';
import { CategoryStub } from './CategoryStub';
import { ScriptSelectionStub } from './ScriptSelectionStub';
export class CategoryCollectionStateStub implements ICategoryCollectionState {
public code: IApplicationCode = new ApplicationCodeStub();
public filter: FilterContext = new FilterContextStub();
public get os(): OperatingSystem {
return this.collection.os;
}
public collection: ICategoryCollection = new CategoryCollectionStub().withSomeActions();
public selection: UserSelection = new UserSelectionStub();
constructor(readonly allScripts: IScript[] = [new ScriptStub('script-id')]) {
this.selection = new UserSelectionStub()
.withScripts(new ScriptSelectionStub());
this.collection = new CategoryCollectionStub()
.withOs(this.os)
.withTotalScripts(this.allScripts.length)
.withAction(new CategoryStub(0).withScripts(...allScripts));
}
public withCollection(collection: ICategoryCollection): this {
this.collection = collection;
return this;
}
public withCode(code: IApplicationCode): this {
this.code = code;
return this;
}
public withOs(os: OperatingSystem): this {
if (this.collection instanceof CategoryCollectionStub) {
this.collection = this.collection.withOs(os);
} else {
this.collection = new CategoryCollectionStub().withOs(os);
}
return this;
}
public withFilter(filter: FilterContext): this {
this.filter = filter;
return this;
}
public withSelectedScripts(initialScripts: readonly SelectedScript[]): this {
return this.withSelection(
new UserSelectionStub().withScripts(
new ScriptSelectionStub()
.withSelectedScripts(initialScripts),
),
);
}
public withSelection(selection: UserSelection): this {
this.selection = selection;
return this;
}
}