Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storybook - Add stories for Canvas component #396

Merged
merged 3 commits into from
Nov 22, 2023
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
100 changes: 100 additions & 0 deletions packages/ui-tests/cypress/fixtures/complexRouteMock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"route": {
"from": {
"uri": "webhook",
"parameters": {},
"steps": [
{
"to": {
"id": "to-2015",
"uri": "log",
"parameters": {}
}
},
{
"choice": {
"when": [
{
"when": {},
"steps": [
{
"to": {
"id": "to-1528",
"uri": "log",
"parameters": {}
}
}
]
},
{
"id": "when-1938",
"simple": "${header.foo} == 1",
"steps": [
{
"log": {
"id": "log-2139",
"message": "${body}"
}
}
]
}
],
"otherwise": {
"id": "otherwise-3846",
"steps": [
{
"log": {
"id": "log-1723",
"message": "${body}"
}
}
]
}
}
},
{
"to": {
"id": "to-2118",
"uri": "aws2-s3",
"parameters": {}
}
},
{
"doTry": {
"id": "doTry-1388",
"doCatch": [
{
"doCatch": {}
},
{
"id": "doCatch-2642",
"steps": []
}
],
"doFinally": {
"id": "doFinally-6670",
"steps": []
},
"steps": []
}
},
{
"to": {
"id": "to-2744",
"uri": "log",
"parameters": {}
}
},
{
"to": {
"id": "to-2300",
"uri": "kafka",
"parameters": {}
}
}
],
"id": "from-5869"
},
"id": "route-8888"
}
}
96 changes: 96 additions & 0 deletions packages/ui-tests/stories/Canvas.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import {
CamelRouteVisualEntity,
Canvas,
CatalogLoaderProvider,
CatalogSchemaLoader,
CatalogTilesProvider,
EntitiesProvider,
PipeVisualEntity,
SchemasLoaderProvider,
SourceCodeProvider,
VisibleFLowsContextResult,
VisibleFlowsContext,
pipeJson,
} from '@kaoto-next/ui/testing';
import { Meta, StoryFn } from '@storybook/react';
import complexRouteMock from '../cypress/fixtures/complexRouteMock.json';

const emptyPipeJson = {
apiVersion: 'camel.apache.org/v1',
kind: 'Pipe',
metadata: {
name: 'new-pipe-template',
},
spec: {
source: {},
sink: {},
},
};

const emptyCamelRouteJson = {
route: {
id: 'route-8888',
from: {
uri: '',
steps: [],
},
},
};

const camelRouteEntity = new CamelRouteVisualEntity(complexRouteMock.route);
const emptyCamelRouteEntity = new CamelRouteVisualEntity(emptyCamelRouteJson.route);
const pipeEntity = new PipeVisualEntity(pipeJson.spec!);
const emptyPipeEntity = new PipeVisualEntity(emptyPipeJson.spec!);

const ContextDecorator = (Story: StoryFn) => (
<SourceCodeProvider>
<EntitiesProvider>
<SchemasLoaderProvider catalogUrl={CatalogSchemaLoader.DEFAULT_CATALOG_PATH}>
<CatalogLoaderProvider catalogUrl={CatalogSchemaLoader.DEFAULT_CATALOG_PATH}>
<CatalogTilesProvider>
<Story />
</CatalogTilesProvider>
</CatalogLoaderProvider>
</SchemasLoaderProvider>
</EntitiesProvider>
</SourceCodeProvider>
);

export default {
title: 'Canvas/Canvas',
component: Canvas,
decorators: [ContextDecorator],
} as Meta<typeof Canvas>;

const Template: StoryFn<typeof Canvas> = (args) => {
const visibleId = args.entities[0].getId();
const firstVisibleEntity: unknown = { visibleFlows: { [visibleId]: true } };

return (
<div style={{ height: '600px', width: '100%' }}>
<VisibleFlowsContext.Provider value={firstVisibleEntity as VisibleFLowsContextResult}>
<Canvas {...args} />
</VisibleFlowsContext.Provider>
</div>
);
};

export const CamelRouteVisualization = Template.bind({});
CamelRouteVisualization.args = {
entities: [camelRouteEntity],
};

export const PipeVisualization = Template.bind({});
PipeVisualization.args = {
entities: [pipeEntity],
};

export const EmptyPipeVisualization = Template.bind({});
EmptyPipeVisualization.args = {
entities: [emptyPipeEntity],
};

export const EmptyCamelRouteVisualization = Template.bind({});
EmptyCamelRouteVisualization.args = {
entities: [emptyCamelRouteEntity],
};
1 change: 1 addition & 0 deletions packages/ui/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './local-storage-keys';
export * from './react-component';
export * from './schema';
export * from './validation';
export * from './visualization';
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { JSONSchemaType } from 'ajv';
import cloneDeep from 'lodash/cloneDeep';
import { pipeJson } from '../../../stubs/pipe';
import { EntityType } from '../../camel/entities';
import { PipeVisualEntity } from './pipe-visual-entity';
import { PipeVisualEntity } from './';
import { KameletSchemaService } from './support/kamelet-schema.service';

describe('Pipe', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/models/visualization/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './visualization-node';
export * from './flows';
3 changes: 3 additions & 0 deletions packages/ui/src/stubs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './camel-route';
export * from './kamelet-binding-route';
export * from './pipe';
1 change: 1 addition & 0 deletions packages/ui/src/testing-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './layout';
export * from './models/visualization';
export * from './providers';
export * from './utils';
export * from './stubs';

/** Re-export public components */
export * from './public-api';
Loading