-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replacing karma+mocha with jest+enzyme. (#4162)
* Replacing karma+mocha with jest+enzyme. This change is: * Replacing previously little used karma + mocha with jest + enzyme, which allows us to do snapshot testing * Updating enzyme * Converting existing tests to work with jest * Making maven run jest for tests * Establishing consistent directory structure for tests (tests for `src/foo/bar/Baz.jsx` are in `test/foo/bar/Baz.test.js`) * Adding mocking helpers. * Adding default rules parameter value, correcting condition. * Putting tests next to components under test. (cherry picked from commit 14218bc)
- Loading branch information
1 parent
6db7ae3
commit e994dd2
Showing
33 changed files
with
826 additions
and
5,435 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,19 +1,13 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const Spinner = ({ text }) => <span><i className="fa fa-spin fa-spinner" /> {text}</span>; | ||
|
||
const Spinner = React.createClass({ | ||
propTypes: { | ||
text: PropTypes.string, | ||
}, | ||
getDefaultProps() { | ||
return { text: 'Loading...' }; | ||
}, | ||
getInitialState() { | ||
return {}; | ||
}, | ||
render() { | ||
return (<span><i className="fa fa-spin fa-spinner" /> {this.props.text}</span>); | ||
}, | ||
}); | ||
Spinner.propTypes = { | ||
text: PropTypes.string, | ||
}; | ||
Spinner.defaultProps = { | ||
text: 'Loading...', | ||
}; | ||
|
||
export default Spinner; |
18 changes: 18 additions & 0 deletions
18
graylog2-web-interface/src/components/common/Spinner.test.jsx
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 from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
|
||
import Spinner from 'components/common/Spinner'; | ||
|
||
describe('<Spinner />', () => { | ||
it('should render without props', () => { | ||
const wrapper = renderer.create(<Spinner />); | ||
expect(wrapper.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render with a different text string', () => { | ||
const text = 'Hello world!'; | ||
const wrapper = renderer.create(<Spinner text={text}/>); | ||
expect(wrapper.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
}); |
21 changes: 21 additions & 0 deletions
21
graylog2-web-interface/src/components/common/__snapshots__/Spinner.test.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,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<Spinner /> should render with a different text string 1`] = ` | ||
<span> | ||
<i | ||
className="fa fa-spin fa-spinner" | ||
/> | ||
Hello world! | ||
</span> | ||
`; | ||
|
||
exports[`<Spinner /> should render without props 1`] = ` | ||
<span> | ||
<i | ||
className="fa fa-spin fa-spinner" | ||
/> | ||
Loading... | ||
</span> | ||
`; |
29 changes: 29 additions & 0 deletions
29
graylog2-web-interface/src/components/users/UserPreferencesButton.test.js
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,29 @@ | ||
import React from 'react'; | ||
|
||
import { CombinedProviderMock, StoreMock } from 'helpers/mocking'; | ||
|
||
describe('UserPreferencesButton', function () { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
}); | ||
|
||
it('should load user data when user clicks edit button', function () { | ||
const PreferencesStore = StoreMock('get', 'listen', 'loadUserPreferences'); | ||
const combinedProviderMock = new CombinedProviderMock({ | ||
Preferences: { PreferencesStore }, | ||
}); | ||
|
||
jest.doMock('injection/CombinedProvider', () => combinedProviderMock); | ||
|
||
const UserPreferencesButton = require('components/users/UserPreferencesButton'); | ||
const userName = 'Full'; | ||
const instance = require('enzyme').mount(<UserPreferencesButton userName={userName} />); | ||
|
||
expect(instance).toMatchSnapshot(); | ||
expect(instance.find('button')).toBeDefined(); | ||
|
||
instance.find('button').simulate('click'); | ||
|
||
expect(PreferencesStore.loadUserPreferences).toBeCalled(); | ||
}); | ||
}); |
93 changes: 93 additions & 0 deletions
93
graylog2-web-interface/src/components/users/__snapshots__/UserPreferencesButton.test.js.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,93 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`UserPreferencesButton should load user data when user clicks edit button 1`] = ` | ||
<UserPreferencesButton | ||
userName="Full" | ||
> | ||
<span> | ||
<Button | ||
active={false} | ||
block={false} | ||
bsClass="btn" | ||
bsStyle="success" | ||
disabled={false} | ||
onClick={[Function]} | ||
> | ||
<button | ||
className="btn btn-success" | ||
disabled={false} | ||
onClick={[Function]} | ||
type="button" | ||
> | ||
User preferences | ||
</button> | ||
</Button> | ||
<UserPreferencesModal | ||
userName="Full" | ||
> | ||
<BootstrapModalForm | ||
cancelButtonText="Cancel" | ||
formProps={Object {}} | ||
onSubmitForm={[Function]} | ||
submitButtonDisabled={false} | ||
submitButtonText="Save" | ||
title="Preferences for user Full" | ||
> | ||
<BootstrapModalWrapper | ||
onHide={[Function]} | ||
> | ||
<Modal | ||
animation={true} | ||
autoFocus={true} | ||
backdrop={true} | ||
bsClass="modal" | ||
dialogComponentClass={[Function]} | ||
enforceFocus={true} | ||
keyboard={true} | ||
manager={ | ||
ModalManager { | ||
"containers": Array [], | ||
"data": Array [], | ||
"handleContainerOverflow": true, | ||
"hideSiblingNodes": true, | ||
"modals": Array [], | ||
} | ||
} | ||
onHide={[Function]} | ||
renderBackdrop={[Function]} | ||
restoreFocus={true} | ||
show={false} | ||
> | ||
<Modal | ||
autoFocus={true} | ||
backdrop={true} | ||
backdropClassName="modal-backdrop" | ||
backdropTransitionTimeout={150} | ||
containerClassName="modal-open" | ||
dialogTransitionTimeout={300} | ||
enforceFocus={true} | ||
keyboard={true} | ||
manager={ | ||
ModalManager { | ||
"containers": Array [], | ||
"data": Array [], | ||
"handleContainerOverflow": true, | ||
"hideSiblingNodes": true, | ||
"modals": Array [], | ||
} | ||
} | ||
onEntering={[Function]} | ||
onExited={[Function]} | ||
onHide={[Function]} | ||
renderBackdrop={[Function]} | ||
restoreFocus={true} | ||
show={false} | ||
transition={[Function]} | ||
/> | ||
</Modal> | ||
</BootstrapModalWrapper> | ||
</BootstrapModalForm> | ||
</UserPreferencesModal> | ||
</span> | ||
</UserPreferencesButton> | ||
`; |
Oops, something went wrong.