Skip to content

Commit

Permalink
chore: rename CanvasService to ControllerService
Browse files Browse the repository at this point in the history
  • Loading branch information
lordrip committed Aug 19, 2024
1 parent 1f00ce8 commit bf32635
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/ui/src/components/Visualization/Canvas/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { VisualizationEmptyState } from '../EmptyState';
import { CanvasSideBar } from './CanvasSideBar';
import { CanvasDefaults } from './canvas.defaults';
import { CanvasEdge, CanvasNode, LayoutType } from './canvas.models';
import { CanvasService } from './canvas.service';
import { ControllerService } from './controller.service';
import { FlowService } from './flow.service';

interface CanvasProps {
Expand All @@ -52,7 +52,7 @@ export const Canvas: FunctionComponent<PropsWithChildren<CanvasProps>> = ({ enti
/** Context to interact with the Canvas catalog */
const catalogModalContext = useContext(CatalogModalContext);

const controller = useMemo(() => CanvasService.createController(), []);
const controller = useMemo(() => ControllerService.createController(), []);
const { visibleFlows } = useContext(VisibleFlowsContext)!;
const shouldShowEmptyState = useMemo(() => {
const areNoFlows = entities.length === 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,49 @@ import {
import { CustomGroupWithSelection } from '../Custom';
import { CanvasDefaults } from './canvas.defaults';
import { LayoutType } from './canvas.models';
import { CanvasService } from './canvas.service';
import { ControllerService } from './controller.service';

describe('CanvasService', () => {
describe('ControllerService', () => {
it('should allow consumers to create a new controller and register its factories', () => {
const layoutFactorySpy = jest.spyOn(Visualization.prototype, 'registerLayoutFactory');
const componentFactorySpy = jest.spyOn(Visualization.prototype, 'registerComponentFactory');
const baselineElementFactorySpy = jest.spyOn(Visualization.prototype, 'registerElementFactory');

const controller = CanvasService.createController();
const controller = ControllerService.createController();

expect(controller).toBeInstanceOf(Visualization);
expect(layoutFactorySpy).toHaveBeenCalledWith(CanvasService.baselineLayoutFactory);
expect(componentFactorySpy).toHaveBeenCalledWith(CanvasService.baselineComponentFactory);
expect(baselineElementFactorySpy).toHaveBeenCalledWith(CanvasService.baselineElementFactory);
expect(layoutFactorySpy).toHaveBeenCalledWith(ControllerService.baselineLayoutFactory);
expect(componentFactorySpy).toHaveBeenCalledWith(ControllerService.baselineComponentFactory);
expect(baselineElementFactorySpy).toHaveBeenCalledWith(ControllerService.baselineElementFactory);
});

describe('baselineComponentFactory', () => {
it('should return the correct component for a group', () => {
const component = CanvasService.baselineComponentFactory({} as ModelKind, 'group');
const component = ControllerService.baselineComponentFactory({} as ModelKind, 'group');

expect(component).toBe(CustomGroupWithSelection);
});

it('should return the correct component for a graph', () => {
const component = CanvasService.baselineComponentFactory(ModelKind.graph, 'graph');
const component = ControllerService.baselineComponentFactory(ModelKind.graph, 'graph');

expect(component).toBeDefined();
});

it('should return the correct component for a node', () => {
const component = CanvasService.baselineComponentFactory(ModelKind.node, 'node');
const component = ControllerService.baselineComponentFactory(ModelKind.node, 'node');

expect(component).toBeDefined();
});

it('should return the correct component for an edge', () => {
const component = CanvasService.baselineComponentFactory(ModelKind.edge, 'edge');
const component = ControllerService.baselineComponentFactory(ModelKind.edge, 'edge');

expect(component).toBe(DefaultEdge);
});

it('should return undefined for an unknown type', () => {
const component = CanvasService.baselineComponentFactory({} as ModelKind, 'unknown');
const component = ControllerService.baselineComponentFactory({} as ModelKind, 'unknown');

expect(component).toBeUndefined();
});
Expand All @@ -72,7 +72,7 @@ describe('CanvasService', () => {
[LayoutType.Grid, GridLayout],
['unknown' as LayoutType, ColaLayout],
] as const)('baselineLayoutFactory [%s]', (type, layout) => {
const newController = CanvasService.createController();
const newController = ControllerService.createController();
newController.fromModel(
{
nodes: [],
Expand All @@ -85,7 +85,7 @@ describe('CanvasService', () => {
},
false,
);
const layoutFactory = CanvasService.baselineLayoutFactory(type, newController.getGraph());
const layoutFactory = ControllerService.baselineLayoutFactory(type, newController.getGraph());

expect(layoutFactory).toBeInstanceOf(layout);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { CustomGroupWithSelection, CustomNodeWithSelection, NoBendpointsEdge } from '../Custom';
import { LayoutType } from './canvas.models';

export class CanvasService {
export class ControllerService {
static createController(): Visualization {
const newController = new Visualization();

Expand Down

0 comments on commit bf32635

Please sign in to comment.