From 39a565e8892ff7e68ce73cdd4ca0d20e2fe66d95 Mon Sep 17 00:00:00 2001 From: Alexander Wolf Date: Fri, 8 Feb 2019 04:37:30 +0100 Subject: [PATCH] Test DevelopmentServerPane component (#359) --- .../DevelopmentServerPane.js | 2 +- .../DevelopmentServerPane.test.js | 61 ++++++++++++ .../DevelopmentServerPane.test.js.snap | 92 +++++++++++++++++++ 3 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 src/components/DevelopmentServerPane/DevelopmentServerPane.test.js create mode 100644 src/components/DevelopmentServerPane/__snapshots__/DevelopmentServerPane.test.js.snap diff --git a/src/components/DevelopmentServerPane/DevelopmentServerPane.js b/src/components/DevelopmentServerPane/DevelopmentServerPane.js index ffd4055d..185be74d 100644 --- a/src/components/DevelopmentServerPane/DevelopmentServerPane.js +++ b/src/components/DevelopmentServerPane/DevelopmentServerPane.js @@ -28,7 +28,7 @@ type Props = { abortTask: Dispatch, }; -class DevelopmentServerPane extends PureComponent { +export class DevelopmentServerPane extends PureComponent { handleToggle = (isToggled: boolean) => { const { task, launchDevServer, abortTask, project } = this.props; diff --git a/src/components/DevelopmentServerPane/DevelopmentServerPane.test.js b/src/components/DevelopmentServerPane/DevelopmentServerPane.test.js new file mode 100644 index 00000000..534f4cd3 --- /dev/null +++ b/src/components/DevelopmentServerPane/DevelopmentServerPane.test.js @@ -0,0 +1,61 @@ +/* eslint-disable flowtype/require-valid-file-annotation */ +import React from 'react'; +import { shallow } from 'enzyme'; +import lolex from 'lolex'; + +import { DevelopmentServerPane } from './DevelopmentServerPane'; + +describe('DevelopmentServerPane component', () => { + let wrapper; + let instance; + lolex.install(); + + const task = { + name: 'start', + status: 'idle', + }; + + const project = { + id: 'a-project', + type: 'create-react-app', + }; + + const mockActions = { + launchDevServer: jest.fn(), + abortTask: jest.fn(), + }; + + beforeEach(() => { + wrapper = shallow( + + ); + instance = wrapper.instance(); + }); + + describe('Rendering', () => { + it('should render', () => { + expect(wrapper).toMatchSnapshot(); + }); + + it('should return message if no tasks', () => { + wrapper = shallow(); + expect(wrapper.text()).toMatch(/This project does not appear/); + }); + }); + + describe('Component logic', () => { + it('should start devServer', () => { + instance.handleToggle(true); + expect(mockActions.launchDevServer).toBeCalledWith(task, new Date()); + }); + + it('should abort task', () => { + instance.handleToggle(false); + expect(mockActions.abortTask).toBeCalledWith( + task, + project.type, + new Date() + ); + }); + }); +}); diff --git a/src/components/DevelopmentServerPane/__snapshots__/DevelopmentServerPane.test.js.snap b/src/components/DevelopmentServerPane/__snapshots__/DevelopmentServerPane.test.js.snap new file mode 100644 index 00000000..9f73d0e1 --- /dev/null +++ b/src/components/DevelopmentServerPane/__snapshots__/DevelopmentServerPane.test.js.snap @@ -0,0 +1,92 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`DevelopmentServerPane component Rendering should render 1`] = ` + + } + title="Development Server" +> + + + + + Runs a local development server that updates whenever you make changes to the files. + + + + + View Documentation + + + + + + + + + + + + + + Runs a local development server that updates whenever you make changes to the files. + + + + + View Documentation + + + + + + + + + + +`;