fix script revert activating recommendation level
Reverting any single of the scripts from standard recommendation pool shows "Standard" selection as selected which is wrong. This commit fixes it, refactors selection handling in a separate class and it also adds missing tests. It removes UserSelection.totalSelected propertty in favor of using UserSelection.selectedScripts.length to provide unified way of accessing the information.
This commit is contained in:
9
tests/unit/stubs/ApplicationCodeStub.ts
Normal file
9
tests/unit/stubs/ApplicationCodeStub.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { ICodeChangedEvent } from '@/application/Context/State/Code/Event/ICodeChangedEvent';
|
||||
import { IApplicationCode } from '@/application/Context/State/Code/IApplicationCode';
|
||||
import { IEventSource } from '@/infrastructure/Events/IEventSource';
|
||||
import { EventSource } from '@/infrastructure/Events/EventSource';
|
||||
|
||||
export class ApplicationCodeStub implements IApplicationCode {
|
||||
public changed: IEventSource<ICodeChangedEvent> = new EventSource<ICodeChangedEvent>();
|
||||
public current: string = '';
|
||||
}
|
||||
30
tests/unit/stubs/CategoryCollectionStateStub.ts
Normal file
30
tests/unit/stubs/CategoryCollectionStateStub.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { IApplicationCode } from '@/application/Context/State/Code/IApplicationCode';
|
||||
import { IUserFilter } from '@/application/Context/State/Filter/IUserFilter';
|
||||
import { ICategoryCollectionState } from '@/application/Context/State/ICategoryCollectionState';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { CategoryCollectionStub } from './CategoryCollectionStub';
|
||||
import { UserSelectionStub } from './UserSelectionStub';
|
||||
import { UserFilterStub } from './UserFilterStub';
|
||||
import { ApplicationCodeStub } from './ApplicationCodeStub';
|
||||
import { SelectedScript } from '@/application/Context/State/Selection/SelectedScript';
|
||||
import { IScript } from '@/domain/IScript';
|
||||
import { CategoryStub } from './CategoryStub';
|
||||
|
||||
export class CategoryCollectionStateStub implements ICategoryCollectionState {
|
||||
public readonly code: IApplicationCode = new ApplicationCodeStub();
|
||||
public readonly filter: IUserFilter = new UserFilterStub();
|
||||
public readonly os = OperatingSystem.Windows;
|
||||
public readonly collection: CategoryCollectionStub;
|
||||
public readonly selection: UserSelectionStub;
|
||||
constructor(readonly allScripts: IScript[]) {
|
||||
this.selection = new UserSelectionStub(allScripts);
|
||||
this.collection = new CategoryCollectionStub()
|
||||
.withOs(this.os)
|
||||
.withTotalScripts(this.allScripts.length)
|
||||
.withAction(new CategoryStub(0).withScripts(...allScripts));
|
||||
}
|
||||
public withSelectedScripts(initialScripts: readonly SelectedScript[]) {
|
||||
this.selection.withSelectedScripts(initialScripts);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { ICategory } from '@/domain/ICategory';
|
||||
import { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import { ScriptStub } from './ScriptStub';
|
||||
import { ScriptingDefinitionStub } from './ScriptingDefinitionStub';
|
||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
|
||||
export class CategoryCollectionStub implements ICategoryCollection {
|
||||
public scripting: IScriptingDefinition = new ScriptingDefinitionStub();
|
||||
@@ -36,14 +37,16 @@ export class CategoryCollectionStub implements ICategoryCollection {
|
||||
}
|
||||
|
||||
public findCategory(categoryId: number): ICategory {
|
||||
return this.getAllCategories().find(
|
||||
(category) => category.id === categoryId);
|
||||
return this.getAllCategories()
|
||||
.find((category) => category.id === categoryId);
|
||||
}
|
||||
public getScriptsByLevel(): readonly IScript[] {
|
||||
throw new Error('Method not implemented: getScriptsByLevel');
|
||||
public getScriptsByLevel(level: RecommendationLevel): readonly IScript[] {
|
||||
return this.getAllScripts()
|
||||
.filter((script) => script.level !== undefined && script.level <= level);
|
||||
}
|
||||
public findScript(scriptId: string): IScript {
|
||||
return this.getAllScripts().find((script) => scriptId === script.id);
|
||||
return this.getAllScripts()
|
||||
.find((script) => scriptId === script.id);
|
||||
}
|
||||
public getAllScripts(): ReadonlyArray<IScript> {
|
||||
const scripts = [];
|
||||
@@ -79,9 +82,7 @@ function getSubCategoriesRecursively(category: ICategory): ReadonlyArray<ICatego
|
||||
function getScriptsRecursively(category: ICategory): ReadonlyArray<IScript> {
|
||||
const categoryScripts = [];
|
||||
if (category.scripts) {
|
||||
for (const script of category.scripts) {
|
||||
categoryScripts.push(script);
|
||||
}
|
||||
categoryScripts.push(...category.scripts);
|
||||
}
|
||||
if (category.subCategories) {
|
||||
for (const subCategory of category.subCategories) {
|
||||
|
||||
15
tests/unit/stubs/UserFilterStub.ts
Normal file
15
tests/unit/stubs/UserFilterStub.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { IFilterResult } from '@/application/Context/State/Filter/IFilterResult';
|
||||
import { IUserFilter } from '@/application/Context/State/Filter/IUserFilter';
|
||||
import { IEventSource } from '@/infrastructure/Events/IEventSource';
|
||||
|
||||
export class UserFilterStub implements IUserFilter {
|
||||
public currentFilter: IFilterResult;
|
||||
public filtered: IEventSource<IFilterResult>;
|
||||
public filterRemoved: IEventSource<void>;
|
||||
public setFilter(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
public removeFilter(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
}
|
||||
49
tests/unit/stubs/UserSelectionStub.ts
Normal file
49
tests/unit/stubs/UserSelectionStub.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { IUserSelection } from '@/application/Context/State/Selection/IUserSelection';
|
||||
import { SelectedScript } from '@/application/Context/State/Selection/SelectedScript';
|
||||
import { IScript } from '@/domain/IScript';
|
||||
import { IEventSource } from '@/infrastructure/Events/IEventSource';
|
||||
import { EventSource } from '@/infrastructure/Events/EventSource';
|
||||
|
||||
export class UserSelectionStub implements IUserSelection {
|
||||
public readonly changed: IEventSource<readonly SelectedScript[]> = new EventSource<readonly SelectedScript[]>();
|
||||
public selectedScripts: readonly SelectedScript[] = [];
|
||||
constructor(private readonly allScripts: readonly IScript[]) {
|
||||
|
||||
}
|
||||
public withSelectedScripts(selectedScripts: readonly SelectedScript[]) {
|
||||
this.selectedScripts = selectedScripts;
|
||||
}
|
||||
public areAllSelected(): boolean {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
public isAnySelected(): boolean {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
public removeAllInCategory(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
public addOrUpdateAllInCategory(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
public addSelectedScript(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
public addOrUpdateSelectedScript(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
public removeSelectedScript(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
public selectOnly(scripts: ReadonlyArray<IScript>): void {
|
||||
this.selectedScripts = scripts.map((s) => new SelectedScript(s, false));
|
||||
}
|
||||
public isSelected(): boolean {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
public selectAll(): void {
|
||||
this.selectOnly(this.allScripts);
|
||||
}
|
||||
public deselectAll(): void {
|
||||
this.selectedScripts = [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user