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:
committed by
mrugesh
parent
9337d6ad82
commit
2b5268305a
@ -45,7 +45,7 @@ const mapDispatchToProps = dispatch =>
|
|||||||
|
|
||||||
const placeholder = 'Search 5,000+ tutorials';
|
const placeholder = 'Search 5,000+ tutorials';
|
||||||
|
|
||||||
class SearchBar extends Component {
|
export class SearchBar extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
@ -62,8 +62,6 @@ class SearchBar extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const searchInput = document.querySelector('.ais-SearchBox-input');
|
|
||||||
searchInput.id = 'fcc_instantsearch';
|
|
||||||
document.addEventListener('click', this.handleFocus);
|
document.addEventListener('click', this.handleFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
27
client/src/components/search/searchBar/SearchBar.test.js
Normal file
27
client/src/components/search/searchBar/SearchBar.test.js
Normal 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()
|
||||||
|
};
|
Reference in New Issue
Block a user