rename Application to CategoryCollection #40
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
import { UserSelection } from '@/application/Context/State/Selection/UserSelection';
|
||||
import { ApplicationCode } from '@/application/Context/State/Code/ApplicationCode';
|
||||
import { ScriptStub } from '../../../stubs/ScriptStub';
|
||||
import { CategoryStub } from '../../../stubs/CategoryStub';
|
||||
import { ApplicationStub } from '../../../stubs/ApplicationStub';
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { ApplicationState } from '@/application/Context/State/ApplicationState';
|
||||
import { UserSelection } from '@/application/Context/State/Selection/UserSelection';
|
||||
import { ApplicationCode } from '@/application/Context/State/Code/ApplicationCode';
|
||||
import { CategoryCollectionState } from '@/application/Context/State/CategoryCollectionState';
|
||||
import { IScript } from '@/domain/IScript';
|
||||
import { ScriptStub } from '../../../stubs/ScriptStub';
|
||||
import { CategoryStub } from '../../../stubs/CategoryStub';
|
||||
import { CategoryCollectionStub } from '../../../stubs/CategoryCollectionStub';
|
||||
|
||||
describe('ApplicationState', () => {
|
||||
describe('CategoryCollectionState', () => {
|
||||
describe('code', () => {
|
||||
it('initialized with empty code', () => {
|
||||
// arrange
|
||||
const app = new ApplicationStub();
|
||||
const sut = new ApplicationState(app);
|
||||
const collection = new CategoryCollectionStub();
|
||||
const sut = new CategoryCollectionState(collection);
|
||||
// act
|
||||
const code = sut.code.current;
|
||||
// assert
|
||||
@@ -21,13 +21,13 @@ describe('ApplicationState', () => {
|
||||
});
|
||||
it('reacts to selection changes as expected', () => {
|
||||
// arrange
|
||||
const app = new ApplicationStub().withAction(new CategoryStub(0).withScriptIds('scriptId'));
|
||||
const selectionStub = new UserSelection(app, []);
|
||||
const expectedCodeGenerator = new ApplicationCode(selectionStub, app.scripting);
|
||||
const collection = new CategoryCollectionStub().withAction(new CategoryStub(0).withScriptIds('scriptId'));
|
||||
const selectionStub = new UserSelection(collection, []);
|
||||
const expectedCodeGenerator = new ApplicationCode(selectionStub, collection.scripting);
|
||||
selectionStub.selectAll();
|
||||
const expectedCode = expectedCodeGenerator.current;
|
||||
// act
|
||||
const sut = new ApplicationState(app);
|
||||
const sut = new CategoryCollectionState(collection);
|
||||
sut.selection.selectAll();
|
||||
const actualCode = sut.code.current;
|
||||
// assert
|
||||
@@ -37,18 +37,19 @@ describe('ApplicationState', () => {
|
||||
describe('selection', () => {
|
||||
it('initialized with no selection', () => {
|
||||
// arrange
|
||||
const app = new ApplicationStub();
|
||||
const sut = new ApplicationState(app);
|
||||
const collection = new CategoryCollectionStub();
|
||||
const sut = new CategoryCollectionState(collection);
|
||||
// act
|
||||
const actual = sut.selection.totalSelected;
|
||||
// assert
|
||||
expect(actual).to.equal(0);
|
||||
});
|
||||
it('can select a script from current application', () => {
|
||||
it('can select a script from current collection', () => {
|
||||
// arrange
|
||||
const expectedScript = new ScriptStub('scriptId');
|
||||
const app = new ApplicationStub().withAction(new CategoryStub(0).withScript(expectedScript));
|
||||
const sut = new ApplicationState(app);
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(0).withScript(expectedScript));
|
||||
const sut = new CategoryCollectionState(collection);
|
||||
// act
|
||||
sut.selection.selectAll();
|
||||
// assert
|
||||
@@ -59,20 +60,20 @@ describe('ApplicationState', () => {
|
||||
describe('filter', () => {
|
||||
it('initialized with an empty filter', () => {
|
||||
// arrange
|
||||
const app = new ApplicationStub();
|
||||
const sut = new ApplicationState(app);
|
||||
const collection = new CategoryCollectionStub();
|
||||
const sut = new CategoryCollectionState(collection);
|
||||
// act
|
||||
const actual = sut.filter.currentFilter;
|
||||
// assert
|
||||
expect(actual).to.equal(undefined);
|
||||
});
|
||||
it('can match a script from current application', () => {
|
||||
it('can match a script from current collection', () => {
|
||||
// arrange
|
||||
const scriptNameFilter = 'scriptName';
|
||||
const expectedScript = new ScriptStub('scriptId').withName(scriptNameFilter);
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(0).withScript(expectedScript));
|
||||
const sut = new ApplicationState(app);
|
||||
const sut = new CategoryCollectionState(collection);
|
||||
// act
|
||||
let actualScript: IScript;
|
||||
sut.filter.filtered.on((result) => actualScript = result.scriptMatches[0]);
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { CategoryStub } from '../../../../stubs/CategoryStub';
|
||||
import { ScriptStub } from '../../../../stubs/ScriptStub';
|
||||
import { ApplicationStub } from '../../../../stubs/ApplicationStub';
|
||||
import { UserSelection } from '@/application/Context/State/Selection/UserSelection';
|
||||
import { ApplicationCode } from '@/application/Context/State/Code/ApplicationCode';
|
||||
import { SelectedScript } from '@/application/Context/State/Selection/SelectedScript';
|
||||
@@ -10,9 +7,12 @@ import { ICodeChangedEvent } from '@/application/Context/State/Code/Event/ICodeC
|
||||
import { IUserScriptGenerator } from '@/application/Context/State/Code/Generation/IUserScriptGenerator';
|
||||
import { CodePosition } from '@/application/Context/State/Code/Position/CodePosition';
|
||||
import { ICodePosition } from '@/application/Context/State/Code/Position/ICodePosition';
|
||||
import { ScriptingDefinitionStub } from '../../../../stubs/ScriptingDefinitionStub';
|
||||
import { IScriptingDefinition } from '@/domain/IScriptingDefinition';
|
||||
import { IUserScript } from '@/application/Context/State/Code/Generation/IUserScript';
|
||||
import { ScriptingDefinitionStub } from '../../../../stubs/ScriptingDefinitionStub';
|
||||
import { CategoryStub } from '../../../../stubs/CategoryStub';
|
||||
import { ScriptStub } from '../../../../stubs/ScriptStub';
|
||||
import { CategoryCollectionStub } from '../../../../stubs/CategoryCollectionStub';
|
||||
|
||||
// TODO: Test scriptingDefinition: IScriptingDefinition logic
|
||||
|
||||
@@ -20,7 +20,7 @@ describe('ApplicationCode', () => {
|
||||
describe('ctor', () => {
|
||||
it('empty when selection is empty', () => {
|
||||
// arrange
|
||||
const selection = new UserSelection(new ApplicationStub(), []);
|
||||
const selection = new UserSelection(new CategoryCollectionStub(), []);
|
||||
const definition = new ScriptingDefinitionStub();
|
||||
const sut = new ApplicationCode(selection, definition);
|
||||
// act
|
||||
@@ -31,8 +31,8 @@ describe('ApplicationCode', () => {
|
||||
it('generates code from script generator when selection is not empty', () => {
|
||||
// arrange
|
||||
const scripts = [new ScriptStub('first'), new ScriptStub('second')];
|
||||
const app = new ApplicationStub().withAction(new CategoryStub(1).withScripts(...scripts));
|
||||
const selection = new UserSelection(app, scripts.map((script) => script.toSelectedScript()));
|
||||
const collection = new CategoryCollectionStub().withAction(new CategoryStub(1).withScripts(...scripts));
|
||||
const selection = new UserSelection(collection, scripts.map((script) => script.toSelectedScript()));
|
||||
const definition = new ScriptingDefinitionStub();
|
||||
const expected: IUserScript = {
|
||||
code: 'expected-code',
|
||||
@@ -53,8 +53,9 @@ describe('ApplicationCode', () => {
|
||||
// arrange
|
||||
let signaled: ICodeChangedEvent;
|
||||
const scripts = [new ScriptStub('first'), new ScriptStub('second')];
|
||||
const app = new ApplicationStub().withAction(new CategoryStub(1).withScripts(...scripts));
|
||||
const selection = new UserSelection(app, scripts.map((script) => new SelectedScript(script, false)));
|
||||
const collection = new CategoryCollectionStub().withAction(new CategoryStub(1).withScripts(...scripts));
|
||||
const scriptsToSelect = scripts.map((script) => new SelectedScript(script, false));
|
||||
const selection = new UserSelection(collection, scriptsToSelect);
|
||||
const definition = new ScriptingDefinitionStub();
|
||||
const sut = new ApplicationCode(selection, definition);
|
||||
sut.changed.on((code) => signaled = code);
|
||||
@@ -68,8 +69,9 @@ describe('ApplicationCode', () => {
|
||||
// arrange
|
||||
let signaled: ICodeChangedEvent;
|
||||
const scripts = [new ScriptStub('first'), new ScriptStub('second')];
|
||||
const app = new ApplicationStub().withAction(new CategoryStub(1).withScripts(...scripts));
|
||||
const selection = new UserSelection(app, scripts.map((script) => new SelectedScript(script, false)));
|
||||
const collection = new CategoryCollectionStub().withAction(new CategoryStub(1).withScripts(...scripts));
|
||||
const scriptsToSelect = scripts.map((script) => new SelectedScript(script, false));
|
||||
const selection = new UserSelection(collection, scriptsToSelect);
|
||||
const definition = new ScriptingDefinitionStub();
|
||||
const sut = new ApplicationCode(selection, definition);
|
||||
sut.changed.on((code) => signaled = code);
|
||||
@@ -84,8 +86,8 @@ describe('ApplicationCode', () => {
|
||||
it('sends scripting definition to generator', () => {
|
||||
// arrange
|
||||
const expectedDefinition = new ScriptingDefinitionStub();
|
||||
const app = new ApplicationStub();
|
||||
const selection = new UserSelection(app, []);
|
||||
const collection = new CategoryCollectionStub();
|
||||
const selection = new UserSelection(collection, []);
|
||||
const generatorMock: IUserScriptGenerator = {
|
||||
buildCode: (selectedScripts, definition) => {
|
||||
if (definition !== expectedDefinition) {
|
||||
@@ -108,9 +110,9 @@ describe('ApplicationCode', () => {
|
||||
// arrange
|
||||
const expectedDefinition = new ScriptingDefinitionStub();
|
||||
const scripts = [new ScriptStub('first'), new ScriptStub('second')];
|
||||
const app = new ApplicationStub().withAction(new CategoryStub(1).withScripts(...scripts));
|
||||
const selection = new UserSelection(app, scripts.map((script) => new SelectedScript(script, false)));
|
||||
const scriptsToSelect = scripts.map((s) => new SelectedScript(s, false));
|
||||
const collection = new CategoryCollectionStub().withAction(new CategoryStub(1).withScripts(...scripts));
|
||||
const scriptsToSelect = scripts.map((script) => new SelectedScript(script, false));
|
||||
const selection = new UserSelection(collection, scriptsToSelect);
|
||||
const generatorMock: IUserScriptGenerator = {
|
||||
buildCode: (selectedScripts) => {
|
||||
if (JSON.stringify(selectedScripts) !== JSON.stringify(scriptsToSelect)) {
|
||||
@@ -133,10 +135,11 @@ describe('ApplicationCode', () => {
|
||||
// arrange
|
||||
let signaled: ICodeChangedEvent;
|
||||
const scripts = [new ScriptStub('first'), new ScriptStub('second')];
|
||||
const app = new ApplicationStub().withAction(new CategoryStub(1).withScripts(...scripts));
|
||||
const selection = new UserSelection(app, scripts.map((script) => new SelectedScript(script, false)));
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(1).withScripts(...scripts));
|
||||
const scriptsToSelect = scripts.map((script) => new SelectedScript(script, false));
|
||||
const selection = new UserSelection(collection, scriptsToSelect);
|
||||
const scriptingDefinition = new ScriptingDefinitionStub();
|
||||
const scriptsToSelect = scripts.map((s) => new SelectedScript(s, false));
|
||||
const totalLines = 20;
|
||||
const expected = new Map<SelectedScript, ICodePosition>(
|
||||
[
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import { CategoryStub } from '../../../../stubs/CategoryStub';
|
||||
import { ScriptStub } from '../../../../stubs/ScriptStub';
|
||||
import { IFilterResult } from '@/application/Context/State/Filter/IFilterResult';
|
||||
import { ApplicationStub } from '../../../../stubs/ApplicationStub';
|
||||
import { UserFilter } from '@/application/Context/State/Filter/UserFilter';
|
||||
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { IFilterResult } from '@/application/Context/State/Filter/IFilterResult';
|
||||
import { UserFilter } from '@/application/Context/State/Filter/UserFilter';
|
||||
import { CategoryStub } from '../../../../stubs/CategoryStub';
|
||||
import { ScriptStub } from '../../../../stubs/ScriptStub';
|
||||
import { CategoryCollectionStub } from '../../../../stubs/CategoryCollectionStub';
|
||||
|
||||
describe('UserFilter', () => {
|
||||
describe('removeFilter', () => {
|
||||
it('signals when removing filter', () => {
|
||||
// arrange
|
||||
let isCalled = false;
|
||||
const sut = new UserFilter(new ApplicationStub());
|
||||
const sut = new UserFilter(new CategoryCollectionStub());
|
||||
sut.filterRemoved.on(() => isCalled = true);
|
||||
// act
|
||||
sut.removeFilter();
|
||||
@@ -20,7 +21,7 @@ describe('UserFilter', () => {
|
||||
});
|
||||
it('sets currentFilter to undefined', () => {
|
||||
// arrange
|
||||
const sut = new UserFilter(new ApplicationStub());
|
||||
const sut = new UserFilter(new CategoryCollectionStub());
|
||||
// act
|
||||
sut.setFilter('non-important');
|
||||
sut.removeFilter();
|
||||
@@ -33,7 +34,7 @@ describe('UserFilter', () => {
|
||||
// arrange
|
||||
let actual: IFilterResult;
|
||||
const nonMatchingFilter = 'non matching filter';
|
||||
const sut = new UserFilter(new ApplicationStub());
|
||||
const sut = new UserFilter(new CategoryCollectionStub());
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
sut.setFilter(nonMatchingFilter);
|
||||
@@ -44,7 +45,7 @@ describe('UserFilter', () => {
|
||||
it('sets currentFilter as expected when no matches', () => {
|
||||
// arrange
|
||||
const nonMatchingFilter = 'non matching filter';
|
||||
const sut = new UserFilter(new ApplicationStub());
|
||||
const sut = new UserFilter(new CategoryCollectionStub());
|
||||
// act
|
||||
sut.setFilter(nonMatchingFilter);
|
||||
// assert
|
||||
@@ -61,7 +62,7 @@ describe('UserFilter', () => {
|
||||
let actual: IFilterResult;
|
||||
const script = new ScriptStub('id').withCode(code);
|
||||
const category = new CategoryStub(33).withScript(script);
|
||||
const sut = new UserFilter(new ApplicationStub()
|
||||
const sut = new UserFilter(new CategoryCollectionStub()
|
||||
.withAction(category));
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
@@ -81,7 +82,7 @@ describe('UserFilter', () => {
|
||||
let actual: IFilterResult;
|
||||
const script = new ScriptStub('id').withRevertCode(revertCode);
|
||||
const category = new CategoryStub(33).withScript(script);
|
||||
const sut = new UserFilter(new ApplicationStub()
|
||||
const sut = new UserFilter(new CategoryCollectionStub()
|
||||
.withAction(category));
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
@@ -101,7 +102,7 @@ describe('UserFilter', () => {
|
||||
let actual: IFilterResult;
|
||||
const script = new ScriptStub('id').withName(name);
|
||||
const category = new CategoryStub(33).withScript(script);
|
||||
const sut = new UserFilter(new ApplicationStub()
|
||||
const sut = new UserFilter(new CategoryCollectionStub()
|
||||
.withAction(category));
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
@@ -121,7 +122,7 @@ describe('UserFilter', () => {
|
||||
const filter = 'Hello WoRLD';
|
||||
let actual: IFilterResult;
|
||||
const category = new CategoryStub(55).withName(categoryName);
|
||||
const sut = new UserFilter(new ApplicationStub()
|
||||
const sut = new UserFilter(new CategoryCollectionStub()
|
||||
.withAction(category));
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
@@ -144,9 +145,9 @@ describe('UserFilter', () => {
|
||||
const category = new CategoryStub(55)
|
||||
.withName(matchingText)
|
||||
.withScript(script);
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(category);
|
||||
const sut = new UserFilter(app);
|
||||
const sut = new UserFilter(collection);
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
sut.setFilter(filter);
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { IScript } from '@/domain/IScript';
|
||||
import { SelectedScript } from '@/application/Context/State/Selection/SelectedScript';
|
||||
import { UserSelection } from '@/application/Context/State/Selection/UserSelection';
|
||||
import { CategoryStub } from '../../../../stubs/CategoryStub';
|
||||
import { CategoryCollectionStub } from '../../../../stubs/CategoryCollectionStub';
|
||||
import { SelectedScriptStub } from '../../../../stubs/SelectedScriptStub';
|
||||
import { ScriptStub } from '../../../../stubs/ScriptStub';
|
||||
import { SelectedScript } from '@/application/Context/State/Selection/SelectedScript';
|
||||
import { CategoryStub } from '../../../../stubs/CategoryStub';
|
||||
import { ApplicationStub } from '../../../../stubs/ApplicationStub';
|
||||
import { UserSelection } from '@/application/Context/State/Selection/UserSelection';
|
||||
|
||||
describe('UserSelection', () => {
|
||||
describe('ctor', () => {
|
||||
it('has nothing with no initial selection', () => {
|
||||
// arrange
|
||||
const app = new ApplicationStub().withAction(new CategoryStub(1).withScriptIds('s1'));
|
||||
const collection = new CategoryCollectionStub().withAction(new CategoryStub(1).withScriptIds('s1'));
|
||||
const selection = [];
|
||||
// act
|
||||
const sut = new UserSelection(app, selection);
|
||||
const sut = new UserSelection(collection, selection);
|
||||
// assert
|
||||
expect(sut.selectedScripts).to.have.lengthOf(0);
|
||||
});
|
||||
@@ -23,11 +23,11 @@ describe('UserSelection', () => {
|
||||
// arrange
|
||||
const firstScript = new ScriptStub('1');
|
||||
const secondScript = new ScriptStub('2');
|
||||
const app = new ApplicationStub().withAction(
|
||||
new CategoryStub(1).withScript(firstScript).withScripts(secondScript));
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(1).withScript(firstScript).withScripts(secondScript));
|
||||
const expected = [ new SelectedScript(firstScript, false), new SelectedScript(secondScript, true) ];
|
||||
// act
|
||||
const sut = new UserSelection(app, expected);
|
||||
const sut = new UserSelection(collection, expected);
|
||||
// assert
|
||||
expect(sut.selectedScripts).to.deep.include(expected[0]);
|
||||
expect(sut.selectedScripts).to.deep.include(expected[1]);
|
||||
@@ -36,13 +36,13 @@ describe('UserSelection', () => {
|
||||
it('deselectAll removes all items', () => {
|
||||
// arrange
|
||||
const events: Array<readonly SelectedScript[]> = [];
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(1)
|
||||
.withScriptIds('s1', 's2', 's3', 's4'));
|
||||
.withScriptIds('s1', 's2', 's3', 's4'));
|
||||
const selectedScripts = [
|
||||
new SelectedScriptStub('s1'), new SelectedScriptStub('s2'), new SelectedScriptStub('s3'),
|
||||
];
|
||||
const sut = new UserSelection(app, selectedScripts);
|
||||
const sut = new UserSelection(collection, selectedScripts);
|
||||
sut.changed.on((newScripts) => events.push(newScripts));
|
||||
// act
|
||||
sut.deselectAll();
|
||||
@@ -54,13 +54,13 @@ describe('UserSelection', () => {
|
||||
it('selectOnly selects expected', () => {
|
||||
// arrange
|
||||
const events: Array<readonly SelectedScript[]> = [];
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(1)
|
||||
.withScriptIds('s1', 's2', 's3', 's4'));
|
||||
.withScriptIds('s1', 's2', 's3', 's4'));
|
||||
const selectedScripts = [
|
||||
new SelectedScriptStub('s1'), new SelectedScriptStub('s2'), new SelectedScriptStub('s3'),
|
||||
];
|
||||
const sut = new UserSelection(app, selectedScripts);
|
||||
const sut = new UserSelection(collection, selectedScripts);
|
||||
sut.changed.on((newScripts) => events.push(newScripts));
|
||||
const scripts = [new ScriptStub('s2'), new ScriptStub('s3'), new ScriptStub('s4')];
|
||||
const expected = [ new SelectedScriptStub('s2'), new SelectedScriptStub('s3'),
|
||||
@@ -78,10 +78,10 @@ describe('UserSelection', () => {
|
||||
// arrange
|
||||
const events: Array<readonly SelectedScript[]> = [];
|
||||
const scripts: IScript[] = [new ScriptStub('s1'), new ScriptStub('s2'), new ScriptStub('s3'), new ScriptStub('s4')];
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(1)
|
||||
.withScripts(...scripts));
|
||||
const sut = new UserSelection(app, []);
|
||||
.withScripts(...scripts));
|
||||
const sut = new UserSelection(collection, []);
|
||||
sut.changed.on((newScripts) => events.push(newScripts));
|
||||
const expected = scripts.map((script) => new SelectedScript(script, false));
|
||||
// act
|
||||
@@ -95,10 +95,10 @@ describe('UserSelection', () => {
|
||||
it('adds when item does not exist', () => {
|
||||
// arrange
|
||||
const events: Array<readonly SelectedScript[]> = [];
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(1)
|
||||
.withScripts(new ScriptStub('s1'), new ScriptStub('s2')));
|
||||
const sut = new UserSelection(app, []);
|
||||
.withScripts(new ScriptStub('s1'), new ScriptStub('s2')));
|
||||
const sut = new UserSelection(collection, []);
|
||||
sut.changed.on((scripts) => events.push(scripts));
|
||||
const expected = [ new SelectedScript(new ScriptStub('s1'), false) ];
|
||||
// act
|
||||
@@ -111,10 +111,10 @@ describe('UserSelection', () => {
|
||||
it('updates when item exists', () => {
|
||||
// arrange
|
||||
const events: Array<readonly SelectedScript[]> = [];
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(1)
|
||||
.withScripts(new ScriptStub('s1'), new ScriptStub('s2')));
|
||||
const sut = new UserSelection(app, []);
|
||||
.withScripts(new ScriptStub('s1'), new ScriptStub('s2')));
|
||||
const sut = new UserSelection(collection, []);
|
||||
sut.changed.on((scripts) => events.push(scripts));
|
||||
const expected = [ new SelectedScript(new ScriptStub('s1'), true) ];
|
||||
// act
|
||||
@@ -130,10 +130,10 @@ describe('UserSelection', () => {
|
||||
// arrange
|
||||
const events: Array<readonly SelectedScript[]> = [];
|
||||
const categoryId = 1;
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(categoryId)
|
||||
.withScripts(new ScriptStub('s1'), new ScriptStub('s2')));
|
||||
const sut = new UserSelection(app, []);
|
||||
.withScripts(new ScriptStub('s1'), new ScriptStub('s2')));
|
||||
const sut = new UserSelection(collection, []);
|
||||
sut.changed.on((s) => events.push(s));
|
||||
// act
|
||||
sut.removeAllInCategory(categoryId);
|
||||
@@ -145,10 +145,10 @@ describe('UserSelection', () => {
|
||||
// arrange
|
||||
const categoryId = 1;
|
||||
const scripts = [new SelectedScriptStub('s1'), new SelectedScriptStub('s2')];
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(categoryId)
|
||||
.withScripts(...scripts.map((script) => script.script)));
|
||||
const sut = new UserSelection(app, scripts);
|
||||
.withScripts(...scripts.map((script) => script.script)));
|
||||
const sut = new UserSelection(collection, scripts);
|
||||
// act
|
||||
sut.removeAllInCategory(categoryId);
|
||||
// assert
|
||||
@@ -160,10 +160,10 @@ describe('UserSelection', () => {
|
||||
const categoryId = 1;
|
||||
const existing = [new ScriptStub('s1'), new ScriptStub('s2')];
|
||||
const notExisting = [new ScriptStub('s3'), new ScriptStub('s4')];
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(categoryId)
|
||||
.withScripts(...existing, ...notExisting));
|
||||
const sut = new UserSelection(app, existing.map((script) => new SelectedScript(script, false)));
|
||||
.withScripts(...existing, ...notExisting));
|
||||
const sut = new UserSelection(collection, existing.map((script) => new SelectedScript(script, false)));
|
||||
// act
|
||||
sut.removeAllInCategory(categoryId);
|
||||
// assert
|
||||
@@ -177,10 +177,10 @@ describe('UserSelection', () => {
|
||||
const events: Array<readonly SelectedScript[]> = [];
|
||||
const categoryId = 1;
|
||||
const scripts = [new ScriptStub('s1'), new ScriptStub('s2')];
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(categoryId)
|
||||
.withScripts(...scripts));
|
||||
const sut = new UserSelection(app, scripts.map((script) => new SelectedScript(script, false)));
|
||||
.withScripts(...scripts));
|
||||
const sut = new UserSelection(collection, scripts.map((script) => new SelectedScript(script, false)));
|
||||
sut.changed.on((s) => events.push(s));
|
||||
// act
|
||||
sut.addOrUpdateAllInCategory(categoryId);
|
||||
@@ -193,10 +193,10 @@ describe('UserSelection', () => {
|
||||
// arrange
|
||||
const categoryId = 1;
|
||||
const expected = [new ScriptStub('s1'), new ScriptStub('s2')];
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(categoryId)
|
||||
.withScripts(...expected));
|
||||
const sut = new UserSelection(app, []);
|
||||
.withScripts(...expected));
|
||||
const sut = new UserSelection(collection, []);
|
||||
// act
|
||||
sut.addOrUpdateAllInCategory(categoryId);
|
||||
// assert
|
||||
@@ -207,10 +207,10 @@ describe('UserSelection', () => {
|
||||
// arrange
|
||||
const categoryId = 1;
|
||||
const expected = [new ScriptStub('s1'), new ScriptStub('s2')];
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(categoryId)
|
||||
.withScripts(...expected));
|
||||
const sut = new UserSelection(app, []);
|
||||
.withScripts(...expected));
|
||||
const sut = new UserSelection(collection, []);
|
||||
// act
|
||||
sut.addOrUpdateAllInCategory(categoryId, true);
|
||||
// assert
|
||||
@@ -223,10 +223,10 @@ describe('UserSelection', () => {
|
||||
const notExisting = [ new ScriptStub('notExisting1'), new ScriptStub('notExisting2') ];
|
||||
const existing = [ new ScriptStub('existing1'), new ScriptStub('existing2') ];
|
||||
const allScripts = [ ...existing, ...notExisting ];
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(categoryId)
|
||||
.withScripts(...allScripts));
|
||||
const sut = new UserSelection(app, existing.map((script) => new SelectedScript(script, false)));
|
||||
const sut = new UserSelection(collection, existing.map((script) => new SelectedScript(script, false)));
|
||||
// act
|
||||
sut.addOrUpdateAllInCategory(categoryId, true);
|
||||
// assert
|
||||
@@ -239,10 +239,10 @@ describe('UserSelection', () => {
|
||||
const notExisting = [ new ScriptStub('notExisting1'), new ScriptStub('notExisting2') ];
|
||||
const existing = [ new ScriptStub('existing1'), new ScriptStub('existing2') ];
|
||||
const allScripts = [ ...existing, ...notExisting ];
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(categoryId)
|
||||
.withScripts(...allScripts));
|
||||
const sut = new UserSelection(app, existing.map((script) => new SelectedScript(script, false)));
|
||||
const sut = new UserSelection(collection, existing.map((script) => new SelectedScript(script, false)));
|
||||
// act
|
||||
sut.addOrUpdateAllInCategory(categoryId, true);
|
||||
// assert
|
||||
@@ -253,10 +253,10 @@ describe('UserSelection', () => {
|
||||
// arrange
|
||||
const categoryId = 1;
|
||||
const scripts = [ new ScriptStub('existing1'), new ScriptStub('existing2') ];
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(categoryId)
|
||||
.withScripts(...scripts));
|
||||
const sut = new UserSelection(app, scripts.map((script) => new SelectedScript(script, false)));
|
||||
const sut = new UserSelection(collection, scripts.map((script) => new SelectedScript(script, false)));
|
||||
// act
|
||||
sut.addOrUpdateAllInCategory(categoryId, true);
|
||||
// assert
|
||||
@@ -269,10 +269,10 @@ describe('UserSelection', () => {
|
||||
// arrange
|
||||
const selectedScript = new ScriptStub('selected');
|
||||
const notSelectedScript = new ScriptStub('not selected');
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(1)
|
||||
.withScripts(selectedScript, notSelectedScript));
|
||||
const sut = new UserSelection(app, [ new SelectedScript(selectedScript, false) ]);
|
||||
const sut = new UserSelection(collection, [ new SelectedScript(selectedScript, false) ]);
|
||||
// act
|
||||
const actual = sut.isSelected(notSelectedScript.id);
|
||||
// assert
|
||||
@@ -282,10 +282,10 @@ describe('UserSelection', () => {
|
||||
// arrange
|
||||
const selectedScript = new ScriptStub('selected');
|
||||
const notSelectedScript = new ScriptStub('not selected');
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(1)
|
||||
.withScripts(selectedScript, notSelectedScript));
|
||||
const sut = new UserSelection(app, [ new SelectedScript(selectedScript, false) ]);
|
||||
const sut = new UserSelection(collection, [ new SelectedScript(selectedScript, false) ]);
|
||||
// act
|
||||
const actual = sut.isSelected(selectedScript.id);
|
||||
// assert
|
||||
@@ -297,8 +297,8 @@ describe('UserSelection', () => {
|
||||
// arrange
|
||||
const category = new CategoryStub(1)
|
||||
.withScriptIds('non-selected-script-1', 'non-selected-script-2');
|
||||
const app = new ApplicationStub().withAction(category);
|
||||
const sut = new UserSelection(app, [ ]);
|
||||
const collection = new CategoryCollectionStub().withAction(category);
|
||||
const sut = new UserSelection(collection, [ ]);
|
||||
it('areAllSelected returns false', () => {
|
||||
// act
|
||||
const actual = sut.areAllSelected(category);
|
||||
@@ -317,10 +317,10 @@ describe('UserSelection', () => {
|
||||
const category = new CategoryStub(1)
|
||||
.withScriptIds('non-selected-script-1', 'non-selected-script-2');
|
||||
const selectedScript = new ScriptStub('selected');
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(category)
|
||||
.withAction(new CategoryStub(22).withScript(selectedScript));
|
||||
const sut = new UserSelection(app, [ new SelectedScript(selectedScript, false) ]);
|
||||
const sut = new UserSelection(collection, [ new SelectedScript(selectedScript, false) ]);
|
||||
it('areAllSelected returns false', () => {
|
||||
// act
|
||||
const actual = sut.areAllSelected(category);
|
||||
@@ -340,8 +340,8 @@ describe('UserSelection', () => {
|
||||
const category = new CategoryStub(1)
|
||||
.withScriptIds('non-selected-script-1', 'non-selected-script-2')
|
||||
.withCategory(new CategoryStub(12).withScript(selectedScript));
|
||||
const app = new ApplicationStub().withAction(category);
|
||||
const sut = new UserSelection(app, [ new SelectedScript(selectedScript, false) ]);
|
||||
const collection = new CategoryCollectionStub().withAction(category);
|
||||
const sut = new UserSelection(collection, [ new SelectedScript(selectedScript, false) ]);
|
||||
it('areAllSelected returns false', () => {
|
||||
// act
|
||||
const actual = sut.areAllSelected(category);
|
||||
@@ -362,8 +362,8 @@ describe('UserSelection', () => {
|
||||
const category = new CategoryStub(1)
|
||||
.withScript(firstSelectedScript)
|
||||
.withCategory(new CategoryStub(12).withScript(secondSelectedScript));
|
||||
const app = new ApplicationStub().withAction(category);
|
||||
const sut = new UserSelection(app,
|
||||
const collection = new CategoryCollectionStub().withAction(category);
|
||||
const sut = new UserSelection(collection,
|
||||
[ firstSelectedScript, secondSelectedScript ].map((s) => new SelectedScript(s, false)));
|
||||
it('areAllSelected returns true', () => {
|
||||
// act
|
||||
@@ -378,6 +378,5 @@ describe('UserSelection', () => {
|
||||
expect(actual).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { IEntity } from '@/infrastructure/Entity/IEntity';
|
||||
import applicationFile, { YamlCategory, YamlScript, YamlApplication, YamlScriptingDefinition } from 'js-yaml-loader!@/application/application.yaml';
|
||||
import { parseApplication } from '@/application/Parser/ApplicationParser';
|
||||
import { parseCategoryCollection } from '@/application/Parser/CategoryCollectionParser';
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { parseCategory } from '@/application/Parser/CategoryParser';
|
||||
@@ -12,47 +12,49 @@ import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||
import { parseScriptingDefinition } from '@/application/Parser/ScriptingDefinitionParser';
|
||||
import { mockEnumParser } from '../../stubs/EnumParserStub';
|
||||
|
||||
describe('ApplicationParser', () => {
|
||||
describe('parseApplication', () => {
|
||||
describe('CategoryCollectionParser', () => {
|
||||
describe('parseCategoryCollection', () => {
|
||||
it('can parse current application file', () => {
|
||||
// act
|
||||
const act = () => parseApplication(applicationFile);
|
||||
const act = () => parseCategoryCollection(applicationFile);
|
||||
// assert
|
||||
expect(act).to.not.throw();
|
||||
});
|
||||
it('throws when undefined', () => {
|
||||
// arrange
|
||||
const expectedError = 'application is null or undefined';
|
||||
const expectedError = 'content is null or undefined';
|
||||
// act
|
||||
const act = () => parseApplication(undefined);
|
||||
const act = () => parseCategoryCollection(undefined);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
describe('actions', () => {
|
||||
it('throws when undefined actions', () => {
|
||||
// arrange
|
||||
const app = new YamlApplicationBuilder().withActions(undefined).build();
|
||||
const expectedError = 'content does not define any action';
|
||||
const collection = new YamlApplicationBuilder().withActions(undefined).build();
|
||||
// act
|
||||
const act = () => parseApplication(app);
|
||||
const act = () => parseCategoryCollection(collection);
|
||||
// assert
|
||||
expect(act).to.throw('application does not define any action');
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws when has no actions', () => {
|
||||
// arrange
|
||||
const app = new YamlApplicationBuilder().withActions([]).build();
|
||||
const expectedError = 'content does not define any action';
|
||||
const collection = new YamlApplicationBuilder().withActions([]).build();
|
||||
// act
|
||||
const act = () => parseApplication(app);
|
||||
const act = () => parseCategoryCollection(collection);
|
||||
// assert
|
||||
expect(act).to.throw('application does not define any action');
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('parses actions', () => {
|
||||
// arrange
|
||||
const actions = [ getTestCategory('test1'), getTestCategory('test2') ];
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const expected = [ parseCategory(actions[0], compiler), parseCategory(actions[1], compiler) ];
|
||||
const app = new YamlApplicationBuilder().withActions(actions).build();
|
||||
const collection = new YamlApplicationBuilder().withActions(actions).build();
|
||||
// act
|
||||
const actual = parseApplication(app).actions;
|
||||
const actual = parseCategoryCollection(collection).actions;
|
||||
// assert
|
||||
expect(excludingId(actual)).to.be.deep.equal(excludingId(expected));
|
||||
function excludingId<TId>(array: ReadonlyArray<IEntity<TId>>) {
|
||||
@@ -69,9 +71,9 @@ describe('ApplicationParser', () => {
|
||||
const expected = 'expected-version';
|
||||
const env = getProcessEnvironmentStub();
|
||||
env.VUE_APP_VERSION = expected;
|
||||
const app = new YamlApplicationBuilder().build();
|
||||
const collection = new YamlApplicationBuilder().build();
|
||||
// act
|
||||
const actual = parseApplication(app, env).info.version;
|
||||
const actual = parseCategoryCollection(collection, env).info.version;
|
||||
// assert
|
||||
expect(actual).to.be.equal(expected);
|
||||
});
|
||||
@@ -80,9 +82,9 @@ describe('ApplicationParser', () => {
|
||||
const expected = 'https://expected-repository.url';
|
||||
const env = getProcessEnvironmentStub();
|
||||
env.VUE_APP_REPOSITORY_URL = expected;
|
||||
const app = new YamlApplicationBuilder().build();
|
||||
const collection = new YamlApplicationBuilder().build();
|
||||
// act
|
||||
const actual = parseApplication(app, env).info.repositoryUrl;
|
||||
const actual = parseCategoryCollection(collection, env).info.repositoryUrl;
|
||||
// assert
|
||||
expect(actual).to.be.equal(expected);
|
||||
});
|
||||
@@ -91,9 +93,9 @@ describe('ApplicationParser', () => {
|
||||
const expected = 'expected-app-name';
|
||||
const env = getProcessEnvironmentStub();
|
||||
env.VUE_APP_NAME = expected;
|
||||
const app = new YamlApplicationBuilder().build();
|
||||
const collection = new YamlApplicationBuilder().build();
|
||||
// act
|
||||
const actual = parseApplication(app, env).info.name;
|
||||
const actual = parseCategoryCollection(collection, env).info.name;
|
||||
// assert
|
||||
expect(actual).to.be.equal(expected);
|
||||
});
|
||||
@@ -102,9 +104,9 @@ describe('ApplicationParser', () => {
|
||||
const expected = 'https://expected.sexy';
|
||||
const env = getProcessEnvironmentStub();
|
||||
env.VUE_APP_HOMEPAGE_URL = expected;
|
||||
const app = new YamlApplicationBuilder().build();
|
||||
const collection = new YamlApplicationBuilder().build();
|
||||
// act
|
||||
const actual = parseApplication(app, env).info.homepage;
|
||||
const actual = parseCategoryCollection(collection, env).info.homepage;
|
||||
// assert
|
||||
expect(actual).to.be.equal(expected);
|
||||
});
|
||||
@@ -112,11 +114,11 @@ describe('ApplicationParser', () => {
|
||||
describe('scripting definition', () => {
|
||||
it('parses scripting definition as expected', () => {
|
||||
// arrange
|
||||
const app = new YamlApplicationBuilder().build();
|
||||
const collection = new YamlApplicationBuilder().build();
|
||||
const information = parseProjectInformation(process.env);
|
||||
const expected = parseScriptingDefinition(app.scripting, information);
|
||||
const expected = parseScriptingDefinition(collection.scripting, information);
|
||||
// act
|
||||
const actual = parseApplication(app).scripting;
|
||||
const actual = parseCategoryCollection(collection).scripting;
|
||||
// assert
|
||||
expect(expected).to.deep.equal(actual);
|
||||
});
|
||||
@@ -127,13 +129,13 @@ describe('ApplicationParser', () => {
|
||||
const expectedOs = OperatingSystem.macOS;
|
||||
const osText = 'macos';
|
||||
const expectedName = 'os';
|
||||
const app = new YamlApplicationBuilder()
|
||||
const collection = new YamlApplicationBuilder()
|
||||
.withOs(osText)
|
||||
.build();
|
||||
const parserMock = mockEnumParser(expectedName, osText, expectedOs);
|
||||
const env = getProcessEnvironmentStub();
|
||||
// act
|
||||
const actual = parseApplication(app, env, parserMock);
|
||||
const actual = parseCategoryCollection(collection, env, parserMock);
|
||||
// assert
|
||||
expect(actual.os).to.equal(expectedOs);
|
||||
});
|
||||
@@ -1,18 +1,18 @@
|
||||
import { ScriptStub } from './../stubs/ScriptStub';
|
||||
import { CategoryStub } from './../stubs/CategoryStub';
|
||||
import { Application } from '@/domain/Application';
|
||||
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/IApplication';
|
||||
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';
|
||||
|
||||
describe('Application', () => {
|
||||
describe('CategoryCollection', () => {
|
||||
describe('getScriptsByLevel', () => {
|
||||
it('filters out scripts without levels', () => {
|
||||
// arrange
|
||||
@@ -25,7 +25,9 @@ describe('Application', () => {
|
||||
const category = new CategoryStub(0)
|
||||
.withScripts(...scriptsWithLevels)
|
||||
.withScript(toIgnore);
|
||||
const sut = new ApplicationBuilder().withActions([category]).construct();
|
||||
const sut = new CategoryCollectionBuilder()
|
||||
.withActions([category])
|
||||
.construct();
|
||||
// act
|
||||
const actual = sut.getScriptsByLevel(currentLevel);
|
||||
// assert
|
||||
@@ -43,7 +45,9 @@ describe('Application', () => {
|
||||
new CategoryStub(3).withScripts(...expected,
|
||||
new ScriptStub('S3').withLevel(RecommendationLevel.Strict)),
|
||||
];
|
||||
const sut = new ApplicationBuilder().withActions(actions).construct();
|
||||
const sut = new CategoryCollectionBuilder()
|
||||
.withActions(actions)
|
||||
.construct();
|
||||
// act
|
||||
const actual = sut.getScriptsByLevel(level);
|
||||
// assert
|
||||
@@ -59,7 +63,9 @@ describe('Application', () => {
|
||||
const actions = [
|
||||
new CategoryStub(3).withScripts(...expected),
|
||||
];
|
||||
const sut = new ApplicationBuilder().withActions(actions).construct();
|
||||
const sut = new CategoryCollectionBuilder()
|
||||
.withActions(actions)
|
||||
.construct();
|
||||
// act
|
||||
const actual = sut.getScriptsByLevel(level);
|
||||
// assert
|
||||
@@ -67,7 +73,8 @@ describe('Application', () => {
|
||||
});
|
||||
it('throws when level is undefined', () => {
|
||||
// arrange
|
||||
const sut = new ApplicationBuilder().construct();
|
||||
const sut = new CategoryCollectionBuilder()
|
||||
.construct();
|
||||
// act
|
||||
const act = () => sut.getScriptsByLevel(undefined);
|
||||
// assert
|
||||
@@ -76,7 +83,8 @@ describe('Application', () => {
|
||||
it('throws when level is out of range', () => {
|
||||
// arrange
|
||||
const invalidValue = 66;
|
||||
const sut = new ApplicationBuilder().construct();
|
||||
const sut = new CategoryCollectionBuilder()
|
||||
.construct();
|
||||
// act
|
||||
const act = () => sut.getScriptsByLevel(invalidValue);
|
||||
// assert
|
||||
@@ -89,10 +97,12 @@ describe('Application', () => {
|
||||
const categories = [];
|
||||
// act
|
||||
function construct() {
|
||||
new ApplicationBuilder().withActions(categories).construct();
|
||||
new CategoryCollectionBuilder()
|
||||
.withActions(categories)
|
||||
.construct();
|
||||
}
|
||||
// assert
|
||||
expect(construct).to.throw('Application must consist of at least one category');
|
||||
expect(construct).to.throw('must consist of at least one category');
|
||||
});
|
||||
it('cannot construct without scripts', () => {
|
||||
// arrange
|
||||
@@ -102,10 +112,12 @@ describe('Application', () => {
|
||||
];
|
||||
// act
|
||||
function construct() {
|
||||
new ApplicationBuilder().withActions(categories).construct();
|
||||
new CategoryCollectionBuilder()
|
||||
.withActions(categories)
|
||||
.construct();
|
||||
}
|
||||
// assert
|
||||
expect(construct).to.throw('Application must consist of at least one script');
|
||||
expect(construct).to.throw('must consist of at least one script');
|
||||
});
|
||||
describe('cannot construct without any recommended scripts', () => {
|
||||
// arrange
|
||||
@@ -119,7 +131,7 @@ describe('Application', () => {
|
||||
new ScriptStub(`Script${index}`).withLevel(level),
|
||||
));
|
||||
// act
|
||||
const construct = () => new ApplicationBuilder()
|
||||
const construct = () => new CategoryCollectionBuilder()
|
||||
.withActions(categories)
|
||||
.construct();
|
||||
// assert
|
||||
@@ -141,7 +153,9 @@ describe('Application', () => {
|
||||
new CategoryStub(4).withScripts(new ScriptStub('S4'))),
|
||||
];
|
||||
// act
|
||||
const sut = new ApplicationBuilder().withActions(categories).construct();
|
||||
const sut = new CategoryCollectionBuilder()
|
||||
.withActions(categories)
|
||||
.construct();
|
||||
// assert
|
||||
expect(sut.totalScripts).to.equal(4);
|
||||
});
|
||||
@@ -156,7 +170,7 @@ describe('Application', () => {
|
||||
new CategoryStub(3).withCategories(new CategoryStub(4).withScripts(new ScriptStub('S4'))),
|
||||
];
|
||||
// act
|
||||
const sut = new ApplicationBuilder()
|
||||
const sut = new CategoryCollectionBuilder()
|
||||
.withActions(categories)
|
||||
.construct();
|
||||
// assert
|
||||
@@ -169,7 +183,9 @@ describe('Application', () => {
|
||||
const expected = new ProjectInformation(
|
||||
'expected-name', 'expected-repo', '0.31.0', 'expected-homepage');
|
||||
// act
|
||||
const sut = new ApplicationBuilder().withInfo(expected).construct();
|
||||
const sut = new CategoryCollectionBuilder()
|
||||
.withInfo(expected)
|
||||
.construct();
|
||||
// assert
|
||||
expect(sut.info).to.deep.equal(expected);
|
||||
});
|
||||
@@ -178,7 +194,9 @@ describe('Application', () => {
|
||||
const information = undefined;
|
||||
// act
|
||||
function construct() {
|
||||
return new ApplicationBuilder().withInfo(information).construct();
|
||||
return new CategoryCollectionBuilder()
|
||||
.withInfo(information)
|
||||
.construct();
|
||||
}
|
||||
// assert
|
||||
expect(construct).to.throw('undefined info');
|
||||
@@ -189,7 +207,9 @@ describe('Application', () => {
|
||||
// arrange
|
||||
const expected = OperatingSystem.macOS;
|
||||
// act
|
||||
const sut = new ApplicationBuilder().withOs(expected).construct();
|
||||
const sut = new CategoryCollectionBuilder()
|
||||
.withOs(expected)
|
||||
.construct();
|
||||
// assert
|
||||
expect(sut.os).to.deep.equal(expected);
|
||||
});
|
||||
@@ -197,7 +217,9 @@ describe('Application', () => {
|
||||
// arrange
|
||||
const os = OperatingSystem.Unknown;
|
||||
// act
|
||||
const construct = () => new ApplicationBuilder().withOs(os).construct();
|
||||
const construct = () => new CategoryCollectionBuilder()
|
||||
.withOs(os)
|
||||
.construct();
|
||||
// assert
|
||||
expect(construct).to.throw('unknown os');
|
||||
});
|
||||
@@ -205,7 +227,9 @@ describe('Application', () => {
|
||||
// arrange
|
||||
const os = undefined;
|
||||
// act
|
||||
const construct = () => new ApplicationBuilder().withOs(os).construct();
|
||||
const construct = () => new CategoryCollectionBuilder()
|
||||
.withOs(os)
|
||||
.construct();
|
||||
// assert
|
||||
expect(construct).to.throw('undefined os');
|
||||
});
|
||||
@@ -213,7 +237,9 @@ describe('Application', () => {
|
||||
// arrange
|
||||
const os: OperatingSystem = 666;
|
||||
// act
|
||||
const construct = () => new ApplicationBuilder().withOs(os).construct();
|
||||
const construct = () => new CategoryCollectionBuilder()
|
||||
.withOs(os)
|
||||
.construct();
|
||||
// assert
|
||||
expect(construct).to.throw(`os "${os}" is out of range`);
|
||||
});
|
||||
@@ -223,7 +249,9 @@ describe('Application', () => {
|
||||
// arrange
|
||||
const expected = getValidScriptingDefinition();
|
||||
// act
|
||||
const sut = new ApplicationBuilder().withScripting(expected).construct();
|
||||
const sut = new CategoryCollectionBuilder()
|
||||
.withScripting(expected)
|
||||
.construct();
|
||||
// assert
|
||||
expect(sut.scripting).to.deep.equal(expected);
|
||||
});
|
||||
@@ -232,7 +260,9 @@ describe('Application', () => {
|
||||
const scriptingDefinition = undefined;
|
||||
// act
|
||||
function construct() {
|
||||
return new ApplicationBuilder().withScripting(scriptingDefinition).construct();
|
||||
return new CategoryCollectionBuilder()
|
||||
.withScripting(scriptingDefinition)
|
||||
.construct();
|
||||
}
|
||||
// assert
|
||||
expect(construct).to.throw('undefined scripting definition');
|
||||
@@ -249,7 +279,7 @@ function getValidScriptingDefinition(): IScriptingDefinition {
|
||||
};
|
||||
}
|
||||
|
||||
class ApplicationBuilder {
|
||||
class CategoryCollectionBuilder {
|
||||
private os = OperatingSystem.Windows;
|
||||
private info = new ProjectInformation('name', 'repo', '0.1.0', 'homepage');
|
||||
private actions: readonly ICategory[] = [
|
||||
@@ -258,23 +288,23 @@ class ApplicationBuilder {
|
||||
new ScriptStub('S2').withLevel(RecommendationLevel.Strict)),
|
||||
];
|
||||
private script: IScriptingDefinition = getValidScriptingDefinition();
|
||||
public withOs(os: OperatingSystem): ApplicationBuilder {
|
||||
public withOs(os: OperatingSystem): CategoryCollectionBuilder {
|
||||
this.os = os;
|
||||
return this;
|
||||
}
|
||||
public withInfo(info: IProjectInformation) {
|
||||
public withInfo(info: IProjectInformation): CategoryCollectionBuilder {
|
||||
this.info = info;
|
||||
return this;
|
||||
}
|
||||
public withActions(actions: readonly ICategory[]) {
|
||||
public withActions(actions: readonly ICategory[]): CategoryCollectionBuilder {
|
||||
this.actions = actions;
|
||||
return this;
|
||||
}
|
||||
public withScripting(script: IScriptingDefinition) {
|
||||
public withScripting(script: IScriptingDefinition): CategoryCollectionBuilder {
|
||||
this.script = script;
|
||||
return this;
|
||||
}
|
||||
public construct(): Application {
|
||||
return new Application(this.os, this.info, this.actions, this.script);
|
||||
public construct(): CategoryCollection {
|
||||
return new CategoryCollection(this.os, this.info, this.actions, this.script);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { getScriptNodeId, getScriptId, getCategoryNodeId, getCategoryId } from '
|
||||
import { CategoryStub } from '../../../stubs/CategoryStub';
|
||||
import { ScriptStub } from '../../../stubs/ScriptStub';
|
||||
import { parseSingleCategory, parseAllCategories } from '@/presentation/Scripts/ScriptsTree/ScriptNodeParser';
|
||||
import { ApplicationStub } from '../../../stubs/ApplicationStub';
|
||||
import { CategoryCollectionStub } from '../../../stubs/CategoryCollectionStub';
|
||||
import { INode, NodeType } from '@/presentation/Scripts/ScriptsTree/SelectableTree/Node/INode';
|
||||
import { IScript } from '@/domain/IScript';
|
||||
import { ICategory } from '@/domain/ICategory';
|
||||
@@ -36,11 +36,11 @@ describe('ScriptNodeParser', () => {
|
||||
const secondSubCategory = new CategoryStub(categoryId)
|
||||
.withCategory(new CategoryStub(33).withScriptIds('331', '331'))
|
||||
.withCategory(new CategoryStub(44).withScriptIds('44'));
|
||||
const app = new ApplicationStub().withAction(new CategoryStub(categoryId)
|
||||
const collection = new CategoryCollectionStub().withAction(new CategoryStub(categoryId)
|
||||
.withCategory(firstSubCategory)
|
||||
.withCategory(secondSubCategory));
|
||||
// act
|
||||
const nodes = parseSingleCategory(categoryId, app);
|
||||
const nodes = parseSingleCategory(categoryId, collection);
|
||||
// assert
|
||||
expect(nodes).to.have.lengthOf(2);
|
||||
expectSameCategory(nodes[0], firstSubCategory);
|
||||
@@ -50,9 +50,10 @@ describe('ScriptNodeParser', () => {
|
||||
// arrange
|
||||
const categoryId = 31;
|
||||
const scripts = [ new ScriptStub('script1'), new ScriptStub('script2'), new ScriptStub('script3') ];
|
||||
const app = new ApplicationStub().withAction(new CategoryStub(categoryId).withScripts(...scripts));
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(categoryId).withScripts(...scripts));
|
||||
// act
|
||||
const nodes = parseSingleCategory(categoryId, app);
|
||||
const nodes = parseSingleCategory(categoryId, collection);
|
||||
// assert
|
||||
expect(nodes).to.have.lengthOf(3);
|
||||
expectSameScript(nodes[0], scripts[0]);
|
||||
@@ -63,18 +64,18 @@ describe('ScriptNodeParser', () => {
|
||||
|
||||
it('parseAllCategories parses as expected', () => {
|
||||
// arrange
|
||||
const app = new ApplicationStub()
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(0).withScriptIds('1, 2'))
|
||||
.withAction(new CategoryStub(1).withCategories(
|
||||
new CategoryStub(3).withScriptIds('3', '4'),
|
||||
new CategoryStub(4).withCategory(new CategoryStub(5).withScriptIds('6')),
|
||||
));
|
||||
// act
|
||||
const nodes = parseAllCategories(app);
|
||||
const nodes = parseAllCategories(collection);
|
||||
// assert
|
||||
expect(nodes).to.have.lengthOf(2);
|
||||
expectSameCategory(nodes[0], app.actions[0]);
|
||||
expectSameCategory(nodes[1], app.actions[1]);
|
||||
expectSameCategory(nodes[0], collection.actions[0]);
|
||||
expectSameCategory(nodes[1], collection.actions[1]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ScriptStub } from '../../../../../../stubs/ScriptStub';
|
||||
import { CategoryReverter } from '@/presentation/Scripts/ScriptsTree/SelectableTree/Node/Reverter/CategoryReverter';
|
||||
import { getCategoryNodeId } from '@/presentation/Scripts/ScriptsTree/ScriptNodeParser';
|
||||
import { CategoryStub } from '../../../../../../stubs/CategoryStub';
|
||||
import { ApplicationStub } from '../../../../../../stubs/ApplicationStub';
|
||||
import { CategoryCollectionStub } from '../../../../../../stubs/CategoryCollectionStub';
|
||||
import { SelectedScript } from '@/application/Context/State/Selection/SelectedScript';
|
||||
import { UserSelection } from '@/application/Context/State/Selection/UserSelection';
|
||||
|
||||
@@ -17,8 +17,8 @@ describe('CategoryReverter', () => {
|
||||
];
|
||||
const category = new CategoryStub(1).withScripts(...scripts);
|
||||
const nodeId = getCategoryNodeId(category);
|
||||
const app = new ApplicationStub().withAction(category);
|
||||
const sut = new CategoryReverter(nodeId, app);
|
||||
const collection = new CategoryCollectionStub().withAction(category);
|
||||
const sut = new CategoryReverter(nodeId, collection);
|
||||
const testCases = [
|
||||
{
|
||||
name: 'false when subscripts are not reverted',
|
||||
@@ -52,7 +52,7 @@ describe('CategoryReverter', () => {
|
||||
new ScriptStub('revertable2').withRevertCode('REM revert me 2'),
|
||||
];
|
||||
const category = new CategoryStub(1).withScripts(...scripts);
|
||||
const app = new ApplicationStub().withAction(category);
|
||||
const collection = new CategoryCollectionStub().withAction(category);
|
||||
const testCases = [
|
||||
{
|
||||
name: 'selects with revert state when not selected',
|
||||
@@ -88,8 +88,8 @@ describe('CategoryReverter', () => {
|
||||
const nodeId = getCategoryNodeId(category);
|
||||
for (const testCase of testCases) {
|
||||
it(testCase.name, () => {
|
||||
const selection = new UserSelection(app, testCase.selection);
|
||||
const sut = new CategoryReverter(nodeId, app);
|
||||
const selection = new UserSelection(collection, testCase.selection);
|
||||
const sut = new CategoryReverter(nodeId, collection);
|
||||
// act
|
||||
sut.selectWithRevertState(testCase.revert, selection);
|
||||
// assert
|
||||
|
||||
@@ -4,7 +4,7 @@ import { INode, NodeType } from '@/presentation/Scripts/ScriptsTree/SelectableTr
|
||||
import { getReverter } from '@/presentation/Scripts/ScriptsTree/SelectableTree/Node/Reverter/ReverterFactory';
|
||||
import { ScriptReverter } from '@/presentation/Scripts/ScriptsTree/SelectableTree/Node/Reverter/ScriptReverter';
|
||||
import { CategoryReverter } from '@/presentation/Scripts/ScriptsTree/SelectableTree/Node/Reverter/CategoryReverter';
|
||||
import { ApplicationStub } from '../../../../../../stubs/ApplicationStub';
|
||||
import { CategoryCollectionStub } from '../../../../../../stubs/CategoryCollectionStub';
|
||||
import { CategoryStub } from '../../../../../../stubs/CategoryStub';
|
||||
import { getScriptNodeId, getCategoryNodeId } from '@/presentation/Scripts/ScriptsTree/ScriptNodeParser';
|
||||
import { ScriptStub } from '../../../../../../stubs/ScriptStub';
|
||||
@@ -15,9 +15,10 @@ describe('ReverterFactory', () => {
|
||||
// arrange
|
||||
const category = new CategoryStub(0).withScriptIds('55');
|
||||
const node = getNodeStub(getCategoryNodeId(category), NodeType.Category);
|
||||
const app = new ApplicationStub().withAction(category);
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(category);
|
||||
// act
|
||||
const result = getReverter(node, app);
|
||||
const result = getReverter(node, collection);
|
||||
// assert
|
||||
expect(result instanceof CategoryReverter).to.equal(true);
|
||||
});
|
||||
@@ -25,9 +26,10 @@ describe('ReverterFactory', () => {
|
||||
// arrange
|
||||
const script = new ScriptStub('test');
|
||||
const node = getNodeStub(getScriptNodeId(script), NodeType.Script);
|
||||
const app = new ApplicationStub().withAction(new CategoryStub(0).withScript(script));
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(0).withScript(script));
|
||||
// act
|
||||
const result = getReverter(node, app);
|
||||
const result = getReverter(node, collection);
|
||||
// assert
|
||||
expect(result instanceof ScriptReverter).to.equal(true);
|
||||
});
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { ScriptReverter } from '@/presentation/Scripts/ScriptsTree/SelectableTree/Node/Reverter/ScriptReverter';
|
||||
import { SelectedScriptStub } from '../../../../../../stubs/SelectedScriptStub';
|
||||
import { getScriptNodeId } from '@/presentation/Scripts/ScriptsTree/ScriptNodeParser';
|
||||
import { ScriptStub } from '../../../../../../stubs/ScriptStub';
|
||||
import { UserSelection } from '@/application/Context/State/Selection/UserSelection';
|
||||
import { SelectedScript } from '@/application/Context/State/Selection/SelectedScript';
|
||||
import { ApplicationStub } from '../../../../../../stubs/ApplicationStub';
|
||||
import { CategoryCollectionStub } from '../../../../../../stubs/CategoryCollectionStub';
|
||||
import { CategoryStub } from '../../../../../../stubs/CategoryStub';
|
||||
import { ScriptStub } from '../../../../../../stubs/ScriptStub';
|
||||
import { SelectedScriptStub } from '../../../../../../stubs/SelectedScriptStub';
|
||||
|
||||
describe('ScriptReverter', () => {
|
||||
describe('getState', () => {
|
||||
@@ -45,7 +45,8 @@ describe('ScriptReverter', () => {
|
||||
describe('selectWithRevertState', () => {
|
||||
// arrange
|
||||
const script = new ScriptStub('id');
|
||||
const app = new ApplicationStub().withAction(new CategoryStub(5).withScript(script));
|
||||
const collection = new CategoryCollectionStub()
|
||||
.withAction(new CategoryStub(5).withScript(script));
|
||||
const testCases = [
|
||||
{
|
||||
name: 'selects with revert state when not selected',
|
||||
@@ -75,7 +76,7 @@ describe('ScriptReverter', () => {
|
||||
const nodeId = getScriptNodeId(script);
|
||||
for (const testCase of testCases) {
|
||||
it(testCase.name, () => {
|
||||
const selection = new UserSelection(app, testCase.selection);
|
||||
const selection = new UserSelection(collection, testCase.selection);
|
||||
const sut = new ScriptReverter(nodeId);
|
||||
// act
|
||||
sut.selectWithRevertState(testCase.revert, selection);
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { ScriptingDefinitionStub } from './ScriptingDefinitionStub';
|
||||
import { IApplication, ICategory, IScript } from '@/domain/IApplication';
|
||||
import { ProjectInformation } from '@/domain/ProjectInformation';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { ScriptStub } from './ScriptStub';
|
||||
import { IScriptingDefinition } from '@/domain/IScriptingDefinition';
|
||||
import { IScript } from '@/domain/IScript';
|
||||
import { ICategory } from '@/domain/ICategory';
|
||||
import { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
|
||||
export class ApplicationStub implements IApplication {
|
||||
export class CategoryCollectionStub implements ICategoryCollection {
|
||||
public scripting: IScriptingDefinition = new ScriptingDefinitionStub();
|
||||
public os = OperatingSystem.Linux;
|
||||
public initialScript: IScript = new ScriptStub('55');
|
||||
@@ -14,19 +16,19 @@ export class ApplicationStub implements IApplication {
|
||||
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): ApplicationStub {
|
||||
public withAction(category: ICategory): CategoryCollectionStub {
|
||||
this.actions.push(category);
|
||||
return this;
|
||||
}
|
||||
public withOs(os: OperatingSystem): ApplicationStub {
|
||||
public withOs(os: OperatingSystem): CategoryCollectionStub {
|
||||
this.os = os;
|
||||
return this;
|
||||
}
|
||||
public withScripting(scripting: IScriptingDefinition): ApplicationStub {
|
||||
public withScripting(scripting: IScriptingDefinition): CategoryCollectionStub {
|
||||
this.scripting = scripting;
|
||||
return this;
|
||||
}
|
||||
public withInitialScript(script: IScript): ApplicationStub {
|
||||
public withInitialScript(script: IScript): CategoryCollectionStub {
|
||||
this.initialScript = script;
|
||||
return this;
|
||||
}
|
||||
Reference in New Issue
Block a user