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

Specs #36

Merged
merged 9 commits into from
Feb 22, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/js/_admin/components/applications/application_row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class ApplicationRow extends React.Component {
application_instances_count : React.PropTypes.number,
}).isRequired,
saveApplication: React.PropTypes.func.isRequired,
}
};

static getStyles() {
return {
Expand All @@ -34,7 +34,7 @@ export default class ApplicationRow extends React.Component {
const styles = ApplicationRow.getStyles();
return (
<tr>
<td>
<td className="test-link">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change the code for tests

<Link to={`/applications/${this.props.application.id}/application_instances`}>{this.props.application.name}</Link>
</td>
<td><span>{this.props.application.application_instances_count}</span></td>
Expand Down
47 changes: 47 additions & 0 deletions client/js/_admin/components/applications/application_row.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { Provider } from 'react-redux';
import Helper from '../../../../specs_support/helper';
import ApplicationRow from './application_row';

describe('applications application row', () => {
let result;
let props;

beforeEach(() => {
props = {
application: {
id : 314159,
name : "SPECNAME",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strings must use singlequote quotes

application_instances_count : 123
},
saveApplication: () => {}
};

result = TestUtils.renderIntoDocument(
<Provider store={Helper.makeStore()}>
<table><tbody>
<ApplicationRow {...props} />
</tbody></table>
</Provider>
);

});

it('button is clicked', () => {
const button = TestUtils.findRenderedDOMComponentWithClass(result, 'i-settings');
TestUtils.Simulate.click(button);
expect(button);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write a test for the button.

});

it('renders application instances count', () => {
const span = TestUtils.findRenderedDOMComponentWithTag(result, 'span');
expect(span.textContent).toContain('123');
});

it('renders application link', () => {
const link = TestUtils.findRenderedDOMComponentWithClass(result, 'test-link');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try not to modify the code with test specific changes.

expect(link.innerText).toContain('SPECNAME');
});

});
47 changes: 47 additions & 0 deletions client/js/_admin/components/applications/form.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import Stub from '../../../../specs_support/stub';
import Form from './form';

describe('applications form', () => {

let result;
let props;
let action;

beforeEach(() => {
action = false;
props = {
onChange : () => {},
closeModal : () => { action = true; },
save : () => { action = true; },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make each action different.

description : "SPEC_DESCRIPTION"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strings must use singlequote quotes

};

result = TestUtils.renderIntoDocument(
<Stub>
<Form {...props} />
</Stub>
);
});

it('renders a form', () => {
const button = TestUtils.findRenderedDOMComponentWithClass(result, 'c-btn c-btn--yellow');
TestUtils.Simulate.click(button);
expect(action).toBeTruthy();
});

it('close modal', () => {
const button = TestUtils.findRenderedDOMComponentWithClass(result, 'c-btn c-btn--gray--large u-m-right');
TestUtils.Simulate.click(button);
expect(action).toBeTruthy();
});

it('renders description', () => {
const element = TestUtils.findRenderedDOMComponentWithClass(result, 'o-grid o-grid__modal-top');
expect(element).toBeDefined();
const childDivs = element.childNodes;
const inputTag = childDivs[0].firstChild.childNodes[1];
expect(inputTag.value).toContain('SPEC_DESCRIPTION');
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon semi

});
39 changes: 39 additions & 0 deletions client/js/_admin/components/applications/index.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { Provider } from 'react-redux';
import Helper from '../../../../specs_support/helper';
import { Index } from './index';

describe('applications index', () => {
let result;
let props;

beforeEach(() => {
props = {
saveApplication: () => {},
applications: {
Spiderman: {
Power1: "Wall Crawling",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strings must use singlequote quotes

Power2: "Spidey Sense"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strings must use singlequote quotes

}
}
};

result = TestUtils.renderIntoDocument(
<Provider store={Helper.makeStore()}>
<Index {...props} />
</Provider>
);
});

it('render the application rows', () => {
const element = TestUtils.findRenderedDOMComponentWithClass(result, 'o-contain o-contain--full');
expect(element).toBeDefined();
});

it('render application', () => {
const element = TestUtils.findRenderedDOMComponentWithTag(result, 'tbody');
expect(element.childNodes.length).toBeGreaterThan(0);
});

});
42 changes: 42 additions & 0 deletions client/js/_admin/components/applications/modal.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { Provider } from 'react-redux';
import Helper from '../../../../specs_support/helper';
import Modal from './modal';

describe('applications modal', () => {
let result;
let props;
let isShown;
beforeEach(() => {
isShown = true;
props = {
application: {
name : 'SPEC_NAME',
description : 'SPEC_STRING'
},
isOpen: true,
closeModal: () => { isShown = false; },
save: () => {}
};

result = TestUtils.renderIntoDocument(
<Provider store={Helper.makeStore()} >
<Modal {...props} />
</Provider>
);
});

it('modal is shown', () => {
const modal = TestUtils.findRenderedComponentWithType(result, Modal);
expect(modal).toBeDefined();
expect(modal.props.isOpen).toBeTruthy();
});

it('modal is hidden', () => {
const modal = TestUtils.findRenderedComponentWithType(result, Modal);
expect(modal).toBeDefined();
modal.props.closeModal();
expect(isShown).toBeFalsy();
});
});