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

Added Story for AddressMotionToVacateView #14777

Merged
merged 5 commits into from
Jul 31, 2020
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
107 changes: 107 additions & 0 deletions client/app/queue/mtv/AddressMotionToVacateView.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import React from 'react';

import { v4 as uuidv4 } from 'uuid';
import { StaticRouter, Route } from 'react-router-dom';
import ReduxBase from '../../components/ReduxBase';
import queueReducer, { initialState } from '../reducers';

import TASK_ACTIONS from '../../../constants/TASK_ACTIONS';
import AddressMotionToVacateView from './AddressMotionToVacateView';

const appealId = uuidv4();
const taskId = '1';
const appeal = {
externalId: appealId,
issues: [
{ id: 1, program: 'compensation', description: 'issue description' },
{ id: 2, program: 'compensation', description: 'issue description 2' },
],
decisionIssues: [
{
id: 1,
disposition: 'allowed',
description: 'Decision issue 1',
benefit_type: 'compensation',
request_issue_ids: [1],
},
{
id: 2,
disposition: 'allowed',
description: 'Decision issue 2',
benefit_type: 'compensation',
request_issue_ids: [2],
},
],
veteranFullName: 'John Doe',
veteranFileNumber: '123456789',
veteranInfo: {
veteran: {
full_name: 'John Doe',
},
},
};

const storyState = {
appeals: {
[appealId]: appeal,
},
appealDetails: {
[appealId]: appeal,
},
amaTasks: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept this seed data to the bare minimum necessary to render the component in the story. This should properly contain the whole task tree.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be some seed data missing, I'm getting an error for the partial grant option (will upload a screenshot on the PR).

[taskId]: {
uniqueId: taskId,
externalAppealId: appealId,
label: 'Address Motion to Vacate',
type: 'JudgeAddressMotionToVacateTask',
instructions: ['I think you should grant vacatur'],
availableActions: [
{
label: 'Address Motion to Vacate',
value: 'address_motion_to_vacate',
data: {
options: [{ label: 'Jane Doe', value: 1 }],
},
},
],
},
},
};

const RouterDecorator = (storyFn) => (
<StaticRouter
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a chance that using MemoryRouter here might actually be better; StaticRouter works fine here since we have only one story and don't use react-router for anything other than grabbing the matched params.

location={{
pathname: `/queue/appeals/${appealId}/tasks/1/${
TASK_ACTIONS.ADDRESS_MOTION_TO_VACATE.value
}`,
}}
>
<Route
path={`/queue/appeals/:appealId/tasks/:taskId/${
TASK_ACTIONS.ADDRESS_MOTION_TO_VACATE.value
}`}
>
{storyFn()}
</Route>
</StaticRouter>
);

const ReduxDecorator = (storyFn) => (
<ReduxBase
reducer={queueReducer}
initialState={{ queue: { ...initialState, ...storyState } }}
>
{storyFn()}
</ReduxBase>
);

export default {
title:
'Queue/Motions to Vacate/Judge Address Motion to Vacate/AddressMotionToVacateView',
component: AddressMotionToVacateView,
decorators: [RouterDecorator, ReduxDecorator],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can specify as many decorators as you want. Each will simply wrap the next.

};

const Template = () => <AddressMotionToVacateView />;

export const Basic = Template.bind({});
Copy link
Contributor Author

@jcq jcq Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (setting up a template once and then basing all stories off of it) is the recommended syntax for stories in Storybook 6.x. While it isn't particularly useful in a case with only a single story, I used it here for example purposes.

4 changes: 2 additions & 2 deletions client/app/queue/mtv/MTVIssueSelection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import PropTypes from 'prop-types';
import CheckboxGroup from '../../components/CheckboxGroup';
import { JUDGE_ADDRESS_MTV_ISSUE_SELECTION_LABEL } from '../../../COPY';

const getDisplayOptions = (issues) => {
const getDisplayOptions = (issues = []) => {
// CheckboxGroup expects options with id (string) & label
return issues.map(({ id, description }, idx) => ({ id: id.toString(),
label: `${idx + 1}. ${description}` }));
};

export const MTVIssueSelection = ({ issues, onChange }) => {
export const MTVIssueSelection = ({ issues = [], onChange }) => {
const [selectedIssues, setSelectedIssues] = useState({});

useEffect(() => {
Expand Down