autoland-ui: Improve tests for ActionButtons by ensuring the land button functions properly. (
Bug 1336249) r?imadueme
MozReview-Commit-ID: HK4z1vZZYWY
--- a/autoland/ui/src/__tests__/ActionButtons.js
+++ b/autoland/ui/src/__tests__/ActionButtons.js
@@ -1,17 +1,37 @@
import React from 'react';
-import ActionButtons from '../components/ActionButtons';
import { shallow } from 'enzyme';
-test('landable=true shows "Land" button', () => {
- const instance = shallow(
- <ActionButtons landable={true} bug="1111111" />
- );
- expect(instance.find('.land').length).toBe(1);
-});
+import ActionButtons from '../components/ActionButtons';
+
+describe('Action Buttons', () => {
+
+ test('landable=true shows "Land" button', () => {
+ const mount = shallow(
+ <ActionButtons landable={true} bug="1111111" />
+ );
+ expect(mount.find('.land').length).toBe(1);
+ });
-test('landable=false hides "Land" button', () => {
- const instance = shallow(
- <ActionButtons landable={false} bug="1111111" />
- );
- expect(instance.find('.land').length).toBe(0);
+ test('landable=false hides "Land" button', () => {
+ const mount = shallow(
+ <ActionButtons landable={false} bug="1111111" />
+ );
+ expect(mount.find('.land').length).toBe(0);
+ });
+
+ test('Clicking the "Land" button executes passed callback', () => {
+ const callback = jest.fn();
+ const mount = shallow(
+ <ActionButtons landable={true} bug="1111111" landcallback={callback} />
+ );
+ mount.find('.land').simulate('click');
+
+ expect(callback.mock.calls.length).toBe(1);
+ expect(mount.state('landing')).toBe(true);
+
+ // Also check that it can't be clicked multiple times
+ mount.find('.land').simulate('click');
+ expect(callback.mock.calls.length).toBe(1);
+ });
+
});
--- a/autoland/ui/src/components/ActionButtons.jsx
+++ b/autoland/ui/src/components/ActionButtons.jsx
@@ -3,17 +3,19 @@ import React from 'react';
class ActionButtons extends React.Component {
constructor(props) {
super(props);
this.state = { landing: false };
this.onLandClick = this.onLandClick.bind(this);
}
onLandClick(e) {
- e.preventDefault();
+ if (e) {
+ e.preventDefault();
+ }
if (this.state.landing) {
return;
}
this.setState({ landing: true });
this.props.landcallback();
}
render() {