Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Nov 4, 2024
1 parent d96095c commit b25f9be
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/wireframes/model/actions/appearance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ export function buildAppearance(builder: ActionReducerMapBuilder<EditorState>) {
const { key, value } = appearance;

return diagram.updateItems(itemIds, item => {
const rendererInstance = PluginRegistry.get(item.renderer);

if (!rendererInstance) {
const plugin = PluginRegistry.get(item.renderer)?.plugin;
if (!plugin) {
throw new Error(`Cannot find renderer for ${item.renderer}.`);
}

if (force || !Types.isUndefined(rendererInstance.defaultAppearance()[key])) {
if (force || !Types.isUndefined(plugin.defaultAppearance()[key])) {
return item.setAppearance(key, value);
}

Expand Down
8 changes: 4 additions & 4 deletions src/wireframes/model/actions/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ export function buildItems(builder: ActionReducerMapBuilder<EditorState>) {
const { diagramId, appearance, id, position, renderer, size } = action.payload;

return state.updateDiagram(diagramId, diagram => {
const rendererInstance = PluginRegistry.get(renderer);
const registration = PluginRegistry.get(renderer);

if (!rendererInstance) {
if (!registration) {
throw new Error(`Cannot find renderer for ${renderer}.`);
}

const { size: defaultSize, appearance: defaultAppearance, ...other } = rendererInstance.createDefaultShape();
const { size: defaultSize, appearance: defaults, ...other } = registration.createDefaultShape();

const initialSize = size || defaultSize;
const initialProps = {
Expand All @@ -141,7 +141,7 @@ export function buildItems(builder: ActionReducerMapBuilder<EditorState>) {
initialSize.x,
initialSize.y),
Rotation.ZERO),
appearance: { ...defaultAppearance || {}, ...appearance },
appearance: { ...defaults || {}, ...appearance },
};

const shape = DiagramItem.createShape(initialProps);
Expand Down
2 changes: 1 addition & 1 deletion src/wireframes/model/diagram-item-set.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('Diagram Item Set', () => {
const editable1 = set.editableIds;
const editable2 = set.editableIds;

expect(editable1).toEqual([root1.id, groupId, child1.id, child2.id]);
expect(editable1).toEqual(new Set([root1.id, groupId, child1.id, child2.id]));
expect(editable1).toBe(editable2);
});
});
6 changes: 4 additions & 2 deletions src/wireframes/model/registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import { PluginRegistry } from '@app/wireframes/model';

describe('PluginRegistry', () => {
it('should register renderer with identifier', () => {
const plugin: any = 42;
const plugin = {
identifier: () => 'MyPlugin',
} as any;

PluginRegistry.addPlugin(plugin);

expect(PluginRegistry.get('identifier')).toBe(plugin);
expect(PluginRegistry.get('MyPlugin')?.plugin).toBe(plugin);
});
});
8 changes: 4 additions & 4 deletions src/wireframes/renderer/ItemsLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ export const ItemsLayer = React.memo((props: ItemsLayerProps) => {
// Create missing shapes.
for (const shape of allShapes) {
if (!references[shape.id]) {
const rendererInstance = PluginRegistry.get(shape.renderer);

if (!rendererInstance) {
const plugin = PluginRegistry.get(shape.renderer)?.plugin;
if (!plugin) {
throw new Error(`Cannot find renderer for ${shape.renderer}.`);
}

references[shape.id] = diagramLayer.item(rendererInstance.plugin);
references[shape.id] = diagramLayer.item(plugin);
}
}

Expand Down

0 comments on commit b25f9be

Please sign in to comment.