Files
noodl/packages/noodl-editor/tests/projectmerger/projectmerger-comments.js
Michael Cartner b9c60b07dc 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>
2024-01-26 11:52:55 +01:00

303 lines
5.2 KiB
JavaScript

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
}
]);
});
});