-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to Realtime Collaboration (Patching) (#331)
- Loading branch information
1 parent
1c2aa37
commit 9abbc29
Showing
7 changed files
with
174 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { ModelState } from '../../../../main/components/store/model-state'; | ||
import { UMLRelationship } from '../../../../main/services/uml-relationship/uml-relationship'; | ||
import { computeBoundingBoxForElements } from '../../../../main/utils/geometry/boundary'; | ||
import diagram from '../../test-resources/class-diagram.json'; | ||
|
||
describe('model state.', () => { | ||
it('centers a model when imported.', () => { | ||
const state = ModelState.fromModel(diagram as any); | ||
const bounds = computeBoundingBoxForElements(Object.values(state.elements as any)); | ||
|
||
expect(Math.abs(bounds.x + bounds.width / 2)).toBeLessThan(40); | ||
expect(Math.abs(bounds.y + bounds.height / 2)).toBeLessThan(40); | ||
}); | ||
|
||
it('does not center the model when imported, given the option.', () => { | ||
const state = ModelState.fromModel(diagram as any, false); | ||
const bounds = computeBoundingBoxForElements(Object.values(state.elements as any)); | ||
|
||
expect(bounds.x).toBe(0); | ||
}); | ||
|
||
it('puts model on 0,0 when exporting.', () => { | ||
const state = ModelState.fromModel(diagram as any); | ||
expect(state.elements).toBeDefined(); | ||
state.elements && | ||
Object.values(state.elements).forEach((element) => { | ||
if (UMLRelationship.isUMLRelationship(element)) { | ||
element.path.forEach((point) => { | ||
point.x += 100; | ||
point.y += 100; | ||
}); | ||
} | ||
|
||
element.bounds.x += 100; | ||
element.bounds.y += 100; | ||
}); | ||
|
||
const exp = ModelState.toModel(state as any); | ||
const bounds = computeBoundingBoxForElements([...Object.values(exp.elements), ...Object.values(exp.relationships)]); | ||
|
||
expect(bounds.x).toBe(0); | ||
expect(bounds.y).toBe(0); | ||
}); | ||
|
||
it('deos not put model on 0,0 when exporting, given the option.', () => { | ||
const state = ModelState.fromModel(diagram as any); | ||
expect(state.elements).toBeDefined(); | ||
state.elements && | ||
Object.values(state.elements).forEach((element) => { | ||
if (UMLRelationship.isUMLRelationship(element)) { | ||
element.path.forEach((point) => { | ||
point.x += 100; | ||
point.y += 100; | ||
}); | ||
} | ||
|
||
element.bounds.x += 100; | ||
element.bounds.y += 100; | ||
}); | ||
|
||
const exp = ModelState.toModel(state as any, false); | ||
const bounds = computeBoundingBoxForElements([...Object.values(exp.elements), ...Object.values(exp.relationships)]); | ||
|
||
expect(bounds.x).not.toBe(0); | ||
expect(bounds.y).not.toBe(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { compare } from '../../../../main/services/patcher/compare'; | ||
|
||
describe('compare models to extract patches.', () => { | ||
it('groups up relationship paths.', () => { | ||
const a = { | ||
relationships: { | ||
x: { | ||
path: [ | ||
{ x: 0, y: 0 }, | ||
{ x: 1, y: 1 }, | ||
], | ||
isManuallyLayouted: false, | ||
bounds: { x: 0, y: 0, width: 1, height: 1 }, | ||
}, | ||
}, | ||
}; | ||
|
||
const b = { | ||
relationships: { | ||
x: { | ||
path: [ | ||
{ x: 1, y: 0 }, | ||
{ x: 0, y: 2 }, | ||
], | ||
isManuallyLayouted: true, | ||
bounds: { x: 0, y: 0, width: 1, height: 2 }, | ||
}, | ||
}, | ||
}; | ||
|
||
const patches = compare(a, b); | ||
|
||
expect(patches.length).toBe(3); | ||
expect(patches[0].path).toBe('/relationships/x/isManuallyLayouted'); | ||
expect(patches[1].path).toBe('/relationships/x/path'); | ||
expect(patches[2].path).toBe('/relationships/x/bounds'); | ||
}); | ||
}); |