add auto-highlighting of selected/updated code
This commit is contained in:
89
tests/unit/domain/Category.spec.ts
Normal file
89
tests/unit/domain/Category.spec.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { Category } from '@/domain/Category';
|
||||
import { CategoryStub } from '../stubs/CategoryStub';
|
||||
import { ScriptStub } from '../stubs/ScriptStub';
|
||||
|
||||
describe('Category', () => {
|
||||
describe('ctor', () => {
|
||||
it('throws when name is empty', () => {
|
||||
const expectedError = 'undefined or empty name';
|
||||
const construct = () => new Category(5, '', [], [new CategoryStub(5)], []);
|
||||
expect(construct).to.throw(expectedError);
|
||||
});
|
||||
it('throws when has no children', () => {
|
||||
const expectedError = 'A category must have at least one sub-category or script';
|
||||
const construct = () => new Category(5, 'category', [], [], []);
|
||||
expect(construct).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
describe('getAllScriptsRecursively', () => {
|
||||
it('gets child scripts', () => {
|
||||
// arrange
|
||||
const expected = [ new ScriptStub('1'), new ScriptStub('2') ];
|
||||
const sut = new Category(0, 'category', [], [], expected);
|
||||
// act
|
||||
const actual = sut.getAllScriptsRecursively();
|
||||
// assert
|
||||
expect(actual).to.have.deep.members(expected);
|
||||
});
|
||||
it('gets child categories', () => {
|
||||
// arrange
|
||||
const expectedScriptIds = ['1', '2', '3', '4'];
|
||||
const categories = [
|
||||
new CategoryStub(31).withScriptIds('1', '2'),
|
||||
new CategoryStub(32).withScriptIds('3', '4'),
|
||||
];
|
||||
const sut = new Category(0, 'category', [], categories, []);
|
||||
// act
|
||||
const actualIds = sut.getAllScriptsRecursively().map((s) => s.id);
|
||||
// assert
|
||||
expect(actualIds).to.have.deep.members(expectedScriptIds);
|
||||
|
||||
});
|
||||
it('gets child scripts and categories', () => {
|
||||
// arrange
|
||||
const expectedScriptIds = ['1', '2', '3', '4', '5' , '6'];
|
||||
const categories = [
|
||||
new CategoryStub(31).withScriptIds('1', '2'),
|
||||
new CategoryStub(32).withScriptIds('3', '4'),
|
||||
];
|
||||
const scripts = [ new ScriptStub('5'), new ScriptStub('6') ];
|
||||
const sut = new Category(0, 'category', [], categories, scripts);
|
||||
// act
|
||||
const actualIds = sut.getAllScriptsRecursively().map((s) => s.id);
|
||||
// assert
|
||||
expect(actualIds).to.have.deep.members(expectedScriptIds);
|
||||
|
||||
});
|
||||
it('gets child categories recursively', () => {
|
||||
// arrange
|
||||
const expectedScriptIds = ['1', '2', '3', '4', '5', '6'];
|
||||
const categories = [
|
||||
new CategoryStub(31)
|
||||
.withScriptIds('1', '2')
|
||||
.withCategory(
|
||||
new CategoryStub(32)
|
||||
.withScriptIds('3', '4'),
|
||||
),
|
||||
new CategoryStub(33)
|
||||
.withCategories(
|
||||
new CategoryStub(34)
|
||||
.withScriptIds('5')
|
||||
.withCategory(
|
||||
new CategoryStub(35)
|
||||
.withCategory(
|
||||
new CategoryStub(35).withScriptIds('6'),
|
||||
),
|
||||
),
|
||||
),
|
||||
];
|
||||
// assert
|
||||
const sut = new Category(0, 'category', [], categories, []);
|
||||
// act
|
||||
const actualIds = sut.getAllScriptsRecursively().map((s) => s.id);
|
||||
// assert
|
||||
expect(actualIds).to.have.deep.members(expectedScriptIds);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user