-
Notifications
You must be signed in to change notification settings - Fork 18
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
No errors found upload transcript to VBMS modal #23349
Draft
piedram
wants to merge
5
commits into
feature/APPEALS-49620-and-APPEALS-49626
Choose a base branch
from
piedram/APPEALS-59938
base: feature/APPEALS-49620-and-APPEALS-49626
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d2b1224
No errors found upload transcript to VBMS modal
piedram 6fdfbab
Add jest test
piedram 54d7fa3
Fix error when failt and put placeholder in textarea field
piedram 4539456
remove imprt
piedram 7bf3c30
reduce method in the controller
piedram File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
client/app/queue/UploadTranscriptionVBMSNoErrorModal.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { bindActionCreators } from 'redux'; | ||
import { withRouter } from 'react-router-dom'; | ||
|
||
import TextareaField from '../components/TextareaField'; | ||
|
||
import { highlightInvalidFormItems, requestPatch } from './uiReducer/uiActions'; | ||
import { setAppealAttrs, onReceiveAmaTasks } from './QueueActions'; | ||
|
||
import { | ||
appealWithDetailSelector, | ||
taskById | ||
} from './selectors'; | ||
import { marginTop } from './constants'; | ||
import COPY from '../../COPY'; | ||
|
||
import QueueFlowModal from './components/QueueFlowModal'; | ||
|
||
class UploadTranscriptionVBMSNoErrorModal extends React.PureComponent { | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
instructions: '', | ||
}; | ||
} | ||
|
||
validateForm = () => Boolean(this.state.instructions); | ||
|
||
prependUrlToInstructions = () => { | ||
return this.state.instructions; | ||
}; | ||
|
||
buildPayload = () => { | ||
return { | ||
data: { | ||
task: { | ||
instructions: this.prependUrlToInstructions() | ||
} | ||
} | ||
}; | ||
} | ||
|
||
submit = () => { | ||
const { task } = this.props; | ||
const payload = this.buildPayload(); | ||
|
||
return this.props.requestPatch(`/tasks/${task.taskId}/upload_transcription_to_vbms`, payload). | ||
then((response) => { | ||
this.props.onReceiveAmaTasks({ amaTasks: response.body.tasks.data }); | ||
}). | ||
catch(() => { | ||
// handle the error from the frontend | ||
}); | ||
} | ||
|
||
actionForm = () => { | ||
const { instructions } = this.state; | ||
|
||
return <React.Fragment> | ||
<div> | ||
<div>{COPY.UPLOAD_TRANSCRIPTION_VBMS_TEXT}</div> | ||
<div {...marginTop(4)}> | ||
<TextareaField | ||
name={COPY.UPLOAD_TRANSCRIPTION_VBMS_TEXT_AREA} | ||
onChange={(value) => this.setState({ instructions: value })} | ||
placeholder= "This is the reason this is being put on hold." | ||
value={instructions} /> | ||
</div> | ||
</div> | ||
</React.Fragment>; | ||
}; | ||
|
||
render = () => { | ||
return <QueueFlowModal | ||
validateForm={this.validateForm} | ||
submit={this.submit} | ||
title={COPY.UPLOAD_TRANSCRIPTION_VBMS_TITLE} | ||
button={COPY.UPLOAD_TRANSCRIPTION_VBMS_BUTTON} | ||
pathAfterSubmit={`/queue/appeals/${this.props.appealId}`} | ||
submitButtonClassNames={['usa-button']} | ||
submitDisabled={!this.validateForm()} | ||
> | ||
{ this.actionForm() } | ||
</QueueFlowModal>; | ||
} | ||
} | ||
|
||
UploadTranscriptionVBMSNoErrorModal.propTypes = { | ||
appealId: PropTypes.string, | ||
error: PropTypes.shape({ | ||
title: PropTypes.string, | ||
detail: PropTypes.string | ||
}), | ||
highlightInvalidFormItems: PropTypes.func, | ||
onReceiveAmaTasks: PropTypes.func, | ||
requestPatch: PropTypes.func, | ||
setAppealAttrs: PropTypes.func, | ||
task: PropTypes.shape({ | ||
taskId: PropTypes.string, | ||
type: PropTypes.string, | ||
}) | ||
}; | ||
|
||
const mapStateToProps = (state, ownProps) => ({ | ||
error: state.ui.messages.error, | ||
appeal: appealWithDetailSelector(state, ownProps), | ||
task: taskById(state, { taskId: ownProps.taskId }) | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch) => bindActionCreators({ | ||
highlightInvalidFormItems, | ||
requestPatch, | ||
onReceiveAmaTasks, | ||
setAppealAttrs | ||
}, dispatch); | ||
|
||
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(UploadTranscriptionVBMSNoErrorModal)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
client/test/app/queue/components/UploadTranscriptionVBMSNoErrorModal.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from 'react'; | ||
import { MemoryRouter, Route } from 'react-router'; | ||
import { render, screen, act } from '@testing-library/react'; | ||
import { Provider } from 'react-redux'; | ||
import { applyMiddleware, createStore, compose } from 'redux'; | ||
import thunk from 'redux-thunk'; | ||
import UploadTranscriptionVBMSNoErrorModal from '../../../../app/queue/UploadTranscriptionVBMSNoErrorModal'; | ||
import { | ||
createQueueReducer, | ||
getAppealId, | ||
getTaskId | ||
} from './modalUtils'; | ||
import { UploadTranscriptionVBMSNoErrorData } from '../../../data/queue/taskActionModals/taskActionModalData'; | ||
import userEvent from '@testing-library/user-event'; | ||
import ApiUtil from '../../../../app/util/ApiUtil'; | ||
jest.mock('../../../../app/util/ApiUtil'); | ||
|
||
const renderUploadTranscriptionVBMSNoErrorModal = (storeValues, taskType) => { | ||
const appealId = getAppealId(storeValues); | ||
const taskId = getTaskId(storeValues, taskType); | ||
|
||
const queueReducer = createQueueReducer(storeValues); | ||
const store = createStore( | ||
queueReducer, | ||
compose(applyMiddleware(thunk)) | ||
); | ||
|
||
const path = `/queue/appeals/${appealId}/tasks/${taskId}/modal/upload_transcription_vbms`; | ||
|
||
return render( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={[path]}> | ||
<Route component={(props) => { | ||
return <UploadTranscriptionVBMSNoErrorModal {...props.match.params} />; | ||
}} path="/queue/appeals/:appealId/tasks/:taskId/modal/upload_transcription_vbms" /> | ||
</MemoryRouter> | ||
</Provider> | ||
); | ||
}; | ||
|
||
describe('UploadTranscriptionVBMSNoErrorModal', () => { | ||
const setUpModal = () => renderUploadTranscriptionVBMSNoErrorModal(UploadTranscriptionVBMSNoErrorData, 'RootTask'); | ||
|
||
describe('on modal open', () => { | ||
test('modal title: "Upload transcript to VBMS"', () => { | ||
setUpModal(); | ||
|
||
expect(screen.getByRole('heading', { level: 1 })).toBeTruthy(); | ||
}); | ||
|
||
test('submit button is initially disabled', () => { | ||
setUpModal(); | ||
|
||
expect(screen.getByText('Upload to VBMS', { selector: 'button' })).toBeDisabled(); | ||
}); | ||
}); | ||
|
||
describe('Button Disabled until text field is populated', () => { | ||
const instructionsLabel = 'Please provide context and instructions for this action'; | ||
|
||
test('instructions field is present', async () => { | ||
jest.useFakeTimers('modern'); | ||
setUpModal(); | ||
|
||
const response = { status: 200, body: { document_presence: true } }; | ||
|
||
ApiUtil.get.mockResolvedValue(response); | ||
await act(async() => jest.runAllTimers()); | ||
userEvent.type(screen.getByLabelText(instructionsLabel), 'This is a test.'); | ||
jest.runAllTimers(); | ||
expect(screen.getByText('Upload to VBMS', { selector: 'button' })).toBeEnabled(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could reduce this method's indentations by using a
return unless
clause instead ofif
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I apologize for being unclear.
For code cleanliness, leave an empty line below the
return
command, and remove one level of indentation through the rest of the method.Functionally there's no difference, but its the sort of thing RuboCop's Layout Cop looks for.