autoland-ui: Improve tests for ActionButtons by ensuring the land button functions properly. (Bug 1336249) r?imadueme draft
authorDavid Walsh <dwalsh@mozilla.com>
Thu, 02 Feb 2017 17:27:20 -0600
changeset 88 65e1cb82f9c562788e8bd8e7af9f2f02806f3a56
parent 86 84eacbb50d900cfcce920d27ff6158d1a49ae3de
child 89 20d5426f348ad9d4eb307e7823e13af0d620d065
child 91 621ff6903b0d0d49e60a6dfd335b6cfdb436b5c0
push id56
push userbmo:dwalsh@mozilla.com
push dateFri, 03 Feb 2017 20:40:03 +0000
reviewersimadueme
bugs1336249
autoland-ui: Improve tests for ActionButtons by ensuring the land button functions properly. (Bug 1336249) r?imadueme MozReview-Commit-ID: HK4z1vZZYWY
autoland/ui/src/__tests__/ActionButtons.js
autoland/ui/src/components/ActionButtons.jsx
--- 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() {