Skip to content

Commit

Permalink
Add basic specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcarbs committed Aug 26, 2016
1 parent bb81df2 commit 1e7d83a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 8 deletions.
3 changes: 0 additions & 3 deletions src/elements/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ const inputPropNames = [
'min',
'multiple',
'name',
'onBlur',
'onChange',
'onFocus',
'pattern',
'placeholder',
'readOnly',
Expand Down
10 changes: 6 additions & 4 deletions src/modules/Search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export default class Search extends Component {
static _meta = _meta
static Result = SearchResult
static Results = SearchResults
static Category = SearchCategory

componentWillMount() {
if (super.componentWillMount) super.componentWillMount()
Expand Down Expand Up @@ -195,14 +196,12 @@ export default class Search extends Component {
if (!prevState.focus && this.state.focus) {
if (!this.state.open) {
document.addEventListener('keydown', this.openOnArrow)
document.addEventListener('keydown', this.openOnSpace)
} else {
document.addEventListener('keydown', this.moveSelectionOnKeyDown)
document.addEventListener('keydown', this.selectItemOnEnter)
}
} else if (prevState.focus && !this.state.focus) {
document.removeEventListener('keydown', this.openOnArrow)
document.removeEventListener('keydown', this.openOnSpace)
document.removeEventListener('keydown', this.moveSelectionOnKeyDown)
document.removeEventListener('keydown', this.selectItemOnEnter)
}
Expand All @@ -215,7 +214,6 @@ export default class Search extends Component {
document.addEventListener('keydown', this.selectItemOnEnter)
document.addEventListener('click', this.closeOnDocumentClick)
document.removeEventListener('keydown', this.openOnArrow)
document.removeEventListener('keydown', this.openOnSpace)
} else if (prevState.open && !this.state.open) {
this.close()
document.removeEventListener('keydown', this.closeOnEscape)
Expand All @@ -228,7 +226,6 @@ export default class Search extends Component {
componentWillUnmount() {
debug('componentWillUnmount()')
document.removeEventListener('keydown', this.openOnArrow)
document.removeEventListener('keydown', this.openOnSpace)
document.removeEventListener('keydown', this.moveSelectionOnKeyDown)
document.removeEventListener('keydown', this.selectItemOnEnter)
document.removeEventListener('keydown', this.closeOnEscape)
Expand Down Expand Up @@ -275,6 +272,11 @@ export default class Search extends Component {
const code = keyboardKey.getCode(e)
if (!_.includes([keyboardKey.ArrowDown, keyboardKey.ArrowUp], code)) return
if (this.state.open) return

const { minCharacters } = this.props
const { value } = this.state
if (value.length < minCharacters) return

e.preventDefault()
// TODO open/close should only change state, open/closeMenu should be called on did update
this.trySetState({ open: true })
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Search/SearchCategory.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ SearchCategory.propTypes = {
text: PropTypes.string,
}

SearchCategory.meta = {
SearchCategory._meta = {
name: 'SearchCategory',
parent: 'Search',
type: META.TYPES.MODULE,
Expand Down
6 changes: 6 additions & 0 deletions test/specs/modules/Search/Search-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Search from 'src/modules/Search/Search'
import * as common from 'test/specs/commonTests'

describe('Search', () => {
common.isConformant(Search)
})
7 changes: 7 additions & 0 deletions test/specs/modules/Search/SearchCategory-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import SearchCategory from 'src/modules/Search/SearchCategory'
import * as common from 'test/specs/commonTests'

describe('SearchCategory', () => {
common.isConformant(SearchCategory)
common.rendersChildren(SearchCategory)
})
7 changes: 7 additions & 0 deletions test/specs/modules/Search/SearchResult-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import SearchResult from 'src/modules/Search/SearchResult'
import * as common from 'test/specs/commonTests'

describe('SearchResult', () => {
common.isConformant(SearchResult)
common.propKeyOnlyToClassName(SearchResult, 'active')
})
7 changes: 7 additions & 0 deletions test/specs/modules/Search/SearchResults-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import SearchResults from 'src/modules/Search/SearchResults'
import * as common from 'test/specs/commonTests'

describe('SearchResults', () => {
common.isConformant(SearchResults)
common.rendersChildren(SearchResults)
})

0 comments on commit 1e7d83a

Please sign in to comment.