refactor to allow switching ICategoryCollection context #40
This commit is contained in:
118
tests/unit/domain/Application.spec.ts
Normal file
118
tests/unit/domain/Application.spec.ts
Normal file
@@ -0,0 +1,118 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { Application } from '@/domain/Application';
|
||||
import { CategoryCollectionStub } from '../stubs/CategoryCollectionStub';
|
||||
import { ProjectInformationStub } from '../stubs/ProjectInformationStub';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
describe('Application', () => {
|
||||
describe('getCollection', () => {
|
||||
it('returns undefined if not found', () => {
|
||||
// arrange
|
||||
const expected = undefined;
|
||||
const info = new ProjectInformationStub();
|
||||
const collections = [ new CategoryCollectionStub().withOs(OperatingSystem.Windows) ];
|
||||
// act
|
||||
const sut = new Application(info, collections);
|
||||
const actual = sut.getCollection(OperatingSystem.Android);
|
||||
// assert
|
||||
expect(actual).to.equals(expected);
|
||||
});
|
||||
it('returns expected when multiple collections exist', () => {
|
||||
// arrange
|
||||
const os = OperatingSystem.Windows;
|
||||
const expected = new CategoryCollectionStub().withOs(os);
|
||||
const info = new ProjectInformationStub();
|
||||
const collections = [ expected, new CategoryCollectionStub().withOs(OperatingSystem.Android) ];
|
||||
// act
|
||||
const sut = new Application(info, collections);
|
||||
const actual = sut.getCollection(os);
|
||||
// assert
|
||||
expect(actual).to.equals(expected);
|
||||
});
|
||||
});
|
||||
describe('ctor', () => {
|
||||
describe('info', () => {
|
||||
it('throws if undefined', () => {
|
||||
// arrange
|
||||
const expectedError = 'undefined project information';
|
||||
const info = undefined;
|
||||
const collections = [new CategoryCollectionStub()];
|
||||
// act
|
||||
const act = () => new Application(info, collections);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('sets as expected', () => {
|
||||
// arrange
|
||||
const expected = new ProjectInformationStub();
|
||||
const collections = [new CategoryCollectionStub()];
|
||||
// act
|
||||
const sut = new Application(expected, collections);
|
||||
// assert
|
||||
expect(sut.info).to.equal(expected);
|
||||
});
|
||||
});
|
||||
describe('collections', () => {
|
||||
describe('throws on invalid value', () => {
|
||||
// arrange
|
||||
const testCases = [
|
||||
{
|
||||
name: 'undefined',
|
||||
expectedError: 'undefined collections',
|
||||
value: undefined,
|
||||
},
|
||||
{
|
||||
name: 'empty',
|
||||
expectedError: 'no collection in the list',
|
||||
value: [],
|
||||
},
|
||||
{
|
||||
name: 'undefined value in list',
|
||||
expectedError: 'undefined collection in the list',
|
||||
value: [ new CategoryCollectionStub(), undefined ],
|
||||
},
|
||||
{
|
||||
name: 'two collections with same OS',
|
||||
expectedError: 'multiple collections with same os: windows',
|
||||
value: [
|
||||
new CategoryCollectionStub().withOs(OperatingSystem.Windows),
|
||||
new CategoryCollectionStub().withOs(OperatingSystem.Windows),
|
||||
new CategoryCollectionStub().withOs(OperatingSystem.BlackBerry),
|
||||
],
|
||||
},
|
||||
];
|
||||
for (const testCase of testCases) {
|
||||
const info = new ProjectInformationStub();
|
||||
const collections = testCase.value;
|
||||
// act
|
||||
const act = () => new Application(info, collections);
|
||||
// assert
|
||||
expect(act).to.throw(testCase.expectedError);
|
||||
}
|
||||
});
|
||||
it('sets as expected', () => {
|
||||
// arrange
|
||||
const info = new ProjectInformationStub();
|
||||
const expected = [new CategoryCollectionStub()];
|
||||
// act
|
||||
const sut = new Application(info, expected);
|
||||
// assert
|
||||
expect(sut.collections).to.equal(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('getSupportedOsList', () => {
|
||||
it('returns expected', () => {
|
||||
// arrange
|
||||
const expected = [ OperatingSystem.Windows, OperatingSystem.macOS ];
|
||||
const info = new ProjectInformationStub();
|
||||
const collections = expected.map((os) => new CategoryCollectionStub().withOs(os));
|
||||
// act
|
||||
const sut = new Application(info, collections);
|
||||
const actual = sut.getSupportedOsList();
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,16 +1,15 @@
|
||||
import { ScriptStub } from '../stubs/ScriptStub';
|
||||
import { CategoryStub } from '../stubs/CategoryStub';
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { ProjectInformation } from '@/domain/ProjectInformation';
|
||||
import { IProjectInformation } from '@/domain/IProjectInformation';
|
||||
import { ICategory } from '@/domain/ICategory';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { IScriptingDefinition } from '@/domain/IScriptingDefinition';
|
||||
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
import { getEnumValues } from '@/application/Common/Enum';
|
||||
import { CategoryCollection } from '../../../src/domain/CategoryCollection';
|
||||
import { CategoryCollection } from '@/domain/CategoryCollection';
|
||||
import { ScriptStub } from '../stubs/ScriptStub';
|
||||
import { CategoryStub } from '../stubs/CategoryStub';
|
||||
|
||||
describe('CategoryCollection', () => {
|
||||
describe('getScriptsByLevel', () => {
|
||||
@@ -177,31 +176,6 @@ describe('CategoryCollection', () => {
|
||||
expect(sut.totalCategories).to.equal(expected);
|
||||
});
|
||||
});
|
||||
describe('information', () => {
|
||||
it('sets information as expected', () => {
|
||||
// arrange
|
||||
const expected = new ProjectInformation(
|
||||
'expected-name', 'expected-repo', '0.31.0', 'expected-homepage');
|
||||
// act
|
||||
const sut = new CategoryCollectionBuilder()
|
||||
.withInfo(expected)
|
||||
.construct();
|
||||
// assert
|
||||
expect(sut.info).to.deep.equal(expected);
|
||||
});
|
||||
it('cannot construct without information', () => {
|
||||
// arrange
|
||||
const information = undefined;
|
||||
// act
|
||||
function construct() {
|
||||
return new CategoryCollectionBuilder()
|
||||
.withInfo(information)
|
||||
.construct();
|
||||
}
|
||||
// assert
|
||||
expect(construct).to.throw('undefined info');
|
||||
});
|
||||
});
|
||||
describe('os', () => {
|
||||
it('sets os as expected', () => {
|
||||
// arrange
|
||||
@@ -281,7 +255,6 @@ function getValidScriptingDefinition(): IScriptingDefinition {
|
||||
|
||||
class CategoryCollectionBuilder {
|
||||
private os = OperatingSystem.Windows;
|
||||
private info = new ProjectInformation('name', 'repo', '0.1.0', 'homepage');
|
||||
private actions: readonly ICategory[] = [
|
||||
new CategoryStub(1).withScripts(
|
||||
new ScriptStub('S1').withLevel(RecommendationLevel.Standard),
|
||||
@@ -292,10 +265,6 @@ class CategoryCollectionBuilder {
|
||||
this.os = os;
|
||||
return this;
|
||||
}
|
||||
public withInfo(info: IProjectInformation): CategoryCollectionBuilder {
|
||||
this.info = info;
|
||||
return this;
|
||||
}
|
||||
public withActions(actions: readonly ICategory[]): CategoryCollectionBuilder {
|
||||
this.actions = actions;
|
||||
return this;
|
||||
@@ -305,6 +274,6 @@ class CategoryCollectionBuilder {
|
||||
return this;
|
||||
}
|
||||
public construct(): CategoryCollection {
|
||||
return new CategoryCollection(this.os, this.info, this.actions, this.script);
|
||||
return new CategoryCollection(this.os, this.actions, this.script);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { ScriptCode } from '@/domain/ScriptCode';
|
||||
import { IScriptCode } from '../../../src/domain/IScriptCode';
|
||||
import { IScriptCode } from '@/domain/IScriptCode';
|
||||
|
||||
describe('ScriptCode', () => {
|
||||
describe('scriptName', () => {
|
||||
|
||||
Reference in New Issue
Block a user