Skip to content

Commit

Permalink
prettier, more codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
loreanvictor committed Dec 10, 2023
1 parent c0690d5 commit 28d4c7a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
5 changes: 2 additions & 3 deletions src/main/services/patcher/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { Patch } from './patcher-types';
* in the form of a [JSON patch](http://jsonpatch.com/)
*/
export function compare<T>(a: T, b: T): Patch {
const patch = comparePatches(a as any, b as any)
.filter((op) => !op.path.startsWith('/size'));
const patch = comparePatches(a as any, b as any).filter((op) => !op.path.startsWith('/size'));

const relationshipIdsWithAffectedPaths: string[] = [];

Expand All @@ -21,7 +20,7 @@ export function compare<T>(a: T, b: T): Patch {
const cleanedPatch = patch.filter((op) => {
const match = /\/relationships\/(?<id>[\w-]+)\//g.exec(op.path);

return !(match?.groups?.id) || !relationshipIdsWithAffectedPaths.includes(match.groups.id);
return !match?.groups?.id || !relationshipIdsWithAffectedPaths.includes(match.groups.id);
});

relationshipIdsWithAffectedPaths.forEach((id) => {
Expand Down
15 changes: 4 additions & 11 deletions src/tests/unit/components/store/model-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ import { UMLRelationship } from '../../../../main/services/uml-relationship/uml-
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!));
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!));
const bounds = computeBoundingBoxForElements(Object.values(state.elements as any));

expect(bounds.x).toBe(0);
});
Expand All @@ -35,10 +34,7 @@ describe('model state.', () => {
});

const exp = ModelState.toModel(state as any);
const bounds = computeBoundingBoxForElements([
...Object.values(exp.elements!),
...Object.values(exp.relationships!),
]);
const bounds = computeBoundingBoxForElements([...Object.values(exp.elements), ...Object.values(exp.relationships)]);

expect(bounds.x).toBe(0);
expect(bounds.y).toBe(0);
Expand All @@ -59,10 +55,7 @@ describe('model state.', () => {
});

const exp = ModelState.toModel(state as any, false);
const bounds = computeBoundingBoxForElements([
...Object.values(exp.elements!),
...Object.values(exp.relationships!),
]);
const bounds = computeBoundingBoxForElements([...Object.values(exp.elements), ...Object.values(exp.relationships)]);

expect(bounds.x).not.toBe(0);
expect(bounds.y).not.toBe(0);
Expand Down
23 changes: 14 additions & 9 deletions src/tests/unit/services/patcher/compare.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
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 }],
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 }],
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);
Expand Down

0 comments on commit 28d4c7a

Please sign in to comment.