chore(client): add tests for search bar (#37012)

* feat(client): Tests for search bar

* Switched out Enzyme for react-test-renderer, but had to remove a lot of the incompatible tests
This commit is contained in:
Kristofer Koishigawa
2019-10-22 20:31:00 +09:00
committed by mrugesh
parent 9337d6ad82
commit 2b5268305a
2 changed files with 28 additions and 3 deletions

View File

@ -45,7 +45,7 @@ const mapDispatchToProps = dispatch =>
const placeholder = 'Search 5,000+ tutorials';
class SearchBar extends Component {
export class SearchBar extends Component {
constructor(props) {
super(props);
@ -62,8 +62,6 @@ class SearchBar extends Component {
}
componentDidMount() {
const searchInput = document.querySelector('.ais-SearchBox-input');
searchInput.id = 'fcc_instantsearch';
document.addEventListener('click', this.handleFocus);
}

View File

@ -0,0 +1,27 @@
/* global jest, expect */
import React from 'react';
import 'jest-dom/extend-expect';
import ShallowRenderer from 'react-test-renderer/shallow';
import { SearchBar } from './SearchBar';
describe('<SearchBar />', () => {
it('renders to the DOM', () => {
const shallow = new ShallowRenderer();
shallow.render(<SearchBar {...searchBarProps} />);
const result = shallow.getRenderOutput();
expect(result).toBeTruthy();
});
/* Todo: When e2e testing is in place,
add tests to check that the search bar
resets to -1 on change/input, redirects to a
selected hit, and redirects to dev news if
there's a query and no hit is selected */
});
const searchBarProps = {
toggleSearchDropdown: jest.fn(),
toggleSearchFocused: jest.fn(),
updateSearchQuery: jest.fn()
};