-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from hql287/custom-invoice-id
Allow user to set custom invoiceID
- Loading branch information
Showing
15 changed files
with
315 additions
and
43 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Libraries | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
// Custom Components | ||
import { Section } from '../shared/Section'; | ||
|
||
// Animation | ||
import _withFadeInAnimation from '../shared/hoc/_withFadeInAnimation'; | ||
|
||
// Styles | ||
import styled from 'styled-components'; | ||
const NoteContent = styled.textarea` | ||
min-height: 36px; | ||
border-radius: 4px; | ||
padding: 10px; | ||
display: block; | ||
width: 100%; | ||
border: 1px solid #f2f3f4; | ||
color: #3a3e42; | ||
font-size: 14px; | ||
`; | ||
|
||
// Component | ||
export class InvoiceID extends PureComponent { | ||
constructor(props) { | ||
super(props); | ||
this.state = { invoiceID: this.props.invoiceID }; | ||
this.handleInputChange = this.handleInputChange.bind(this); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (nextProps.invoiceID === "") { | ||
this.setState({ invoiceID: "" }); | ||
} | ||
} | ||
|
||
handleInputChange(event) { | ||
this.setState({ invoiceID: event.target.value }, () => { | ||
this.props.updateFieldData('invoiceID', this.state.invoiceID); | ||
}); | ||
} | ||
|
||
render() { | ||
const { t } = this.props; | ||
return ( | ||
<Section> | ||
<label className="itemLabel">Invoice ID</label> | ||
<input | ||
name="invoiceID" | ||
type="text" | ||
onChange={this.handleInputChange} | ||
value={this.state.invoiceID} | ||
/> | ||
</Section> | ||
); | ||
} | ||
} | ||
|
||
InvoiceID.propTypes = { | ||
invoiceID: PropTypes.string.isRequired, | ||
t: PropTypes.func.isRequired, | ||
updateFieldData: PropTypes.func.isRequired, | ||
}; | ||
|
||
// Export | ||
export default _withFadeInAnimation(InvoiceID); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Libs | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import { mount } from 'enzyme'; | ||
|
||
// Component | ||
import { InvoiceID } from '../InvoiceID.jsx'; | ||
|
||
// Mocks | ||
const t = jest.fn(); | ||
const updateFieldData = jest.fn(); | ||
const invoiceID = "Invoice: 123-456-789" | ||
|
||
describe('InvoiceID component', () => { | ||
let wrapper; | ||
beforeEach(() => { | ||
wrapper = mount( | ||
<InvoiceID | ||
t={t} | ||
invoiceID={invoiceID} | ||
updateFieldData={updateFieldData} | ||
/> | ||
); | ||
}); | ||
|
||
// PROPS & STATE | ||
it('receives correct props', () => { | ||
expect(wrapper.prop('invoiceID')).toEqual(invoiceID); | ||
expect(wrapper.prop('updateFieldData')).toEqual(updateFieldData); | ||
}); | ||
|
||
// RENDER | ||
it('renders necessary element', () => { | ||
expect(wrapper.find('label')).toHaveLength(1); | ||
expect(wrapper.find('input')).toHaveLength(1); | ||
}); | ||
|
||
// LIFE CYCLE EVENTS | ||
// TODO | ||
it('render when necessary', () => {}); | ||
|
||
// PRIVATE METHOD | ||
it('handleInputChange correctly', () => { | ||
const spy = jest.spyOn(InvoiceID.prototype, 'handleInputChange'); | ||
const wrap = mount( | ||
<InvoiceID | ||
t={t} | ||
invoiceID={invoiceID} | ||
updateFieldData={updateFieldData} | ||
/> | ||
); | ||
const textInput = wrap.find('input'); | ||
textInput.simulate('change', { target: { value: 'Invoice: 987-654-321' } }); | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
|
||
// SNAPSHOT | ||
it('matches snapshot', () => { | ||
const tree = renderer | ||
.create( | ||
<InvoiceID | ||
t={t} | ||
invoiceID={invoiceID} | ||
updateFieldData={updateFieldData} | ||
/> | ||
) | ||
.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); |
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
19 changes: 19 additions & 0 deletions
19
app/components/form/__tests__/__snapshots__/InvoiceID.spec.jsx.snap
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,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`InvoiceID component matches snapshot 1`] = ` | ||
<div | ||
className="Section__SectionStyle-dgSKSv cwfAAu" | ||
> | ||
<label | ||
className="itemLabel" | ||
> | ||
Invoice ID | ||
</label> | ||
<input | ||
name="invoiceID" | ||
onChange={[Function]} | ||
type="text" | ||
value="Invoice: 123-456-789" | ||
/> | ||
</div> | ||
`; |
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
Oops, something went wrong.