-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
127 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React, { Component } from 'react'; | ||
import sinon from 'sinon'; | ||
import Autosuggest from '../../src/AutosuggestContainer'; | ||
import CustomInput from './CustomInput'; | ||
let app = null; | ||
|
||
export const onChange = sinon.spy((event, { newValue }) => { | ||
app.setState({ | ||
value: newValue | ||
}); | ||
}); | ||
|
||
const onSuggestionsFetchRequested = () => {}; | ||
const getSuggestionValue = () => 'value'; | ||
const renderSuggestion = () => <span>test</span>; | ||
|
||
export default class AutosuggestApp extends Component { | ||
constructor() { | ||
super(); | ||
|
||
app = this; | ||
|
||
this.state = { | ||
value: '', | ||
suggestions: [] | ||
}; | ||
} | ||
|
||
render() { | ||
const { value, suggestions } = this.state; | ||
const inputProps = { | ||
value, | ||
onChange | ||
}; | ||
|
||
return ( | ||
<Autosuggest | ||
suggestions={suggestions} | ||
onSuggestionsFetchRequested={onSuggestionsFetchRequested} | ||
getSuggestionValue={getSuggestionValue} | ||
renderSuggestion={renderSuggestion} | ||
inputProps={inputProps} | ||
inputElement={CustomInput} | ||
alwaysRenderSuggestions={true} /> | ||
); | ||
} | ||
} |
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,20 @@ | ||
import React from 'react'; | ||
import TestUtils from 'react-addons-test-utils'; | ||
import { | ||
init, | ||
expectInputElement | ||
} from '../helpers'; | ||
import AutosuggestApp from './AutosuggestApp'; | ||
import CustomInput from './CustomInput'; | ||
|
||
describe('Autosuggest with inputElement', () => { | ||
beforeEach(() => { | ||
init(TestUtils.renderIntoDocument(<AutosuggestApp />)); | ||
}); | ||
|
||
describe('initially', () => { | ||
it('should render the inputElement', () => { | ||
expectInputElement(CustomInput); | ||
}); | ||
}); | ||
}); |
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,18 @@ | ||
import React, { Component } from 'react'; | ||
|
||
export default class CustomInput extends Component { | ||
constructor() { | ||
super(); | ||
this.state = { | ||
custom: 42 | ||
}; | ||
} | ||
render() { | ||
return ( | ||
<div className="my-custom-input"> | ||
<input {...this.props} /> | ||
<span>(customized)</span> | ||
</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