-
Notifications
You must be signed in to change notification settings - Fork 10
GoToTicket box is shown on all pages #131
base: master
Are you sure you want to change the base?
Changes from all commits
6c0f0f1
fc06a19
9f7c696
707a3a0
0ad9697
50949b0
69fd333
4ef5499
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,46 +3,54 @@ import PropTypes from 'prop-types' | |
| import { connect } from 'react-redux' | ||
| import { TextField } from 'material-ui' | ||
| import FlatButtonStyled from 'components/elements/FlatButtonStyled' | ||
| import { updateIncidentCreationInput } from 'actions/incidentActions' | ||
| import { updateTicketNavigationInput } from 'actions/incidentActions' | ||
| import Paper from 'material-ui/Paper' | ||
|
|
||
| export const onSubmit = (input, history, dispatch) => () => { | ||
| export const onSubmit = (input, history) => () => { | ||
| if (input) { | ||
| dispatch(updateIncidentCreationInput('')) | ||
| history.push(/tickets/ + input) | ||
| history.push('/tickets/' + input) | ||
| } | ||
| } | ||
|
|
||
| export const CreateIncident = ({input, creationError, history, dispatch}) => <form | ||
| id='incident-search' | ||
| export const GoToTicketForm = ({input, creationError, history, dispatch}) => <form | ||
| id='incident-navigation' | ||
| onSubmit={onSubmit(input, history)} | ||
| style={{padding: '16px'}} | ||
| > | ||
| <TextField | ||
| hintText='Ticket Id of primary ticket' | ||
| hintText='Ticket Id' | ||
| floatingLabelText='Ticket Id' | ||
| onChange={(event, newValue) => dispatch(updateIncidentCreationInput(newValue))} | ||
| onChange={(event, newValue) => dispatch(updateTicketNavigationInput(newValue))} | ||
| value={input} | ||
| errorText={creationError} | ||
| /> | ||
| <FlatButtonStyled | ||
| label='Submit' | ||
| onTouchTap={onSubmit(input, history, dispatch)} | ||
| onTouchTap={onSubmit(input, history)} | ||
| /> | ||
| </form> | ||
|
|
||
| export const mapStateToProps = (state) => { | ||
| export const mapStateToProps = (state, ownProps) => { | ||
| return { | ||
| input: state.incidents.creation.input, | ||
| ticketSystem: state.tickets.systems[1], | ||
| creationError: state.incidents.creation.error ? state.incidents.creation.error.message : '' | ||
| creationError: state.incidents.creation.error ? state.incidents.creation.error.message : '', | ||
| ...ownProps | ||
| } | ||
| } | ||
|
|
||
| CreateIncident.propTypes = { | ||
| GoToTicketForm.propTypes = { | ||
| input: PropTypes.string, | ||
| creationError: PropTypes.string, | ||
| history: PropTypes.object.isRequired, | ||
| dispatch: PropTypes.func.isRequired | ||
| } | ||
|
|
||
| export default connect(mapStateToProps)(CreateIncident) | ||
| export const ConnectedGoToTicketForm = connect(mapStateToProps)(GoToTicketForm) | ||
|
|
||
| export const GoToTicket = ({history}) => <Paper zDepth={1}> | ||
| <span>Go To Ticket:</span> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [This will almost certainly be less relevant given our discussion at the standup] The To get "Go To Ticket" on the same line as the form:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From our conversation earlier and the wireframe up top, Toolbars might give us what we need here: http://www.material-ui.com/#/components/toolbar |
||
| <ConnectedGoToTicketForm history={history} /> | ||
| </Paper> | ||
|
|
||
| export default GoToTicket | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,27 +2,34 @@ | |
| import { expect } from 'chai' | ||
| import React from 'react' | ||
| import { TextField } from 'material-ui' | ||
| import Paper from 'material-ui/Paper' | ||
|
|
||
| import { GetMockDispatch, GetDispatchRecorder } from 'test/helpers/mockDispatch' | ||
| import { GetMockHistory, GetHistoryRecorder } from 'test/helpers/mockHistory' | ||
| import createComponent from 'test/helpers/shallowRenderHelper' | ||
|
|
||
| import { CreateIncident, mapStateToProps, onSubmit } from 'components/Search/CreateIncident' | ||
| import { | ||
| GoToTicketForm, | ||
| mapStateToProps, | ||
| onSubmit, | ||
| ConnectedGoToTicketForm, | ||
| GoToTicket | ||
| } from 'components/Incident/GoToTicket' | ||
| import FlatButtonStyled from 'components/elements/FlatButtonStyled' | ||
|
|
||
| const setup = (input, creationError) => { | ||
| let props = { | ||
| dispatch: () => null, | ||
| input, | ||
| creationError | ||
| } | ||
| describe('GoToTicket', function () { | ||
| describe('GoToTicketForm render output', function () { | ||
| const setup = (input, creationError) => { | ||
| let props = { | ||
| dispatch: () => null, | ||
| input, | ||
| creationError | ||
| } | ||
|
|
||
| return createComponent(CreateIncident, props) | ||
| } | ||
| return createComponent(GoToTicketForm, props) | ||
| } | ||
|
|
||
| describe('CreateIncident', function testCreateIncident () { | ||
| describe('Rendered component', function () { | ||
| beforeEach(function createIncidentInit () { | ||
| beforeEach(function () { | ||
| this.testError = 'Test Error' | ||
| this.testInput = '10' | ||
|
|
||
|
|
@@ -31,7 +38,7 @@ describe('CreateIncident', function testCreateIncident () { | |
| this.withInput = setup(this.testInput, '') | ||
| }) | ||
|
|
||
| it('Should render a form with text field and FlatButtonStyled', function createIncidentRenderForm () { | ||
| it('Should render a form with text field and FlatButtonStyled', function () { | ||
| expect(this.defaultCase.type).to.equal('form') | ||
| expect(this.defaultCase.props.children[0].type).to.equal(TextField) | ||
| expect(this.defaultCase.props.children[1].type).to.equal(FlatButtonStyled) | ||
|
|
@@ -43,12 +50,12 @@ describe('CreateIncident', function testCreateIncident () { | |
| expect(this.withInput.props.children[1].type).to.equal(FlatButtonStyled) | ||
| }) | ||
|
|
||
| it('Should pass props.input to TextField value', function createIncidentDisplayInput () { | ||
| it('Should pass props.input to TextField value', function () { | ||
| expect(this.defaultCase.props.children[0].props.value).to.equal('') | ||
| expect(this.withInput.props.children[0].props.value).to.equal(this.testInput) | ||
| }) | ||
|
|
||
| it('Should pass props.creationError to TextField errorText', function createIncidentDisplayCreationError () { | ||
| it('Should pass props.creationError to TextField errorText', function () { | ||
| expect(this.defaultCase.props.children[0].props.errorText).to.equal('') | ||
| expect(this.withError.props.children[0].props.errorText).to.equal(this.testError) | ||
| }) | ||
|
|
@@ -59,23 +66,13 @@ describe('CreateIncident', function testCreateIncident () { | |
| const input = 'testInput' | ||
| const historyRecord = GetHistoryRecorder() | ||
| const history = GetMockHistory(historyRecord) | ||
| const dispatchRecord = GetDispatchRecorder() | ||
| const dispatch = GetMockDispatch(dispatchRecord) | ||
|
|
||
| onSubmit(input, history, dispatch)() | ||
| onSubmit(input, history)() | ||
| describe('History', function () { | ||
| it('Should push a new url based on input', function () { | ||
| expect(historyRecord[0]).to.equal('/tickets/testInput') | ||
| }) | ||
| }) | ||
|
|
||
| describe('Dispatched actions', function () { | ||
| it('Should dispatch an updateIncidentCreationInput action', function () { | ||
| expect(dispatchRecord.action).to.not.be.null | ||
| expect(dispatchRecord.action.type).to.equal('UPDATE_INCIDENT_CREATION_INPUT') | ||
| expect(dispatchRecord.action.input).to.equal('') | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| context('When input is not truthy', function () { | ||
|
|
@@ -85,59 +82,74 @@ describe('CreateIncident', function testCreateIncident () { | |
| const dispatchRecord = GetDispatchRecorder() | ||
| const dispatch = GetMockDispatch(dispatchRecord) | ||
|
|
||
| onSubmit(input, history, dispatch)() | ||
| onSubmit(input, history)() | ||
| describe('History', function () { | ||
| it('Should not be changed', function () { | ||
| expect(historyRecord.length).to.equal(0) | ||
| }) | ||
| }) | ||
|
|
||
| describe('Dispatched actions', function () { | ||
| it('Should not have dispatched any actions', function () { | ||
| expect(dispatchRecord.action).to.be.undefined | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| const inputState = { | ||
| tickets: { | ||
| map: { | ||
| 1: {id: 100} | ||
| }, | ||
| systems: { | ||
| 1: {id: 1}, | ||
| 2: {id: 2} | ||
| } | ||
| }, | ||
| incidents: { | ||
| creation: { | ||
| input: 'test input', | ||
| error: { | ||
| message: 'test error message' | ||
| describe('mapStateToProps', function () { | ||
| const inputState = { | ||
| tickets: { | ||
| map: { | ||
| 1: {id: 100} | ||
| }, | ||
| systems: { | ||
| 1: {id: 1}, | ||
| 2: {id: 2} | ||
| } | ||
| }, | ||
| incidents: { | ||
| creation: { | ||
| input: 'test input', | ||
| error: { | ||
| message: 'test error message' | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const expectedResult = { | ||
| input: 'test input', | ||
| ticketSystem: { | ||
| id: 1 | ||
| }, | ||
| creationError: 'test error message', | ||
| incidentActions: { | ||
| TestKey: 'TestValue' | ||
| } | ||
| } | ||
|
|
||
| describe('CreateIncidentMapStateToProps', () => { | ||
| it('Should correctly generate an args object from state', () => { | ||
|
|
||
| const result = mapStateToProps(inputState) | ||
|
|
||
| expect(result.input).to.equal(expectedResult.input) | ||
| expect(result.ticketSystem.id).to.equal(expectedResult.ticketSystem.id) | ||
| expect(result.creationError).to.equal(expectedResult.creationError) | ||
| it('Should correctly generate an args object from state', () => { | ||
| const expectedResult = { | ||
| input: 'test input', | ||
| ticketSystem: { | ||
| id: 1 | ||
| }, | ||
| creationError: 'test error message', | ||
| incidentActions: { | ||
| TestKey: 'TestValue' | ||
| } | ||
| } | ||
|
|
||
| expect(result.input).to.equal(expectedResult.input) | ||
| expect(result.ticketSystem.id).to.equal(expectedResult.ticketSystem.id) | ||
| expect(result.creationError).to.equal(expectedResult.creationError) | ||
| }) | ||
| }) | ||
|
|
||
| describe('GoToTicket render output', function () { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to change anything here... Taking advantage of another soapbox opportunity These tests are manually verifying aspects of the component but they're not handling scenarios where, for example, a child could be added after |
||
| const result = createComponent(GoToTicket) | ||
|
|
||
| it('Should be a Paper', function () { | ||
| expect(result.type).to.equal(Paper) | ||
| }) | ||
|
|
||
| it('Should have a label span as its first child', function () { | ||
| expect(result.props.children[0].type).to.equal('span') | ||
| }) | ||
|
|
||
| it('Should have ConnectedGoToTicketForm as its second child', function () { | ||
| expect(result.props.children[1].type).to.equal(ConnectedGoToTicketForm) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
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.
historyappears to go unused in any calls toupdateTicketNavigationInputand within the function body itself. Is it necessary?