Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

chore: re-enable storybook, add support for mocking #1579

Merged
merged 3 commits into from
Mar 28, 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
29 changes: 0 additions & 29 deletions .storybook/main.js

This file was deleted.

73 changes: 73 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const { merge } = require('webpack-merge');
const prod = require('../webpack.prod.js');
const path = require('path');

module.exports = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
staticDirs: ['../public'],
addons: ['@storybook/addon-essentials'],
babel: async (options) => {
// Update your babel configuration here
return options;
},
typescript: {
check: false,
checkOptions: {},
reactDocgen: 'react-docgen-typescript',
reactDocgenTypescriptOptions: {
shouldExtractLiteralValuesFromEnum: true,
propFilter: (prop) => (prop.parent ? !/node_modules/.test(prop.parent.fileName) : true),
},
},
core: {
builder: 'webpack5',
},
framework: '@storybook/react',
webpackFinal: async (config, { configType }) => {
// Make whatever fine-grained changes you need
// Return the altered config

const updatedConfig = merge(config, {
resolve: {
alias: {
'@kaoto/api': path.resolve(__dirname, '../src/api/'),
'@kaoto/assets': path.resolve(__dirname, '../src/assets/'),
'@kaoto/components': path.resolve(__dirname, '../src/components/'),
'@kaoto/constants': path.resolve(__dirname, '../src/store/constants/'),
'@kaoto/hooks': path.resolve(__dirname, '../src/hooks/'),
'@kaoto/layout': path.resolve(__dirname, '../src/layout/'),
'@kaoto/types': path.resolve(__dirname, '../src/types/'),
'@kaoto/routes': path.resolve(__dirname, '../src/routes/'),
'@kaoto/services': path.resolve(__dirname, '../src/services/'),
'@kaoto/store': path.resolve(__dirname, '../src/store/'),
'@kaoto/utils': path.resolve(__dirname, '../src/utils/'),
}
}
});

/**
* The first rule from the array it's the typescript one,
* it would be better to have a more deterministic way to ensure it*/
const [existingTypescriptConfig, ...rest] = updatedConfig.module.rules;

updatedConfig.module.rules = [
{
test: /\.(tsx|ts|jsx)?$/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
},
],
},
...rest,
];

console.log(JSON.stringify(updatedConfig.module.rules, null, 4));

return updatedConfig;
},
};
8 changes: 7 additions & 1 deletion .storybook/preview.js → .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import '@patternfly/patternfly/utilities/Flex/flex.css';
import '@patternfly/patternfly/utilities/Sizing/sizing.css';
import '@patternfly/patternfly/utilities/Spacing/spacing.css';
import 'reactflow/dist/style.css';
import { AlertProvider } from "../src/layout";
import { AlertProvider } from '../src/layout';
import { worker } from '../src/__mocks__/browser';

if (process.env.NODE_ENV === 'development') {
const { worker } = require('../src/__mocks__/browser');
worker.start();
}

export const decorators = [
(Story) => (
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"jest-environment-jsdom": "^29.3.1",
"lint-staged": "12.4.3",
"mini-css-extract-plugin": "2.7.5",
"msw": "^1.1.0",
"null-loader": "^4.0.1",
"prettier": "2.8.7",
"prop-types": "15.8.1",
Expand Down Expand Up @@ -193,5 +194,8 @@
"dist",
"src",
"tsconfig.json"
]
],
"msw": {
"workerDirectory": "dist"
}
}
6 changes: 3 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import './App.css';
import { useIntegrationJsonStore } from './store';
import { bindUndoRedo } from './utils';
import { AlertProvider, AppLayout, MASLoading } from '@kaoto/layout';
import { AppRoutes } from '@kaoto/routes';
import '@patternfly/patternfly/patternfly-theme-dark.css';
Expand All @@ -12,9 +15,6 @@ import '@patternfly/patternfly/utilities/Text/text.css';
import { Suspense } from 'react';
import { BrowserRouter as Router } from 'react-router-dom';
import 'reactflow/dist/style.css';
import './App.css';
import { useIntegrationJsonStore } from './store';
import { bindUndoRedo } from './utils';

const { undo, redo } = useIntegrationJsonStore.temporal.getState();

Expand Down
5 changes: 5 additions & 0 deletions src/__mocks__/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { handlers } from './handlers';
import { setupWorker } from 'msw';

// This configures a Service Worker with the given request handlers.
export const worker = setupWorker(...handlers);
18 changes: 18 additions & 0 deletions src/__mocks__/handlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @ts-ignore
import capabilitiesGet from './http/capabilities.get.json';
import { rest } from 'msw';

export const handlers = [
rest.get('http://localhost:8081/v1/capabilities', (_req, res, ctx) => {
return res(ctx.status(200), ctx.json(capabilitiesGet));
}),

rest.get('http://localhost:8081/v1/capabilities/namespace', (_req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
namespace: 'default',
})
);
}),
];
41 changes: 41 additions & 0 deletions src/__mocks__/http/capabilities.get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"dsls": [
{
"output": "true",
"input": "true",
"validationSchema": "/v1/capabilities/Integration/schema",
"deployable": "true",
"name": "Integration",
"description": "An Integration defines a workflow of actions and steps.",
"step-kinds": "[CAMEL-CONNECTOR, EIP, EIP-BRANCH]"
},
{
"output": "true",
"input": "true",
"validationSchema": "/v1/capabilities/Camel Route/schema",
"deployable": "false",
"name": "Camel Route",
"description": "A camel route is a non deployable in cluster workflow of actions and steps.",
"step-kinds": "[CAMEL-CONNECTOR, EIP, EIP-BRANCH]"
},
{
"output": "true",
"input": "true",
"validationSchema": "/v1/capabilities/Kamelet/schema",
"deployable": "true",
"name": "Kamelet",
"description": "A Kamelet is a snippet of a route. It defines meta building blocks or steps that can be reused on integrations.",
"step-kinds": "[CAMEL-CONNECTOR, EIP, EIP-BRANCH]"
},
{
"output": "true",
"input": "true",
"default": "true",
"validationSchema": "/v1/capabilities/KameletBinding/schema",
"deployable": "true",
"name": "KameletBinding",
"description": "Kamelet Bindings are used to create simple integrations that link a start step to an end step with optional intermediate action steps.",
"step-kinds": "[KAMELET, KNATIVE]"
}
]
}
18 changes: 18 additions & 0 deletions src/components/Catalog.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import { Catalog } from './Catalog';
import KaotoDrawer from './KaotoDrawer';
import { DrawerContentBody } from '@patternfly/react-core';
import { ComponentStory, ComponentMeta } from '@storybook/react';

export default {
title: 'Catalog/Catalog',
component: Catalog,
argTypes: { handleClose: { action: 'clicked' } },
decorators: [
(Story) => (
<div style={{ height: 'calc(100vh - 29px)' }}>
<KaotoDrawer
isExpanded={true}
panelContent={
<DrawerContentBody style={{ padding: '10px' }}>
<Story />
</DrawerContentBody>
}
children={<></>}
position={'left'}
/>
</div>
),
],
} as ComponentMeta<typeof Catalog>;

const Template: ComponentStory<typeof Catalog> = (args) => {
Expand Down
Loading