Skip to content

Commit

Permalink
broke react, passing feature switches through ctor.
Browse files Browse the repository at this point in the history
  • Loading branch information
ds committed Jan 6, 2024
1 parent 6dc1744 commit 330d307
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 57 deletions.
6 changes: 4 additions & 2 deletions frontend/src/__tests__/GivenAcceleratora.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ jest.mock('react', () => ({
useContext.mockReturnValue({});

describe('Given Accelerator components', function () {
const mockContextValue = useContext();

test('When accelerator is specificed then convert output is correct', function () {
let actual = 'accelerator randomkey [0.9, 0.1]' + '\n';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);
expect(result.accelerators.length).toEqual(1);
expect(result.accelerators[0].name).toEqual('randomkey');
});

test('When deaccelerator is specificed then convert output is correct', function () {
let actual = 'deaccelerator randomkey [0.9, 0.1]' + '\n';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);
expect(result.accelerators.length).toEqual(1);
expect(result.accelerators[0].name).toEqual('randomkey');
expect(result.accelerators[0].deaccelerator).toEqual(true);
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/__tests__/GivenComponentsEvolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ jest.mock('react', () => ({
useContext: jest.fn(),
}));

useContext.mockReturnValue({});
useContext.mockReturnValue({ enableNewPipelines: false });

describe('Given Components Evolve', function () {
const mockContextValue = useContext();
test('When evolve text is supplied then convert output is correct', function () {
let actual = 'component Foo [0.9, 0.1]' + '\n' + 'evolve Foo 0.9';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);
const mergeables = [{ collection: result.elements, type: 'component' }];
let me = new MapElements(mergeables, result.evolved);
let evolved = me.getEvolveElements();
Expand All @@ -25,7 +26,7 @@ describe('Given Components Evolve', function () {

test('When evolve text is supplied with overriding label, ensure label is mutated', function () {
let actual = 'component Foo [0.9, 0.1]' + '\n' + 'evolve Foo->Bar 0.9';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);
const mergeables = [{ collection: result.elements, type: 'component' }];
let me = new MapElements(mergeables, result.evolved);
let evolved = me.getEvolveElements();
Expand All @@ -42,7 +43,7 @@ describe('Given Components Evolve', function () {
'component Foo [0.1, 0.1] label [66,99]' +
'\n' +
'evolve Foo 0.9 label [-33, -55]';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);
const mergeables = [{ collection: result.elements, type: 'component' }];
let me = new MapElements(mergeables, result.evolved);
let evolving = me.getEvolveElements();
Expand Down
14 changes: 8 additions & 6 deletions frontend/src/__tests__/GivenComponentsHavePipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ useContext.mockReturnValue({
});

describe('Given Components Have Pipelines', function () {
const mockContextValue = useContext();

test('When pipeline is specificed then convert output is correct', function () {
let actual =
'component Foo [0.9, 0.1]' + '\n' + 'pipeline Foo [0.15, 0.65]';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);
const mergeables = [{ collection: result.elements, type: 'component' }];
let me = new MapElements(mergeables, result.evolved, result.pipelines);
let pipelines = me.getMapPipelines();
Expand All @@ -31,7 +33,7 @@ describe('Given Components Have Pipelines', function () {

test('When pipeline is specificed but boundaries are not defined, pipeline should be hidden and returns', function () {
let actual = 'component Foo [0.9, 0.1]' + '\n' + 'pipeline Foo';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);
const mergeables = [{ collection: result.elements, type: 'component' }];
let me = new MapElements(mergeables, result.evolved, result.pipelines);
let pipelines = me.getMapPipelines();
Expand All @@ -55,7 +57,7 @@ describe('Given Components Have Pipelines', function () {
'component FooBar [0.11]' +
'\n' +
'}';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);
const mergeables = [{ collection: result.elements, type: 'component' }];
let me = new MapElements(mergeables, result.evolved, result.pipelines);
let pipelines = me.getMapPipelines();
Expand All @@ -79,7 +81,7 @@ describe('Given Components Have Pipelines', function () {
'component FooBar [0.11]' +
'\n' +
'}';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);
const mergeables = [{ collection: result.elements, type: 'component' }];
let me = new MapElements(mergeables, result.evolved, result.pipelines);
let pipelines = me.getMapPipelines();
Expand All @@ -104,7 +106,7 @@ describe('Given Components Have Pipelines', function () {
'component Bar [0.65]' +
'\n' +
'}';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);
const mergeables = [{ collection: result.elements, type: 'component' }];
let me = new MapElements(mergeables, result.evolved, result.pipelines);
let pipelines = me.getMapPipelines();
Expand All @@ -131,7 +133,7 @@ describe('Given Components Have Pipelines', function () {
'\n' +
'component FooBar [0.41]';
'\n' + '}';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);
const mergeables = [{ collection: result.elements, type: 'component' }];
let me = new MapElements(mergeables, result.evolved, result.pipelines);
let pipelines = me.getMapPipelines();
Expand Down
64 changes: 33 additions & 31 deletions frontend/src/__tests__/GivenConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jest.mock('react', () => ({
useContext.mockReturnValue({});

describe('Convert test suite', function () {
const mockContextValue = useContext();

const genericMapComponents = [
{ keyword: 'component', container: 'elements' },
{ keyword: 'market', container: 'markets' },
Expand All @@ -17,7 +19,7 @@ describe('Convert test suite', function () {
test('should create mapJson Object with title property', function () {
let expected = 'This is an example map';
let actual = `title ${expected}`;
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.title).toEqual(expected);
});
Expand All @@ -26,7 +28,7 @@ describe('Convert test suite', function () {
'should create map component from string',
(e) => {
let actual = `${e.keyword} Customer [1, 0.4]\n${e.keyword} Customer2 [0,0.1]`;
let obj = new Converter();
let obj = new Converter(mockContextValue);
let result = obj.parse(actual);
expect(result[e.container][0].id).toEqual(1);
expect(result[e.container][0].name).toEqual('Customer');
Expand All @@ -45,7 +47,7 @@ describe('Convert test suite', function () {
(e) => {
let actual = `${e.keyword} Customer [1, 0.4] inertia\n`;

let obj = new Converter();
let obj = new Converter(mockContextValue);
let result = obj.parse(actual);

expect(result[e.container][0].id).toEqual(1);
Expand All @@ -60,7 +62,7 @@ describe('Convert test suite', function () {
let actual =
'component Customer [1, 0.4]\ncomponent Customer2 [0,0.1]\nCustomer->Customer2';

let obj = new Converter();
let obj = new Converter(mockContextValue);
let result = obj.parse(actual);

expect(result.links[0].start).toEqual('Customer');
Expand All @@ -72,7 +74,7 @@ describe('Convert test suite', function () {
let actual =
'component Sales marketing [1, 0.4]\ncomponent Sales ecosystem [0,0.1]\nSales marketing->Sales ecosystem';

let obj = new Converter();
let obj = new Converter(mockContextValue);
let result = obj.parse(actual);

expect(result.links[0].start).toEqual('Sales marketing');
Expand All @@ -84,7 +86,7 @@ describe('Convert test suite', function () {
let actual =
'component Customer [1, 0.4]\ncomponent Customer2 [0,0.1]\nCustomer+>Customer2';

let obj = new Converter();
let obj = new Converter(mockContextValue);
let result = obj.parse(actual);

expect(result.links[0].start).toEqual('Customer');
Expand All @@ -97,7 +99,7 @@ describe('Convert test suite', function () {
actual = actual + '\n';
actual = actual + "Customer+'5.88'>Customer2";

let obj = new Converter();
let obj = new Converter(mockContextValue);
let result = obj.parse(actual);

expect(result.links[0].start).toEqual('Customer');
Expand All @@ -114,7 +116,7 @@ describe('Convert test suite', function () {
actual = actual + '\r\n ';
actual = actual + '\r\n ';

let obj = new Converter();
let obj = new Converter(mockContextValue);
let result = obj.parse(actual);

expect(result.links[0].start).toEqual('Customer');
Expand All @@ -124,7 +126,7 @@ describe('Convert test suite', function () {
test('should set evolution', function () {
let actual = 'evolution Novel->Emerging->Good->Best';

let obj = new Converter();
let obj = new Converter(mockContextValue);
let result = obj.parse(actual);

expect(result.evolution[0].line1).toEqual('Novel');
Expand All @@ -136,7 +138,7 @@ describe('Convert test suite', function () {
test('should create map object with annotations property with an annotation with a single occurance', function () {
let actual =
'annotation 1 [.38,.4] Standardising power allows Kettles to evolve faster';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.annotations.length).toEqual(1);
expect(result.annotations[0].number).toEqual(1);
Expand All @@ -149,7 +151,7 @@ describe('Convert test suite', function () {

test('should create map object with annotations property with an annotation with many occurances with no text', function () {
let actual = 'annotation 1 [[.38, .4],[0.44, 0.33]]';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.annotations.length).toEqual(1);
expect(result.annotations[0].number).toEqual(1);
Expand All @@ -161,7 +163,7 @@ describe('Convert test suite', function () {
test('should create map object with annotations property with an annotation with many occurances', function () {
let actual =
'annotation 1 [[.38, .4],[0.44, 0.33],[0.11, 0.22] ] Standardising power allows Kettles to evolve faster';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.annotations.length).toEqual(1);
expect(result.annotations[0].number).toEqual(1);
Expand All @@ -177,43 +179,43 @@ describe('Convert test suite', function () {

test('should create map object with map style data', function () {
let actual = 'style wardley';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.presentation.style).toEqual('wardley');
});

test('should create map object with annotations positional data', function () {
let actual = 'annotations [.38, .4]';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.presentation.annotations.visibility).toEqual(0.38);
expect(result.presentation.annotations.maturity).toEqual(0.4);
});

test('should not create map object with annotations when incomplete', function () {
let actual = 'annotation ';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.annotations.length).toEqual(0);
});

test('should not create map object with annotations when incomplete', function () {
let actual = 'annotation 1';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.annotations.length).toEqual(0);
});

test('comments are ignored', function () {
let actual = '// hello world.';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.elements.length).toEqual(0);
});

test('comments are ignored', function () {
let actual = '/* hello world.\r\n* something\r\n*/';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.elements.length).toEqual(0);
});
Expand All @@ -222,7 +224,7 @@ describe('Convert test suite', function () {
'map component with little info is still made available to the map',
(e) => {
let actual = `${e.keyword} Foo []`;
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result[e.container].length).toEqual(1);
expect(result[e.container][0].visibility).toEqual(0.9);
Expand All @@ -232,7 +234,7 @@ describe('Convert test suite', function () {

test('anchor with little info is still made available to the map', function () {
let actual = 'anchor Foo []';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.anchors.length).toEqual(1);
expect(result.anchors[0].visibility).toEqual(0.9);
Expand All @@ -243,7 +245,7 @@ describe('Convert test suite', function () {
'map component with little info is still made available to the map',
(e) => {
let actual = `${e.keyword} Foo`;
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result[e.container].length).toEqual(1);
expect(result[e.container][0].visibility).toEqual(0.9);
Expand All @@ -253,7 +255,7 @@ describe('Convert test suite', function () {

test('notes are extracted and made available to the map', function () {
let actual = 'note some text [0.9, 0.1]';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.notes.length).toEqual(1);
expect(result.notes[0].text).toEqual('some text');
Expand All @@ -263,7 +265,7 @@ describe('Convert test suite', function () {

test('notes with note in the text still works', function () {
let actual = 'note a generic note appeard [0.9, 0.1]';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.notes.length).toEqual(1);
expect(result.notes[0].text).toEqual('a generic note appeard');
Expand All @@ -273,7 +275,7 @@ describe('Convert test suite', function () {

test('notes starting with space works correctly', function () {
let actual = ' note a generic note appeard [0.9, 0.1]';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.notes.length).toEqual(1);
expect(result.notes[0].text).toEqual('a generic note appeard');
Expand All @@ -283,7 +285,7 @@ describe('Convert test suite', function () {

test('notes with little info is still made available to the map', function () {
let actual = 'note Foo []';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.notes.length).toEqual(1);
expect(result.notes[0].visibility).toEqual(0.9);
Expand All @@ -294,7 +296,7 @@ describe('Convert test suite', function () {
'map component with label position then position is available to map',
(e) => {
let actual = `${e.keyword} Foo [0.9, 0.1] label [66,99] inertia evolve 0.9`;
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result[e.container].length).toEqual(1);
expect(result[e.container][0].visibility).toEqual(0.9);
Expand All @@ -306,7 +308,7 @@ describe('Convert test suite', function () {

test('pipelines made available to the map', function () {
let actual = 'pipeline Foo [0.05, 0.95]';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.pipelines.length).toEqual(1);
expect(result.pipelines[0].name).toEqual('Foo');
Expand All @@ -317,7 +319,7 @@ describe('Convert test suite', function () {

test('pipelines made available to the map but set to hidden', function () {
let actual = 'pipeline Foo';
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.pipelines.length).toEqual(1);
expect(result.pipelines[0].name).toEqual('Foo');
Expand All @@ -330,7 +332,7 @@ describe('Convert test suite', function () {
'pioneers are extracted with width and height',
function (x) {
let actual = `${x} [0.98, 0.5] 100 200`;
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.attitudes.length).toEqual(1);
expect(result.attitudes[0].maturity).toEqual(0.5);
Expand All @@ -344,7 +346,7 @@ describe('Convert test suite', function () {
'pioneers are extracted with matruity and visibility for width height',
function (x) {
let actual = `${x} [0.98, 0.5, 0.6, 0.7]`;
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.attitudes.length).toEqual(1);
expect(result.attitudes[0].maturity).toEqual(0.5);
Expand All @@ -356,7 +358,7 @@ describe('Convert test suite', function () {

test.each(['build', 'buy', 'outsource'])('methods are extracted', (k) => {
let actual = `${k} Foo Bar`;
let result = new Converter().parse(actual);
let result = new Converter(mockContextValue).parse(actual);

expect(result.methods.length).toEqual(1);
expect(result.methods[0].name).toEqual('Foo Bar');
Expand Down
Loading

0 comments on commit 330d307

Please sign in to comment.