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

Test Storybook support #277

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
14 changes: 14 additions & 0 deletions client/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
stories: [
{
directory: '../src/stories',
titlePrefix: 'Routed',
},
],
staticDirs: ['../public', '../build'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/addon-interactions', '@storybook/preset-create-react-app'],
framework: '@storybook/react',
core: {
builder: '@storybook/builder-webpack5',
},
};
2 changes: 2 additions & 0 deletions client/.storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<link rel="stylesheet" type="text/css" href="/libraries/fontawesome-free/css/all.css" />
<link rel="stylesheet" type="text/css" href="/libraries/uswds/theme/styles.css" />
9 changes: 9 additions & 0 deletions client/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
};
16 changes: 15 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"sass": "sass --load-path=../node_modules/uswds/dist/scss --style=compressed src/theme/styles.scss build/libraries/uswds/theme/styles_pre.css",
"postcss": "postcss --verbose build/libraries/uswds/theme/styles_pre.css --use autoprefixer -o build/libraries/uswds/theme/styles.css",
"test": "craco test",
"eject": "craco eject"
"eject": "craco eject",
"storybook": "NODE_OPTIONS=--openssl-legacy-provider start-storybook -p 6006",
"build-storybook": "NODE_OPTIONS=--openssl-legacy-provider build-storybook"
},
"browserslist": {
"production": [
Expand All @@ -47,6 +49,18 @@
"last 1 safari version"
]
},
"devDependencies": {
"@storybook/addon-actions": "^6.5.15",
"@storybook/addon-essentials": "^6.5.15",
"@storybook/addon-interactions": "^6.5.15",
"@storybook/addon-links": "^6.5.15",
"@storybook/builder-webpack5": "^6.5.15",
"@storybook/manager-webpack5": "^6.5.15",
"@storybook/node-logger": "^6.5.15",
"@storybook/preset-create-react-app": "^4.1.2",
"@storybook/react": "^6.5.15",
"@storybook/testing-library": "^0.0.13"
},
"eslintConfig": {
"extends": [
"react-app",
Expand Down
25 changes: 25 additions & 0 deletions client/src/stories/Alert.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import Alert from '../Components/Alert';

const metadata = {
component: Alert,
argTypes: {},
};

export default metadata;

function story(args = {}, Component = metadata.component) {
const func = (args) => <Component {...args} />;

func.args = args;

return func;
}

export const Warning = story({
type: 'warning',
title: 'Clear form?',
message: 'All of the fields will be reset.',
destructive: 'Clear form',
cancel: 'Keep editing',
});
28 changes: 28 additions & 0 deletions client/src/stories/RingdownBadge.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import RingdownBadge from '../Components/RingdownBadge';
import DeliveryStatus from '../../../shared/constants/DeliveryStatus';

const metadata = {
component: RingdownBadge,
argTypes: {
status: {
options: DeliveryStatus.ALL_STATUSES,
control: 'select',
},
},
};

export default metadata;

function story(args = {}, Component = metadata.component) {
const func = (args) => <Component {...args} />;

func.args = args;

return func;
}

export const Sent = story({ status: DeliveryStatus.RINGDOWN_SENT });
export const Confirmed = story({ status: DeliveryStatus.RINGDOWN_CONFIRMED });
export const Arrived = story({ status: DeliveryStatus.ARRIVED });
export const Offloaded = story({ status: DeliveryStatus.OFFLOADED });
50 changes: 50 additions & 0 deletions client/src/stories/TabBar.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, { useState } from 'react';
import TabBar from '../Components/TabBar';

const metadata = {
component: TabBar,
decorators: [
(Story) => (
<div style={{ width: '50%' }}>
<Story />
</div>
),
],
};

export default metadata;

function story(args = {}, Component = metadata.component) {
const func = (args) => {
// since func() isn't a component, we can't call a hook from inside it. so create a functional component to
// contain the state hook and render the TabBar
function Header() {
const [selectedTab, setSelectedTab] = useState(args.selectedTab);

return (
<Component
{...args}
selectedTab={selectedTab}
onSelect={(tab) => {
setSelectedTab(tab);
args.onSelect(tab);
}}
/>
);
}

return <Header />;
};

func.args = args;

return func;
}

export const EMS = story({
tabs: [
{ label: 'Ringdown', id: 'ringdown' },
{ label: 'Hospital Info', id: 'hospitalInfo' },
],
selectedTab: 'ringdown',
});
1 change: 0 additions & 1 deletion client/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/prefer-default-export
export function isValueEmpty(value) {
const valueType = typeof value;
// count 0 and false as non-empty values
Expand Down
Loading