Skip to content

Commit

Permalink
Merge branch 'master' into paula/caseflow-1126-judge-tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
pbradin authored Apr 16, 2021
2 parents 256a414 + d05e949 commit bf9d992
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 130 deletions.
2 changes: 1 addition & 1 deletion client/COPY.json
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@
"DOCKET_SWITCH_REVIEW_REQUEST_PRIOR_TO_RAMP_DATE_ERROR": "Receipt date cannot be before 11/01/17",
"DOCKET_SWITCH_REVIEW_REQUEST_FUTURE_DATE_ERROR": "Receipt date cannot be in the future",
"DOCKET_SWITCH_RULING_TITLE": "Switch Docket: Rule on %s's Request",
"DOCKET_SWITCH_RULING_INSTRUCTIONS": "**Provided below is a summary of the pertinent facts used by the Office of the Clerk of the Board to prepare a docket switch ruling. Determine how you would like to rule on this request to switch dockets and select the corresponding button below.**\n\nThe hyperlink takes you to a draft ruling letter based on the recommended ruling. Please feel free to make any necessary edits to the ruling letter. You may then sign the letter. Inserting a hyperlink to a signed ruling letter is recommended, but optional.\n\nIf you have any questions, or need assistance making edits to the ruling letter, please [email](mailto:[email protected]) the Office of the Clerk of the Board or use the text box below to provide any additional context or instructions.\n\nWhen you click \"Confirm,\" the task will automatically be returned to the individual who assigned it to you. If you would like to return the task to a different individual, please use the drop down box to select a different name.",
"DOCKET_SWITCH_RULING_INSTRUCTIONS": "**Provided below is a summary of the pertinent facts used by the Office of the Clerk of the Board to prepare a docket switch ruling. Determine how you would like to rule on this request to switch dockets and select the corresponding button below.**\n\nThe hyperlink takes you to a draft ruling letter based on the recommended ruling. Please feel free to make any necessary edits to the ruling letter. You may then sign the letter.\n\nIf you have any questions, or need assistance making edits to the ruling letter, please [email](mailto:[email protected]) the Office of the Clerk of the Board or use the text box below to provide any additional context or instructions.\n\nWhen you click \"Confirm,\" the task will automatically be returned to the individual who assigned it to you. If you would like to return the task to a different individual, please use the drop down box to select a different name.",
"DOCKET_SWITCH_RULING_SUCCESS_TITLE": "You have %s %s's request to switch dockets",
"DOCKET_SWITCH_RULING_SUCCESS_MESSAGE": "This will be sent to the assigned member of the Office of the Clerk of the Board.",
"DOCKET_SWITCH_DENIAL_TITLE": "Switch Docket: Deny %s's Request",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export const formatDocketSwitchRuling = ({
const parts = [];

parts.push(`I am proceeding with a ${DISPOSITIONS[disposition].judgeRulingText}.`);
parts.push(`Signed ruling letter: \n${hyperlink}`);
if (hyperlink) {
parts.push(`**Signed ruling letter:** [View link](${hyperlink})`);
}
parts.push(context);

return parts.join(' \n \n');
Expand All @@ -39,9 +41,14 @@ export const DocketSwitchRulingContainer = () => {
const match = useRouteMatch();
const { selected, options } = taskActionData({ task, match });

// Use regex to pull draft letter hyperlink out from the current task's instructions, if possible.
// It will be reused in the subsequent task's instructions.
const draftInstructions = task.instructions.join('\n');
const hyperlink = (/\*\*Draft letter:\*\* \[[^\]]+\]\(([^)]+)\)/).exec(draftInstructions)?.[1];

// eslint-disable-next-line no-console
const handleSubmit = async (formData) => {
const instructions = formatDocketSwitchRuling({ ...formData });
const instructions = formatDocketSwitchRuling({ hyperlink, ...formData });
const { disposition } = formData;
const dispositionType = DISPOSITIONS[disposition].dispositionType;
const taskType = `DocketSwitch${dispositionType}Task`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import AppSegment from '@department-of-veterans-affairs/caseflow-frontend-toolki
import Button from 'app/components/Button';
import { sprintf } from 'sprintf-js';
import DISPOSITIONS from 'constants/DOCKET_SWITCH_DISPOSITIONS';
import TextField from 'app/components/TextField';
import TextareaField from 'app/components/TextareaField';
import RadioField from 'app/components/RadioField';
import SearchableDropdown from 'app/components/SearchableDropdown';
Expand All @@ -26,7 +25,6 @@ const schema = yup.object().shape({
mixed().
oneOf(Object.keys(DISPOSITIONS)).
required(),
hyperlink: yup.string(),
context: yup.string().required(),
attorney: yup.
object().
Expand Down Expand Up @@ -89,14 +87,6 @@ export const DocketSwitchRulingForm = ({
vertical
/>

<TextField
inputRef={register}
name="hyperlink"
label="Insert hyperlink to signed ruling letter"
strongLabel
optional
/>

<TextareaField
inputRef={register}
name="context"
Expand Down
131 changes: 131 additions & 0 deletions client/test/app/components/Modal.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { axe } from 'jest-axe';

import Modal from 'app/components/Modal';
import Button from 'app/components/Button';

describe('Modal', () => {
const title = 'Test Modal Title';
const modalBodyContent = 'This is text content';
const closeHandler = jest.fn();
const cancelMock = jest.fn();
const confirmMock = jest.fn();

const defaultProps = {
title,
closeHandler,
cancelButton: <Button onClick={cancelMock}> Cancel </Button>,
confirmButton: <Button onClick={confirmMock}> Confirm </Button>,
};

const setupComponent = (props) => {
return render(<Modal {...defaultProps} {...props}>
<p>{modalBodyContent}</p>
</Modal>);
};

it('renders correctly', () => {
const { container } = setupComponent();

expect(container).toMatchSnapshot();
});

it('passes a11y testing', async () => {
const { container } = setupComponent();

const results = await axe(container);

expect(results).toHaveNoViolations();
});

it('renders title', () => {
setupComponent();

expect(screen.getByText(defaultProps.title)).toBeInTheDocument();
});

it('renders body content', () => {
setupComponent();

expect(screen.getByText(modalBodyContent)).toBeInTheDocument();
});

it('renders divider if noDivider set to false', () => {
const { container } = setupComponent();

// Not recommended way of testing but element does not have text, role, or id
expect(container.querySelector('.cf-modal-divider')).toBeTruthy();
});

it('does not render divider if noDivider set to true', () => {
const { container } = setupComponent({ noDivider: true });

// Not recommended way of testing but element does not have text, role, or id
expect(container.querySelector('.cf-modal-divider')).toBeFalsy();
});

describe('buttons', () => {
it('renders close button', async() => {
const { container } = setupComponent();
const closeButton = container.firstChild.firstChild.firstChild;

await userEvent.click(closeButton);

expect(closeButton).toBeInTheDocument();
expect(defaultProps.closeHandler).toHaveBeenCalledTimes(1);
});

it('renders cancel and confirm buttons', async() => {
setupComponent();
const cancelButton = screen.getByText('Cancel');
const confirmButton = screen.getByText('Confirm');

expect(cancelButton).toBeInTheDocument();
expect(confirmButton).toBeInTheDocument();

confirmMock.mockClear();
await userEvent.click(cancelButton);
expect(cancelMock).toHaveBeenCalledTimes(1);

await userEvent.click(confirmButton);
expect(confirmMock).toHaveBeenCalledTimes(1);
});

it('renders array of buttons', async() => {
const props = {
title,
closeHandler,
buttons: [
{
classNames: ['cf-modal-link', 'cf-btn-link'],
name: 'Cancel',
onClick: jest.fn(),
},
{
classNames: ['usa-button'],
name: 'Edit',
onClick: jest.fn(),
},
{
classNames: ['usa-button', 'usa-button-secondary'],
name: 'Continue',
onClick: jest.fn(),
}
]
};

render(<Modal {...props} />);

for (let button of props.buttons) {
const buttonElement = screen.getByText(button.name);

expect(buttonElement).toBeInTheDocument();

await userEvent.click(buttonElement);
expect(button.onClick).toHaveBeenCalledTimes(1);
}
});
});
});
98 changes: 98 additions & 0 deletions client/test/app/components/__snapshots__/Modal.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Modal renders correctly 1`] = `
<div>
<section
aria-describedby="modal_id-desc"
aria-labelledby="modal_id-title"
aria-modal="true"
class="cf-modal active "
id="modal_id"
role="alertdialog"
>
<div
class="cf-modal-body"
id=""
>
<button
class="cf-modal-close"
id="Test-Modal-Title-button-id-close"
type="button"
>
<span
class="usa-sr-only"
>
Close
</span>
<svg
class="cf-icon-close"
height="55"
viewBox="0 0 55 55"
width="55"
xmlns="http://www.w3.org/2000/svg"
>
<title>
close
</title>
<path
d="M52.6 46.9l-6 6c-.8.8-1.9 1.2-3 1.2s-2.2-.4-3-1.2l-13-13-13 13c-.8.8-1.9 1.2-3 1.2s-2.2-.4-3-1.2l-6-6c-.8-.8-1.2-1.9-1.2-3s.4-2.2 1.2-3l13-13-13-13c-.8-.8-1.2-1.9-1.2-3s.4-2.2 1.2-3l6-6c.8-.8 1.9-1.2 3-1.2s2.2.4 3 1.2l13 13 13-13c.8-.8 1.9-1.2 3-1.2s2.2.4 3 1.2l6 6c.8.8 1.2 1.9 1.2 3s-.4 2.2-1.2 3l-13 13 13 13c.8.8 1.2 1.9 1.2 3s-.4 2.2-1.2 3z"
/>
</svg>
</button>
<div
style="display: flex;"
>
<div
data-css-1gs0ko2=""
>
<h1
id="modal_id-title"
>
Test Modal Title
</h1>
<div
data-css-o98ubo=""
>
<p>
This is text content
</p>
</div>
</div>
</div>
<div
class="cf-modal-divider"
/>
<div
class="cf-modal-controls"
>
<div>
<span
class="cf-push-right"
>
<span>
<button
class="cf-submit usa-button"
type="button"
>
Confirm
</button>
</span>
</span>
<span
class="cf-push-left"
>
<span>
<button
class="cf-submit usa-button"
type="button"
>
Cancel
</button>
</span>
</span>
</div>
</div>
</div>
</section>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('AddClaimantForm', () => {
await waitFor(() => {
expect(onSubmit).toHaveBeenCalled();
});
});
}, 15000);
});

describe('default values', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ describe('AddClaimantPage', () => {
await waitFor(() => {
expect(submit).not.toBeDisabled();
});
});
}, 15000);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { formatDocketSwitchRuling } from 'app/queue/docketSwitch/judgeRuling/Doc

describe('formatDocketSwitchRuling', () => {
const context = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...';
const hyperlink = 'https://example.com/file.txt';

let disposition = 'granted';

Expand All @@ -14,14 +13,12 @@ describe('formatDocketSwitchRuling', () => {
it('properly formats', () => {
const res = formatDocketSwitchRuling({
context,
hyperlink,
disposition,
});

expect(res).toMatch(
new RegExp('I am proceeding with a full switch\\. {2}\\n {2}\\n')
);
expect(res).toMatch(new RegExp(`Signed ruling letter: {2}\\n${hyperlink} {2}\\n {2}\\n`));
expect(res).toMatch(
new RegExp(context)
);
Expand All @@ -37,7 +34,6 @@ describe('formatDocketSwitchRuling', () => {
it('properly formats', () => {
const res = formatDocketSwitchRuling({
context,
hyperlink,
disposition,
});

Expand All @@ -47,7 +43,6 @@ describe('formatDocketSwitchRuling', () => {
'I am proceeding with a partial switch\\. {2}\\n {2}\\n'
)
);
expect(res).toMatch(new RegExp(`Signed ruling letter: {2}\\n${hyperlink} {2}\\n {2}\\n`));
expect(res).toMatch(
new RegExp(context)
);
Expand All @@ -63,14 +58,12 @@ describe('formatDocketSwitchRuling', () => {
it('properly formats', () => {
const res = formatDocketSwitchRuling({
context,
hyperlink,
disposition,
});

expect(res).toMatch(
new RegExp('I am proceeding with a denial\\. {2}\\n {2}\\n')
);
expect(res).toMatch(new RegExp(`Signed ruling letter: {2}\\n${hyperlink} {2}\\n {2}\\n`));
expect(res).toMatch(
new RegExp(context)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@
exports[`formatDocketSwitchRuling with denied disposition properly formats 1`] = `
"I am proceeding with a denial.
Signed ruling letter:
https://example.com/file.txt
Lorem ipsum dolor sit amet, consectetur adipiscing elit..."
`;

exports[`formatDocketSwitchRuling with granted disposition properly formats 1`] = `
"I am proceeding with a full switch.
Signed ruling letter:
https://example.com/file.txt
Lorem ipsum dolor sit amet, consectetur adipiscing elit..."
`;

exports[`formatDocketSwitchRuling with partially_granted disposition properly formats 1`] = `
"I am proceeding with a partial switch.
Signed ruling letter:
https://example.com/file.txt
Lorem ipsum dolor sit amet, consectetur adipiscing elit..."
`;
Loading

0 comments on commit bf9d992

Please sign in to comment.