refactor to allow switching ICategoryCollection context #40
This commit is contained in:
28
tests/unit/stubs/ApplicationStub.ts
Normal file
28
tests/unit/stubs/ApplicationStub.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { IApplication } from '@/domain/IApplication';
|
||||
import { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { IProjectInformation } from '@/domain/IProjectInformation';
|
||||
import { ProjectInformationStub } from './ProjectInformationStub';
|
||||
|
||||
export class ApplicationStub implements IApplication {
|
||||
public info: IProjectInformation = new ProjectInformationStub();
|
||||
public collections: ICategoryCollection[] = [ ];
|
||||
public getCollection(operatingSystem: OperatingSystem): ICategoryCollection {
|
||||
return this.collections.find((collection) => collection.os === operatingSystem);
|
||||
}
|
||||
public getSupportedOsList(): OperatingSystem[] {
|
||||
return this.collections.map((collection) => collection.os);
|
||||
}
|
||||
public withCollection(collection: ICategoryCollection): ApplicationStub {
|
||||
this.collections.push(collection);
|
||||
return this;
|
||||
}
|
||||
public withProjectInformation(info: IProjectInformation): ApplicationStub {
|
||||
this.info = info;
|
||||
return this;
|
||||
}
|
||||
public withCollections(...collections: readonly ICategoryCollection[]): ApplicationStub {
|
||||
this.collections.push(...collections);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { ScriptingDefinitionStub } from './ScriptingDefinitionStub';
|
||||
import { ProjectInformation } from '@/domain/ProjectInformation';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { ScriptStub } from './ScriptStub';
|
||||
import { IScriptingDefinition } from '@/domain/IScriptingDefinition';
|
||||
@@ -13,7 +12,6 @@ export class CategoryCollectionStub implements ICategoryCollection {
|
||||
public initialScript: IScript = new ScriptStub('55');
|
||||
public totalScripts = 0;
|
||||
public totalCategories = 0;
|
||||
public readonly info = new ProjectInformation('StubApplication', '0.1.0', 'https://github.com/undergroundwires/privacy.sexy', 'https://privacy.sexy');
|
||||
public readonly actions = new Array<ICategory>();
|
||||
|
||||
public withAction(category: ICategory): CategoryCollectionStub {
|
||||
|
||||
11
tests/unit/stubs/EnvironmentStub.ts
Normal file
11
tests/unit/stubs/EnvironmentStub.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { IEnvironment } from '@/application/Environment/IEnvironment';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
export class EnvironmentStub implements IEnvironment {
|
||||
public isDesktop = true;
|
||||
public os = OperatingSystem.Windows;
|
||||
public withOs(os: OperatingSystem): EnvironmentStub {
|
||||
this.os = os;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
8
tests/unit/stubs/ProcessEnvironmentStub.ts
Normal file
8
tests/unit/stubs/ProcessEnvironmentStub.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export function getProcessEnvironmentStub(): NodeJS.ProcessEnv {
|
||||
return {
|
||||
VUE_APP_VERSION: 'stub-version',
|
||||
VUE_APP_NAME: 'stub-name',
|
||||
VUE_APP_REPOSITORY_URL: 'stub-repository-url',
|
||||
VUE_APP_HOMEPAGE_URL: 'stub-homepage-url',
|
||||
};
|
||||
}
|
||||
@@ -2,13 +2,13 @@ import { IProjectInformation } from '@/domain/IProjectInformation';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
export class ProjectInformationStub implements IProjectInformation {
|
||||
public name: string;
|
||||
public version: string;
|
||||
public repositoryUrl: string;
|
||||
public homepage: string;
|
||||
public feedbackUrl: string;
|
||||
public releaseUrl: string;
|
||||
public repositoryWebUrl: string;
|
||||
public name = 'name';
|
||||
public version = 'version';
|
||||
public repositoryUrl = 'repositoryUrl';
|
||||
public homepage = 'homepage';
|
||||
public feedbackUrl = 'feedbackUrl';
|
||||
public releaseUrl = 'releaseUrl';
|
||||
public repositoryWebUrl = 'repositoryWebUrl';
|
||||
public withName(name: string): ProjectInformationStub {
|
||||
this.name = name;
|
||||
return this;
|
||||
|
||||
53
tests/unit/stubs/YamlApplicationStub.ts
Normal file
53
tests/unit/stubs/YamlApplicationStub.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||
import { YamlCategory, YamlScript, YamlApplication, YamlScriptingDefinition } from 'js-yaml-loader!@/application/application.yaml';
|
||||
|
||||
export class YamlApplicationStub implements YamlApplication {
|
||||
public os = 'windows';
|
||||
public actions: readonly YamlCategory[] = [ getCategoryStub() ];
|
||||
public scripting: YamlScriptingDefinition = getTestDefinitionStub();
|
||||
|
||||
public withActions(actions: readonly YamlCategory[]): YamlApplicationStub {
|
||||
this.actions = actions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withOs(os: string): YamlApplicationStub {
|
||||
this.os = os;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withScripting(scripting: YamlScriptingDefinition): YamlApplicationStub {
|
||||
this.scripting = scripting;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
export function getCategoryStub(scriptPrefix = 'testScript'): YamlCategory {
|
||||
return {
|
||||
category: 'category name',
|
||||
children: [
|
||||
getScriptStub(`${scriptPrefix}-standard`, RecommendationLevel.Standard),
|
||||
getScriptStub(`${scriptPrefix}-strict`, RecommendationLevel.Strict),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
function getTestDefinitionStub(): YamlScriptingDefinition {
|
||||
return {
|
||||
fileExtension: '.bat',
|
||||
language: ScriptingLanguage[ScriptingLanguage.batchfile],
|
||||
startCode: 'start',
|
||||
endCode: 'end',
|
||||
};
|
||||
}
|
||||
|
||||
function getScriptStub(scriptName: string, level: RecommendationLevel = RecommendationLevel.Standard): YamlScript {
|
||||
return {
|
||||
name: scriptName,
|
||||
code: 'script code',
|
||||
revertCode: 'revert code',
|
||||
recommend: RecommendationLevel[level].toLowerCase(),
|
||||
call: undefined,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user