From 52f6fd6f86066ab0001f4bc958b1a6eb1114386e Mon Sep 17 00:00:00 2001 From: Mavis Ou Date: Thu, 28 May 2015 03:00:02 -0700 Subject: [PATCH] (WIP) unit test for the new homepage --- pages/home.jsx | 15 ++++++++++---- test/browser/home-page.test.jsx | 30 +++++++++++++++++++++++++++ test/browser/stub-blog-feed-loader.js | 2 +- 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 test/browser/home-page.test.jsx diff --git a/pages/home.jsx b/pages/home.jsx index f427ca27a..6c8121a1a 100644 --- a/pages/home.jsx +++ b/pages/home.jsx @@ -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, latestPosts: data.latestPosts }); }.bind(this)); @@ -137,6 +141,9 @@ var BlogSection = React.createClass({ }); var HomePage = React.createClass({ + statics: { + BlogSection: BlogSection + }, render: function() { return (
diff --git a/test/browser/home-page.test.jsx b/test/browser/home-page.test.jsx new file mode 100644 index 000000000..9a99de577 --- /dev/null +++ b/test/browser/home-page.test.jsx @@ -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); + }); + }); + + afterEach(function() { + stubContext.unmount(homePage); + stubContext.unmount(blogSection); + }); +}); diff --git a/test/browser/stub-blog-feed-loader.js b/test/browser/stub-blog-feed-loader.js index 2d76c03e6..865fefcc9 100644 --- a/test/browser/stub-blog-feed-loader.js +++ b/test/browser/stub-blog-feed-loader.js @@ -1,5 +1,5 @@ var FAKE_POSTS = { - "featuredPosts": { + "featuredPost": { "title": "What’s next for Thimble?", "author": "Hannah Kane", "publishedDate": "Tue, 12 May 2015 10:47:33 -0700",