-
Notifications
You must be signed in to change notification settings - Fork 0
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
unit test for the new homepage #4
base: issue-856-new-homepage
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,11 +96,15 @@ var BlogSection = React.createClass({ | |
featuredPost: { | ||
title: "", | ||
author: "", | ||
publishedDate: "", | ||
publishedDate: new Date(), | ||
contentSnippet: "", | ||
link: "" | ||
link: "https://blog.webmaker.org" | ||
}, | ||
latestPosts: [] | ||
latestPosts: [{ | ||
title: "", | ||
publishedDate: new Date(), | ||
link: "https://blog.webmaker.org" | ||
}] | ||
} | ||
}, | ||
componentDidMount: function() { | ||
|
@@ -109,7 +113,7 @@ var BlogSection = React.createClass({ | |
return; | ||
} | ||
this.setState({ | ||
featuredPost: data.featuredPosts, | ||
featuredPost: data.featuredPost, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. um sorry for being picky, i just thought this should be singular instead of plural 🙊 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yeah totally, that was my bad, thanks for fixing! |
||
latestPosts: data.latestPosts | ||
}); | ||
}.bind(this)); | ||
|
@@ -137,6 +141,9 @@ var BlogSection = React.createClass({ | |
}); | ||
|
||
var HomePage = React.createClass({ | ||
statics: { | ||
BlogSection: BlogSection | ||
}, | ||
render: function() { | ||
return ( | ||
<div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var should = require('should'); | ||
var React = require('react/addons'); | ||
var TestUtils = React.addons.TestUtils; | ||
|
||
var stubContext = require('./stub-context.jsx'); | ||
var stubBlogFeedLoader = require('./stub-blog-feed-loader.js'); | ||
var HomePage = require('../../pages/home.jsx'); | ||
|
||
describe("HomePage", function() { | ||
var homePage, blogSection; | ||
|
||
beforeEach(function() { | ||
homePage = stubContext.render(HomePage); | ||
blogSection = stubContext.render(HomePage.BlogSection); | ||
}); | ||
|
||
describe("blogSection", function() { | ||
it("should display featured post", function() { | ||
blogSection.getDOMNode().querySelector(".featured-post .entry-title").textContent.should.not.eql(""); | ||
}); | ||
it("should display 3 other latest posts", function() { | ||
blogSection.getDOMNode().querySelectorAll(".recent-posts .post-title").length.should.equal(3); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @toolness! ( I created this PR against my own PR so that I(or we) can easily compare the code changes. ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh yeah yup that's what's going on. :( for now i recommend just adding another line at line 16: // Wait for the stub blog posts to load.
beforeEach(process.nextTick); It's not super clean--ideally we'd maybe use sinon to trigger the feed callback ourselves--but it'll do for now, hopefully. Let me know if it doesn't work! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, rather than doing that, you could even wrap that test in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @toolness I tried the following and got errors describe("blogSection", function() {
process.tick(function() {
it("should display featured post", function() {
blogSection.getDOMNode().querySelector(".featured-post .entry-title").textContent.should.not.eql("");
});
it("should display 3 other latest posts", function() {
blogSection.getDOMNode().querySelectorAll(".recent-posts .post-title").length.should.equal(3);
});
});
}); I even tried commenting out There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought it would go like this
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you don't want to do anything asynchronous within |
||
}); | ||
|
||
afterEach(function() { | ||
stubContext.unmount(homePage); | ||
stubContext.unmount(blogSection); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
var FAKE_POSTS = { | ||
"featuredPosts": { | ||
"featuredPost": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"title": "What’s next for Thimble?", | ||
"author": "Hannah Kane", | ||
"publishedDate": "Tue, 12 May 2015 10:47:33 -0700", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have to set some initial values so we don't run into validation / parsing errors during the initial render
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, this will be nice for non-JS users too maybe, so that at least there will be a link to the blog they can click on?