Skip to content

Commit a75afc1

Browse files
committed
We add a unit test for PostSubmit component
1 parent 27e85f8 commit a75afc1

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

client/templates/posts/post_submit.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ PostInput = React.createClass({
1717
},
1818
render () {
1919
const errorClassName = "form-group " + this.props.errorClassName;
20+
const inputClass = "form-control "+this.props.title.toLowerCase();
2021
return (
2122
<div className={errorClassName}>
2223
<label className="control-label" htmlFor={this.props.title.toLowerCase()}>{this.props.title}</label>
@@ -29,7 +30,7 @@ PostInput = React.createClass({
2930
placeholder={this.props.placeholder}
3031
value={this.props.value}
3132
onChange={this.handleChangedValue}
32-
className="form-control"
33+
className={inputClass}
3334
/>
3435
<span className="help-block">{this.props.errorMessage}</span>
3536
</div>

tests/jasmine/client/unit/components/post_item_spec.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,19 @@ describe("PostItem", function () {
4141
expect($el.text()).toContain("Edit");
4242

4343
});
44-
//
45-
//it("should go to post page", function () {
46-
// var fakeUrl = "posts/XYZ"
44+
45+
//it("should call showPost function", function () {
46+
// // We get the discuss button
47+
// var button = React.addons.TestUtils.findRenderedDOMComponentWithClass(component, "discuss");
48+
// console.log(button);
49+
// // We set a fake url
50+
// var fakeUrl = "posts/XYZ";
51+
// // We spy on FlowRouter object
4752
// spyOn(FlowRouter, "go").and.returnValue(fakeUrl);
48-
// renderWithProps(defProps);
49-
// expect(PostItem.prototype.showPost($.Event("click"))).toBe(fakeUrl);
50-
// expect(FlowRouter.go.calls.argsFor(0)).toEqual("posts/XYZ");
53+
// // We simulate the click event into Discuss button
54+
// React.addons.TestUtils.Simulate.click(button.getDOMNode())
55+
// // We expect the FlowRouter.go function to has as paramter the below string
56+
// expect(FlowRouter.go.calls.argsFor(0)).toEqual(["/posts/XYZ"]);
5157
//});
52-
58+
5359
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
describe("PostSubmit", function () {
2+
var defProps, renderWithProps, component, el, $el;
3+
4+
beforeEach(function () {
5+
renderWithProps = function (props) {
6+
component = renderComponent(PostSubmit, props);
7+
el = React.findDOMNode(component);
8+
$el = $(el);
9+
};
10+
});
11+
12+
it("should render an input for post's title", function () {
13+
// We spyOn Meteor.userId to provide a user id
14+
spyOn(Meteor, "userId").and.returnValue("xyz");
15+
// We render the component
16+
renderWithProps({});
17+
// We get the dom element with class title
18+
var titleInput = TestUtils.findRenderedDOMComponentWithClass(component, "title");
19+
// We expect to be defined"
20+
expect(titleInput).toBeDefined();
21+
});
22+
23+
});

0 commit comments

Comments
 (0)