Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Commit

Permalink
Test DevelopmentServerPane component (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
AWolf81 authored and melanieseltzer committed Feb 8, 2019
1 parent c84c992 commit 39a565e
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Props = {
abortTask: Dispatch<typeof actions.abortTask>,
};

class DevelopmentServerPane extends PureComponent<Props> {
export class DevelopmentServerPane extends PureComponent<Props> {
handleToggle = (isToggled: boolean) => {
const { task, launchDevServer, abortTask, project } = this.props;

Expand Down
61 changes: 61 additions & 0 deletions src/components/DevelopmentServerPane/DevelopmentServerPane.test.js
Original file line number Diff line number Diff line change
@@ -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(
<DevelopmentServerPane task={task} project={project} {...mockActions} />
);
instance = wrapper.instance();
});

describe('Rendering', () => {
it('should render', () => {
expect(wrapper).toMatchSnapshot();
});

it('should return message if no tasks', () => {
wrapper = shallow(<DevelopmentServerPane />);
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()
);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DevelopmentServerPane component Rendering should render 1`] = `
<Pane
moreInfoHref="https://github.com/joshwcomeau/guppy/blob/master/docs/getting-started.md#development-server"
primaryActionChildren={
<Toggle
isToggled={false}
onToggle={[Function]}
padding={2}
size={32}
/>
}
title="Development Server"
>
<OnlyOn
display="inline"
size="mdMin"
>
<styled.div>
<styled.div>
<styled.div>
Runs a local development server that updates whenever you make changes to the files.
</styled.div>
<DevelopmentServerStatus
status="idle"
/>
<styled.div>
<ExternalLink
color="#304FFE"
display="inline-block"
hoverColor="#3f6cff"
href="https://github.com/facebook/create-react-app#user-guide"
>
View Documentation
</ExternalLink>
</styled.div>
</styled.div>
<styled.div>
<Connect(TerminalOutput)
height={300}
task={
Object {
"name": "start",
"status": "idle",
}
}
title="Server Logs"
/>
</styled.div>
</styled.div>
</OnlyOn>
<OnlyOn
display="inline"
size="sm"
>
<styled.div>
<styled.div>
<styled.div>
<styled.div>
Runs a local development server that updates whenever you make changes to the files.
</styled.div>
<styled.div
size={10}
/>
<styled.div>
<ExternalLink
color="#304FFE"
display="inline-block"
hoverColor="#3f6cff"
href="https://github.com/facebook/create-react-app#user-guide"
>
View Documentation
</ExternalLink>
</styled.div>
</styled.div>
</styled.div>
<styled.div>
<Connect(TerminalOutput)
height={300}
task={
Object {
"name": "start",
"status": "idle",
}
}
/>
</styled.div>
</styled.div>
</OnlyOn>
</Pane>
`;

0 comments on commit 39a565e

Please sign in to comment.