Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProjectStatus unit tests #4127

Merged
merged 9 commits into from
Nov 8, 2017
10 changes: 5 additions & 5 deletions app/pages/admin/project-status.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ class ProjectStatus extends Component {

return (
<ul className="project-status__section-list">
{this.state.dialogIsOpen &&
<WorkflowDefaultDialog
onCancel={this.handleDialogCancel}
onSuccess={this.handleDialogSuccess}
/>}
{this.state.workflows.map((workflow) => {
return (
<li key={workflow.id} className="section-list__item">
Expand All @@ -144,11 +149,6 @@ class ProjectStatus extends Component {
checked={workflow.active}
handleToggle={event => this.handleToggle(event, workflow)}
/>{' | '}
{this.state.dialogIsOpen &&
<WorkflowDefaultDialog
onCancel={this.handleDialogCancel}
onSuccess={this.handleDialogSuccess}
/>}
<label>
Level:{' '}
<select
Expand Down
141 changes: 141 additions & 0 deletions app/pages/admin/project-status.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import React from 'react';
import assert from 'assert';
import sinon from 'sinon';
import { shallow } from 'enzyme';
import ProjectStatus from './project-status';

const project = {
name: 'Test Project',
configuration: {
default_workflow: '1'
}
};

const workflows = [
{
active: true,
configuration: {},
display_name: 'Test Workflow 1',
id: '1'
},
{
active: true,
configuration: {},
display_name: 'Test Workflow 2',
id: '2'
},
{
active: false,
configuration: {},
display_name: 'Test Workflow 3',
id: '3'
}
];

describe('ProjectStatus', () => {
let handleDialogCancelStub;
let handleDialogSuccessStub;
let loadingIndicator;
let onChangeWorkflowLevelStub;
let wrapper;

before(() => {
onChangeWorkflowLevelStub = sinon.stub(ProjectStatus.prototype, 'onChangeWorkflowLevel');
handleDialogCancelStub = sinon.stub(ProjectStatus.prototype, 'handleDialogCancel');
handleDialogSuccessStub = sinon.stub(ProjectStatus.prototype, 'handleDialogSuccess');

wrapper = shallow(<ProjectStatus />);
});

it('renders without crashing', () => {
assert.equal(wrapper, wrapper);
});

describe('when no project is in component state', () => {
it('renders Loading Indicator component', () => {
loadingIndicator = wrapper.find('LoadingIndicator');
assert.equal(loadingIndicator.length, 1);
});
});

describe('when project is in component state', () => {
before(() => {
wrapper.setState({ project });
});

it('does not render the LoadingIndicator component', () => {
loadingIndicator = wrapper.find('LoadingIndicator');
assert.equal(loadingIndicator.length, 0);
});

it('renders a ProjectIcon component', () => {
wrapper.setState({ project });
const projectIconComponent = wrapper.find('ProjectIcon');
assert.equal(projectIconComponent.length, 1);
});

it('renders a RedirectToggle component', () => {
const redirectToggleComponent = wrapper.find('RedirectToggle');
assert.equal(redirectToggleComponent.length, 1);
});

it('renders a ExperimentalFeatures component', () => {
const experimentalFeaturesComponent = wrapper.find('ExperimentalFeatures');
assert.equal(experimentalFeaturesComponent.length, 1);
});

it('renders a VersionList component', () => {
const versionListComponent = wrapper.find('VersionList');
assert.equal(versionListComponent.length, 1);
});

it('renders a no workflows found message when no workflow is in component state', () => {
const noWorkflowsMessage = wrapper.find('.project-status__section').at(1).children().find('div');
assert.equal(noWorkflowsMessage.text(), 'No workflows found');
});
});

describe('when workflow is in component state', () => {
before(() => {
wrapper.setState({ workflows });
});

it('displays an asterisk next to the default workflow, if one is set', () => {
const defaultWorkflow = wrapper.find('li.section-list__item').first().text();
assert.ok(defaultWorkflow.match(' * '), true);
});

it('does not display an asterisk next to a workflow that is not the default workflow', () => {
const notDefaultWorkflow = wrapper.find('li.section-list__item').last().text();
assert.ok(notDefaultWorkflow.match(' * '), false);
});

it('renders a WorkflowToggle component for each workflow', () => {
const workflowToggleComponents = wrapper.find('WorkflowToggle');
assert.equal(workflowToggleComponents.length, workflows.length);
});

it('calls #onChangeWorkflowLevel when a user changes a workflow\'s configuration level', () => {
wrapper.find('select').first().simulate('change');
sinon.assert.calledOnce(onChangeWorkflowLevelStub);
});

it('renders the WorkflowDefaultDialog component when dialogIsOpen state is true', () => {
wrapper.setState({ dialogIsOpen: true });
const workflowDefaultDialog = wrapper.find('WorkflowDefaultDialog');
assert.equal(workflowDefaultDialog.length, 1);
});

it('calls #handleDialogCancel when a user cancels the WorkflowDefaultDialog modal', () => {
const workflowDefaultDialog = wrapper.find('WorkflowDefaultDialog');
workflowDefaultDialog.simulate('cancel');
sinon.assert.calledOnce(handleDialogCancelStub);
});

it('calls #handleDialogSuccess when a user clicks ok on the WorkflowDefaultDialog modal', () => {
const workflowDefaultDialog = wrapper.find('WorkflowDefaultDialog');
workflowDefaultDialog.simulate('success');
sinon.assert.calledOnce(handleDialogSuccessStub);
});
});
});