Files
privacy.sexy/tests/unit/shared/Stubs/UseUserSelectionStateStub.ts
undergroundwires a721e82a4f Bump TypeScript to 5.3 with verbatimModuleSyntax
This commit upgrades TypeScript to the latest version 5.3 and introduces
`verbatimModuleSyntax` in line with the official Vue guide
recommendatinos (vuejs/docs#2592).

By enforcing `import type` for type-only imports, this commit improves
code clarity and supports tooling optimization, ensuring imports are
only bundled when necessary for runtime.

Changes:

- Bump TypeScript to 5.3.3 across the project.
- Adjust import statements to utilize `import type` where applicable,
  promoting cleaner and more efficient code.
2024-02-27 04:20:22 +01:00

53 lines
1.8 KiB
TypeScript

import { shallowRef } from 'vue';
import type { SelectionModifier, useUserSelectionState } from '@/presentation/components/Shared/Hooks/UseUserSelectionState';
import type { UserSelection } from '@/application/Context/State/Selection/UserSelection';
import type { SelectedScript } from '@/application/Context/State/Selection/Script/SelectedScript';
import { StubWithObservableMethodCalls } from './StubWithObservableMethodCalls';
import { UserSelectionStub } from './UserSelectionStub';
import { ScriptSelectionStub } from './ScriptSelectionStub';
export class UseUserSelectionStateStub
extends StubWithObservableMethodCalls<ReturnType<typeof useUserSelectionState>> {
private readonly currentSelection = shallowRef<UserSelection>(
new UserSelectionStub(),
);
private modifyCurrentSelection(mutator: SelectionModifier) {
mutator(this.currentSelection.value);
this.registerMethodCall({
methodName: 'modifyCurrentSelection',
args: [mutator],
});
}
public withUserSelection(userSelection: UserSelection): this {
this.currentSelection.value = userSelection;
return this;
}
public withSelectedScripts(selectedScripts: readonly SelectedScript[]): this {
return this.withUserSelection(
new UserSelectionStub()
.withScripts(
new ScriptSelectionStub().withSelectedScripts(selectedScripts),
),
);
}
public get selection(): UserSelection {
return this.currentSelection.value;
}
public isSelectionModified(): boolean {
const modifyCall = this.callHistory.find((call) => call.methodName === 'modifyCurrentSelection');
return modifyCall !== undefined;
}
public get(): ReturnType<typeof useUserSelectionState> {
return {
currentSelection: this.currentSelection,
modifyCurrentSelection: this.modifyCurrentSelection.bind(this),
};
}
}