controls.test.jsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import React from 'react';
  2. import {mountWithIntl} from '../../helpers/intl-helpers.jsx';
  3. import Controls from '../../../src/components/controls/controls';
  4. import TurboMode from '../../../src/components/turbo-mode/turbo-mode';
  5. import GreenFlag from '../../../src/components/green-flag/green-flag';
  6. import StopAll from '../../../src/components/stop-all/stop-all';
  7. describe('Controls component', () => {
  8. const defaultProps = () => ({
  9. active: false,
  10. onGreenFlagClick: jest.fn(),
  11. onStopAllClick: jest.fn(),
  12. turbo: false
  13. });
  14. test('shows turbo mode when in turbo mode', () => {
  15. const component = mountWithIntl(
  16. <Controls
  17. {...defaultProps()}
  18. />
  19. );
  20. expect(component.find(TurboMode).exists()).toEqual(false);
  21. component.setProps({turbo: true});
  22. expect(component.find(TurboMode).exists()).toEqual(true);
  23. });
  24. test('triggers the right callbacks when clicked', () => {
  25. const props = defaultProps();
  26. const component = mountWithIntl(
  27. <Controls
  28. {...props}
  29. />
  30. );
  31. component.find(GreenFlag).simulate('click');
  32. expect(props.onGreenFlagClick).toHaveBeenCalled();
  33. component.find(StopAll).simulate('click');
  34. expect(props.onStopAllClick).toHaveBeenCalled();
  35. });
  36. });