mirror of
https://github.com/noodlapp/noodl.git
synced 2026-01-12 15:22:52 +01:00
Initial commit
Co-Authored-By: Eric Tuvesson <eric.tuvesson@gmail.com> Co-Authored-By: mikaeltellhed <2311083+mikaeltellhed@users.noreply.github.com> Co-Authored-By: kotte <14197736+mrtamagotchi@users.noreply.github.com> Co-Authored-By: Anders Larsson <64838990+anders-topp@users.noreply.github.com> Co-Authored-By: Johan <4934465+joolsus@users.noreply.github.com> Co-Authored-By: Tore Knudsen <18231882+torekndsn@users.noreply.github.com> Co-Authored-By: victoratndl <99176179+victoratndl@users.noreply.github.com>
This commit is contained in:
5
packages/noodl-editor/tests/projectmerger/index.ts
Normal file
5
packages/noodl-editor/tests/projectmerger/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export * from './projectmerger-comments';
|
||||
export * from './projectmerger-diff';
|
||||
export * from './projectmerger-states';
|
||||
export * from './projectmerger-variants';
|
||||
export * from './projectmerger';
|
||||
@@ -0,0 +1,302 @@
|
||||
var ProjectMerger = require('@noodl-utils/projectmerger');
|
||||
|
||||
function mergeComments(base, ours, theirs) {
|
||||
const baseComponent = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [],
|
||||
comments: base
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const ourComponent = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [],
|
||||
comments: ours
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const theirComponent = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [],
|
||||
comments: theirs
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
return ProjectMerger.mergeProject(baseComponent, ourComponent, theirComponent);
|
||||
}
|
||||
// Project settings
|
||||
describe('Project merger - comments', function () {
|
||||
it('can merge new comments', function () {
|
||||
const ours = [
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hej',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const theirs = [
|
||||
{
|
||||
id: 'c2',
|
||||
text: 'hopp',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const res = mergeComments(undefined, ours, theirs);
|
||||
|
||||
expect(res.components[0].graph.comments).toEqual([
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hej',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
},
|
||||
{
|
||||
id: 'c2',
|
||||
text: 'hopp',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it('can merge updated comments - theirs updated', function () {
|
||||
const base = [
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hej',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const ours = [
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hej',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const theirs = [
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hopp',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const res = mergeComments(base, ours, theirs);
|
||||
|
||||
expect(res.components[0].graph.comments).toEqual([
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hopp',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it('can merge updated comments - ours updated', function () {
|
||||
const base = [
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hej',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const ours = [
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hopp',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const theirs = [
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hej',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const res = mergeComments(base, ours, theirs);
|
||||
|
||||
expect(res.components[0].graph.comments).toEqual([
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hopp',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it('can merge deleted comments - ours deleted', function () {
|
||||
const base = [
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hej',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const ours = [];
|
||||
const theirs = [
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hej',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const res = mergeComments(base, ours, theirs);
|
||||
|
||||
expect(res.components[0].graph.comments).toEqual([]);
|
||||
});
|
||||
|
||||
it('can merge deleted comments - theirs deleted', function () {
|
||||
const base = [
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hej',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const ours = [
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hej',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const theirs = [];
|
||||
const res = mergeComments(base, ours, theirs);
|
||||
|
||||
expect(res.components[0].graph.comments).toEqual([]);
|
||||
});
|
||||
|
||||
it('can merge deleted and changed comments - ours modified, theirs deleted', function () {
|
||||
const base = [
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hej',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const ours = [
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hopp',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const theirs = [];
|
||||
const res = mergeComments(base, ours, theirs);
|
||||
|
||||
expect(res.components[0].graph.comments).toEqual([
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hopp',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it('can merge deleted and changed comments - ours deleted, theirs modified', function () {
|
||||
const base = [
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hej',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const ours = [];
|
||||
const theirs = [
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hopp',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
];
|
||||
const res = mergeComments(base, ours, theirs);
|
||||
|
||||
expect(res.components[0].graph.comments).toEqual([
|
||||
{
|
||||
id: 'c1',
|
||||
text: 'hopp',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}
|
||||
]);
|
||||
});
|
||||
});
|
||||
155
packages/noodl-editor/tests/projectmerger/projectmerger-diff.js
Normal file
155
packages/noodl-editor/tests/projectmerger/projectmerger-diff.js
Normal file
@@ -0,0 +1,155 @@
|
||||
var { diffProject } = require('@noodl-utils/projectmerger.diff');
|
||||
var fs = require('fs');
|
||||
var Process = require('process');
|
||||
|
||||
// Project settings
|
||||
describe('Project merger diff', function () {
|
||||
it('can diff two identical projects without reporting any changes', function () {
|
||||
const base = JSON.parse(
|
||||
fs.readFileSync(
|
||||
Process.cwd() + '/tests/testfs/merge-tests/move-nodes/base-merge-project-Wed--03-Feb-2021-11-07-55-GMT.json'
|
||||
)
|
||||
);
|
||||
const diff = diffProject(base, base);
|
||||
|
||||
expect(diff.components.changed.length).toBe(0, 'no changed components');
|
||||
expect(diff.components.created.length).toBe(0, 'no created components');
|
||||
expect(diff.components.deleted.length).toBe(0, 'no deleted components');
|
||||
expect(diff.components.unchanged.length).toBe(base.components.length, 'all components unchanged');
|
||||
});
|
||||
|
||||
it('can diff with one node changes', function () {
|
||||
const base = JSON.parse(
|
||||
fs.readFileSync(
|
||||
Process.cwd() + '/tests/testfs/merge-tests/move-nodes/base-merge-project-Wed--03-Feb-2021-11-07-55-GMT.json'
|
||||
)
|
||||
);
|
||||
const current = JSON.parse(JSON.stringify(base));
|
||||
|
||||
//modify a text node
|
||||
current.components[0].graph.roots[0].children[0].parameters.text = 'Hello 2';
|
||||
|
||||
const diff = diffProject(base, current);
|
||||
|
||||
expect(diff.components.changed.length).toBe(1, 'should have one changed component');
|
||||
expect(diff.components.created.length).toBe(0, 'no created components');
|
||||
expect(diff.components.deleted.length).toBe(0, 'no deleted components');
|
||||
expect(diff.components.unchanged.length).toBe(base.components.length - 1);
|
||||
});
|
||||
|
||||
it('diff ignores metadata', function () {
|
||||
const base = JSON.parse(
|
||||
fs.readFileSync(
|
||||
Process.cwd() + '/tests/testfs/merge-tests/move-nodes/base-merge-project-Wed--03-Feb-2021-11-07-55-GMT.json'
|
||||
)
|
||||
);
|
||||
const current = JSON.parse(JSON.stringify(base));
|
||||
|
||||
// change metadata in component
|
||||
current.components[0].metadata.canvasPos.x = 50;
|
||||
current.components[0].graph.roots[0].dynamicports = [
|
||||
{
|
||||
name: 'testy',
|
||||
type: 'string'
|
||||
}
|
||||
];
|
||||
|
||||
//change metadata in node
|
||||
current.components[0].graph.roots[0].metadata = {
|
||||
sourceCodePorts: ['test']
|
||||
};
|
||||
|
||||
const diff = diffProject(base, current);
|
||||
|
||||
expect(diff.components.changed.length).toBe(0, 'no changed components');
|
||||
expect(diff.components.created.length).toBe(0, 'no created components');
|
||||
expect(diff.components.deleted.length).toBe(0, 'no deleted components');
|
||||
expect(diff.components.unchanged.length).toBe(base.components.length, 'all components unchanged');
|
||||
});
|
||||
|
||||
it('can diff variants', function () {
|
||||
const base = {
|
||||
components: [],
|
||||
variants: [
|
||||
{
|
||||
name: 'A',
|
||||
typename: 'A',
|
||||
parameters: {
|
||||
p1: 10
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'A',
|
||||
typename: 'B',
|
||||
parameters: {
|
||||
p1: 'test'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'C',
|
||||
typename: 'C',
|
||||
parameters: {
|
||||
p1: 10
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
const current = {
|
||||
components: [],
|
||||
variants: [
|
||||
{
|
||||
name: 'A',
|
||||
typename: 'A',
|
||||
parameters: {
|
||||
p2: 20
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'B',
|
||||
typename: 'A',
|
||||
parameters: {
|
||||
p1: 'test'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'C',
|
||||
typename: 'C',
|
||||
parameters: {
|
||||
p1: 10
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const diff = diffProject(base, current);
|
||||
|
||||
expect(diff.variants.changed.length).toBe(1);
|
||||
expect(diff.variants.created.length).toBe(1);
|
||||
expect(diff.variants.unchanged.length).toBe(1);
|
||||
});
|
||||
|
||||
it('can diff settings', function () {
|
||||
const base = {
|
||||
components: [],
|
||||
settings: {
|
||||
htmlTitle: 'A',
|
||||
headCode: 'lolol',
|
||||
someSetting: 'abc'
|
||||
}
|
||||
};
|
||||
const current = {
|
||||
components: [],
|
||||
settings: {
|
||||
htmlTitle: 'B',
|
||||
bodyScroll: true,
|
||||
someSetting: 'abc'
|
||||
}
|
||||
};
|
||||
const diff = diffProject(base, current);
|
||||
|
||||
expect(diff.settings.changed.length).toBe(1);
|
||||
expect(diff.settings.created.length).toBe(1);
|
||||
expect(diff.settings.deleted.length).toBe(1);
|
||||
expect(diff.settings.unchanged.length).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,557 @@
|
||||
var ProjectMerger = require('@noodl-utils/projectmerger');
|
||||
var NodeLibrary = require('@noodl-models/nodelibrary').NodeLibrary;
|
||||
var fs = require('fs');
|
||||
var Process = require('process');
|
||||
|
||||
// Project settings
|
||||
describe('Project merger (states and transitions)', function () {
|
||||
it('can merge add state transitions to empty ancestor', function () {
|
||||
var a = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A'
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
var o = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
stateParameters: {
|
||||
hover: {
|
||||
p1: 'changed'
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
var t = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A'
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var res = ProjectMerger.mergeProject(a, o, t);
|
||||
expect(res.components[0].graph.roots[0]).toEqual({
|
||||
type: '0',
|
||||
id: 'A',
|
||||
stateParameters: {
|
||||
hover: {
|
||||
p1: 'changed'
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('can merge state parameters', function () {
|
||||
var a = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
parameters: {},
|
||||
stateParameters: {
|
||||
hover: {
|
||||
p1: 'some-string',
|
||||
p3: 'remove-me'
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
var o = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
stateParameters: {
|
||||
hover: {
|
||||
p1: 'changed',
|
||||
p2: 'added-string',
|
||||
p3: 'remove-me'
|
||||
},
|
||||
pressed: {
|
||||
p4: 'new-param'
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
var t = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
parameters: {},
|
||||
stateParameters: {
|
||||
hover: {
|
||||
p1: 10 // Should conflict
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var res = ProjectMerger.mergeProject(a, o, t);
|
||||
expect(res.components[0].graph.roots[0]).toEqual({
|
||||
type: '0',
|
||||
id: 'A',
|
||||
parameters: undefined,
|
||||
stateParameters: {
|
||||
hover: {
|
||||
p1: 'changed',
|
||||
p2: 'added-string',
|
||||
p3: undefined
|
||||
},
|
||||
pressed: {
|
||||
p4: 'new-param'
|
||||
}
|
||||
},
|
||||
ports: [],
|
||||
conflicts: [
|
||||
{
|
||||
type: 'stateParameter',
|
||||
state: 'hover',
|
||||
name: 'p1',
|
||||
ours: 'changed',
|
||||
theirs: 10
|
||||
}
|
||||
],
|
||||
children: undefined
|
||||
});
|
||||
});
|
||||
|
||||
it('can merge add state transitions to empty ancestor', function () {
|
||||
var a = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
parameters: {}
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
var o = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
stateTransitions: {
|
||||
hover: {
|
||||
p1: {
|
||||
dur: 0,
|
||||
curve: 'changed'
|
||||
},
|
||||
p2: {
|
||||
dur: 0,
|
||||
curve: 'added'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
var t = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
parameters: {}
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var res = ProjectMerger.mergeProject(a, o, t);
|
||||
expect(res.components[0].graph.roots[0]).toEqual({
|
||||
type: '0',
|
||||
id: 'A',
|
||||
stateTransitions: {
|
||||
hover: {
|
||||
p1: {
|
||||
dur: 0,
|
||||
curve: 'changed'
|
||||
},
|
||||
p2: {
|
||||
dur: 0,
|
||||
curve: 'added'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('can merge state transitions', function () {
|
||||
var a = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
parameters: {},
|
||||
stateTransitions: {
|
||||
hover: {
|
||||
p1: {
|
||||
dur: 0,
|
||||
curve: [1, 1, 1, 1]
|
||||
},
|
||||
p3: 'remove-me'
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
var o = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
stateTransitions: {
|
||||
hover: {
|
||||
p1: {
|
||||
dur: 0,
|
||||
curve: 'changed'
|
||||
},
|
||||
p2: {
|
||||
dur: 0,
|
||||
curve: 'added'
|
||||
},
|
||||
p3: 'remove-me'
|
||||
},
|
||||
pressed: {
|
||||
p4: {
|
||||
dur: 0,
|
||||
curve: [0, 1, 0, 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
var t = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
parameters: {},
|
||||
stateTransitions: {
|
||||
hover: {
|
||||
p1: {
|
||||
dur: 0,
|
||||
curve: [0, 0, 0, 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var res = ProjectMerger.mergeProject(a, o, t);
|
||||
expect(res.components[0].graph.roots[0]).toEqual({
|
||||
type: '0',
|
||||
id: 'A',
|
||||
parameters: undefined,
|
||||
stateTransitions: {
|
||||
hover: {
|
||||
p1: {
|
||||
dur: 0,
|
||||
curve: 'changed'
|
||||
},
|
||||
p2: {
|
||||
dur: 0,
|
||||
curve: 'added'
|
||||
},
|
||||
p3: undefined
|
||||
},
|
||||
pressed: {
|
||||
p4: {
|
||||
dur: 0,
|
||||
curve: [0, 1, 0, 1]
|
||||
}
|
||||
}
|
||||
},
|
||||
ports: [],
|
||||
conflicts: [
|
||||
{
|
||||
type: 'stateTransition',
|
||||
state: 'hover',
|
||||
name: 'p1',
|
||||
ours: {
|
||||
dur: 0,
|
||||
curve: 'changed'
|
||||
},
|
||||
theirs: {
|
||||
dur: 0,
|
||||
curve: [0, 0, 0, 1]
|
||||
}
|
||||
}
|
||||
],
|
||||
children: undefined
|
||||
});
|
||||
});
|
||||
|
||||
it('can merge default state transitions', function () {
|
||||
var a = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
parameters: {}
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
var o = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
defaultStateTransitions: {
|
||||
neutral: {
|
||||
dur: 100,
|
||||
curve: [0, 0, 1, 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
var t = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
parameters: {},
|
||||
defaultStateTransitions: {
|
||||
neutral: {
|
||||
dur: 200,
|
||||
curve: [1, 1, 1, 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var res = ProjectMerger.mergeProject(a, o, t);
|
||||
expect(res.components[0].graph.roots[0]).toEqual({
|
||||
type: '0',
|
||||
id: 'A',
|
||||
parameters: undefined,
|
||||
defaultStateTransitions: {
|
||||
neutral: {
|
||||
dur: 100,
|
||||
curve: [0, 0, 1, 1]
|
||||
}
|
||||
},
|
||||
ports: [],
|
||||
conflicts: [
|
||||
{
|
||||
type: 'defaultStateTransition',
|
||||
state: 'neutral',
|
||||
ours: {
|
||||
dur: 100,
|
||||
curve: [0, 0, 1, 1]
|
||||
},
|
||||
theirs: {
|
||||
dur: 200,
|
||||
curve: [1, 1, 1, 1]
|
||||
}
|
||||
}
|
||||
],
|
||||
children: undefined
|
||||
});
|
||||
});
|
||||
|
||||
it('can merge variant', function () {
|
||||
var a = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
parameters: {}
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
var o = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
variant: 'VariantA'
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
var t = {
|
||||
components: [
|
||||
{
|
||||
name: 'comp1',
|
||||
graph: {
|
||||
roots: [
|
||||
{
|
||||
type: '0',
|
||||
id: 'A',
|
||||
parameters: {},
|
||||
variant: 'VariantB'
|
||||
}
|
||||
],
|
||||
connections: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var res = ProjectMerger.mergeProject(a, o, t);
|
||||
expect(res.components[0].graph.roots[0]).toEqual({
|
||||
type: '0',
|
||||
id: 'A',
|
||||
parameters: undefined,
|
||||
variant: 'VariantA',
|
||||
ports: [],
|
||||
conflicts: [
|
||||
{
|
||||
type: 'variant',
|
||||
ours: 'VariantA',
|
||||
theirs: 'VariantB'
|
||||
}
|
||||
],
|
||||
children: undefined
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,153 @@
|
||||
var ProjectMerger = require('@noodl-utils/projectmerger');
|
||||
var NodeLibrary = require('@noodl-models/nodelibrary').NodeLibrary;
|
||||
var fs = require('fs');
|
||||
var Process = require('process');
|
||||
|
||||
// Project settings
|
||||
describe('Project merger (variants)', function () {
|
||||
it('can merge variants (conflicts)', function () {
|
||||
var a = {
|
||||
components: [],
|
||||
variants: [
|
||||
{
|
||||
typename: 'Group',
|
||||
name: 'A',
|
||||
parameters: {
|
||||
test: 'hej'
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
var o = {
|
||||
components: [],
|
||||
variants: [
|
||||
{
|
||||
typename: 'Group',
|
||||
name: 'A',
|
||||
parameters: {
|
||||
test: 'hej2'
|
||||
},
|
||||
stateParameters: {
|
||||
hover: {
|
||||
test: 'a'
|
||||
}
|
||||
},
|
||||
stateTransitions: {
|
||||
hover: {
|
||||
p1: {
|
||||
dur: 500,
|
||||
curve: [0, 0, 0, 1]
|
||||
}
|
||||
}
|
||||
},
|
||||
defaultStateTransitions: {
|
||||
hover: {
|
||||
dur: 500,
|
||||
curve: [0, 0, 0, 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
var t = {
|
||||
components: [],
|
||||
variants: [
|
||||
{
|
||||
typename: 'Group',
|
||||
name: 'A',
|
||||
parameters: {
|
||||
test: 'hej3'
|
||||
},
|
||||
stateParameters: {
|
||||
hover: {
|
||||
test: 'b'
|
||||
}
|
||||
},
|
||||
stateTransitions: {
|
||||
hover: {
|
||||
p1: {
|
||||
dur: 0,
|
||||
curve: [0, 0, 0, 1]
|
||||
}
|
||||
}
|
||||
},
|
||||
defaultStateTransitions: {
|
||||
hover: {
|
||||
dur: 0,
|
||||
curve: [0, 0, 0, 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var res = ProjectMerger.mergeProject(a, o, t);
|
||||
console.log(res);
|
||||
expect(res.variants[0]).toEqual({
|
||||
typename: 'Group',
|
||||
name: 'A',
|
||||
parameters: {
|
||||
test: 'hej2'
|
||||
},
|
||||
stateParameters: {
|
||||
hover: {
|
||||
test: 'a'
|
||||
}
|
||||
},
|
||||
stateTransitions: {
|
||||
hover: {
|
||||
p1: {
|
||||
dur: 500,
|
||||
curve: [0, 0, 0, 1]
|
||||
}
|
||||
}
|
||||
},
|
||||
defaultStateTransitions: {
|
||||
hover: {
|
||||
dur: 500,
|
||||
curve: [0, 0, 0, 1]
|
||||
}
|
||||
},
|
||||
conflicts: [
|
||||
{
|
||||
type: 'parameter',
|
||||
name: 'test',
|
||||
ours: 'hej2',
|
||||
theirs: 'hej3'
|
||||
},
|
||||
{
|
||||
type: 'stateParameter',
|
||||
state: 'hover',
|
||||
name: 'test',
|
||||
ours: 'a',
|
||||
theirs: 'b'
|
||||
},
|
||||
{
|
||||
type: 'stateTransition',
|
||||
state: 'hover',
|
||||
name: 'p1',
|
||||
ours: {
|
||||
dur: 500,
|
||||
curve: [0, 0, 0, 1]
|
||||
},
|
||||
theirs: {
|
||||
dur: 0,
|
||||
curve: [0, 0, 0, 1]
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'defaultStateTransition',
|
||||
state: 'hover',
|
||||
ours: {
|
||||
dur: 500,
|
||||
curve: [0, 0, 0, 1]
|
||||
},
|
||||
theirs: {
|
||||
dur: 0,
|
||||
curve: [0, 0, 0, 1]
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
});
|
||||
1500
packages/noodl-editor/tests/projectmerger/projectmerger.js
Normal file
1500
packages/noodl-editor/tests/projectmerger/projectmerger.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user