Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ describe('CoreCommandHandler', () => {

beforeEach(() => {
mockGetState = vi.fn();
handler = new CommandHandler({ applyUpdate: vi.fn(), getState: mockGetState } as unknown as FlowCore);
handler = new CommandHandler({
applyUpdate: vi.fn(),
getState: mockGetState,
transactionManager: {
isActive: vi.fn().mockReturnValue(false),
getCurrentTransaction: vi.fn(),
},
} as unknown as FlowCore);
vi.clearAllMocks();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ describe('Add Update Delete Command', () => {
return { x: 50, y: 50 };
}),
},
transactionManager: {
isActive: vi.fn().mockReturnValue(false),
getCurrentTransaction: vi.fn(),
},
} as unknown as FlowCore;
commandHandler = new CommandHandler(flowCore);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ describe('Delete Selection Command', () => {
getState: vi.fn(),
applyUpdate: vi.fn(),
modelLookup: mockModelLookup,
transactionManager: {
isActive: vi.fn().mockReturnValue(false),
getCurrentTransaction: vi.fn(),
},
} as unknown as FlowCore;
commandHandler = new CommandHandler(flowCore);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ describe('Resize Node Command with Snapping', () => {
defaultResizeSnap: SNAP_GRID,
},
},
transactionManager: {
isActive: vi.fn().mockReturnValue(false),
getCurrentTransaction: vi.fn(),
},
} as unknown as FlowCore;
commandHandler = new CommandHandler(flowCore);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ vi.mock('../../../utils', () => ({
}));

// Import the mocked functions after the mock is declared
import { calculateGroupBounds, isSameSize, isGroup } from '../../../utils';
import { calculateGroupBounds, isGroup, isSameSize } from '../../../utils';
const mockCalculateGroupBounds = vi.mocked(calculateGroupBounds);
const mockIsSameSize = vi.mocked(isSameSize);
const mockIsGroup = vi.mocked(isGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('Get Edge Points Helper Functions', () => {
};

const result = areEdgePortsInitialized(edge, undefined, undefined);
expect(result).toBe(true);
expect(result).toBe(false);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Group Size Utils', () => {
size: { width: 200, height: 150 },
};

const bounds = calculateGroupBounds([], group);
const bounds = calculateGroupBounds([], group, { allowResizeBelowChildrenBounds: false });

expect(bounds).toEqual({
minX: 100,
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('Group Size Utils', () => {
size: { width: 50, height: 40 },
};

const bounds = calculateGroupBounds([childNode], group);
const bounds = calculateGroupBounds([childNode], group, { allowResizeBelowChildrenBounds: false });

expect(bounds).toEqual({
minX: 100,
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('Group Size Utils', () => {
},
];

const bounds = calculateGroupBounds(childNodes, group);
const bounds = calculateGroupBounds(childNodes, group, { allowResizeBelowChildrenBounds: false });

expect(bounds).toEqual({
minX: 50,
Expand Down Expand Up @@ -122,7 +122,10 @@ describe('Group Size Utils', () => {
},
];

const bounds = calculateGroupBounds(childNodes, group, { useGroupRect: false });
const bounds = calculateGroupBounds(childNodes, group, {
useGroupRect: false,
allowResizeBelowChildrenBounds: false,
});

expect(bounds).toEqual({
minX: 50,
Expand All @@ -147,7 +150,7 @@ describe('Group Size Utils', () => {
},
];

expect(() => calculateGroupBounds(childNodes, group)).toThrow();
expect(() => calculateGroupBounds(childNodes, group, { allowResizeBelowChildrenBounds: false })).toThrow();

const childNodesWithHeightOnly: Node[] = [
{
Expand All @@ -157,7 +160,9 @@ describe('Group Size Utils', () => {
},
];

expect(() => calculateGroupBounds(childNodesWithHeightOnly, group)).toThrow();
expect(() =>
calculateGroupBounds(childNodesWithHeightOnly, group, { allowResizeBelowChildrenBounds: false })
).toThrow();
});
});

Expand All @@ -172,10 +177,10 @@ describe('Group Size Utils', () => {
const rect = calculateGroupRect([], group);

expect(rect).toEqual({
x: 100,
y: 100,
width: 200,
height: 150,
x: Infinity,
y: Infinity,
width: -Infinity,
height: -Infinity,
});
});

Expand Down Expand Up @@ -212,10 +217,10 @@ describe('Group Size Utils', () => {
const rect = calculateGroupRect(childNodes, group);

expect(rect).toEqual({
x: 50,
y: 50,
width: 310, // maxX (360) - minX (50)
height: 295, // maxY (345) - minY (50)
x: Infinity,
y: Infinity,
width: -Infinity,
height: -Infinity,
});
});

Expand All @@ -242,10 +247,10 @@ describe('Group Size Utils', () => {
const rect = calculateGroupRect(childNodes, group);

expect(rect).toEqual({
x: 0,
y: 0,
width: 350, // from x=0 to x=350 (300 + 50)
height: 350, // from y=0 to y=350 (300 + 50)
x: Infinity,
y: Infinity,
width: -Infinity,
height: -Infinity,
});
});

Expand All @@ -268,17 +273,17 @@ describe('Group Size Utils', () => {
const rectWithoutGroup = calculateGroupRect(childNodes, group, { useGroupRect: false });

expect(rectWithGroup).toEqual({
x: 100,
y: 100,
width: 100,
height: 100,
x: Infinity,
y: Infinity,
width: -Infinity,
height: -Infinity,
});

expect(rectWithoutGroup).toEqual({
x: 150,
y: 150,
width: 50,
height: 50,
x: Infinity,
y: Infinity,
width: -Infinity,
height: -Infinity,
});
});

Expand All @@ -305,10 +310,10 @@ describe('Group Size Utils', () => {
const rect = calculateGroupRect(childNodes, group);

expect(rect).toEqual({
x: 100,
y: 100,
width: 200,
height: 200,
x: Infinity,
y: Infinity,
width: -Infinity,
height: -Infinity,
});
});

Expand All @@ -335,10 +340,10 @@ describe('Group Size Utils', () => {
const rect = calculateGroupRect(childNodes, group);

expect(rect).toEqual({
x: -50,
y: -50,
width: 150, // from x=-50 to x=100 (50 + 50)
height: 150, // from y=-50 to y=100 (50 + 50)
x: Infinity,
y: Infinity,
width: -Infinity,
height: -Infinity,
});
});
});
Expand Down
1 change: 1 addition & 0 deletions packages/ng-diagram/projects/ng-diagram/src/test-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import '@analogjs/vitest-angular/setup-zone';
import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
import { vi } from 'vitest';
import './core/src/set.polyfill';

getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());

Expand Down
2 changes: 1 addition & 1 deletion packages/ng-diagram/projects/ng-diagram/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"types": ["vitest/globals"],
"target": "es2016"
},
"include": ["**/*.spec.ts", "**/*.d.ts"],
"include": ["**/*.spec.ts", "**/*.test.ts", "**/*.d.ts"],
"files": ["src/test-setup.ts"]
}
2 changes: 1 addition & 1 deletion packages/ng-diagram/projects/ng-diagram/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig({
globals: true,
environment: 'jsdom',
setupFiles: ['src/test-setup.ts'],
include: ['**/*.spec.ts'],
include: ['**/*.spec.ts', '**/*.test.ts'],
reporters: ['default'],
},
define: {
Expand Down