Skip to content

Commit 76c4bdc

Browse files
author
Matt Swanson
committed
add some test for StoryView.
1 parent 715fe5d commit 76c4bdc

4 files changed

Lines changed: 106 additions & 2 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"use strict";
2+
3+
describe("Storyiew", function(){
4+
it("should exist", function(){
5+
StoryView.should.exist;
6+
});
7+
8+
describe("Rendering the view", function(){
9+
before(function() {
10+
this.story = new Story({
11+
source: "TechKrunch",
12+
headline: "Every startups acquired by Yahoo!",
13+
lead: "This is the lead.",
14+
title: "Every startups acquired by Yahoo! NOT!!",
15+
body: "All remote workers have been exiled to Ohio.",
16+
pretty_date: "Mon July 1, 2013",
17+
permalink: "http://example.com/krunch",
18+
keep_unread: false,
19+
is_read: false
20+
});
21+
22+
this.view = new StoryView({model: this.story})
23+
24+
this.view.render();
25+
});
26+
27+
it("should render li.story items", function(){
28+
this.view.$el.hasClass("story").should.be.true;
29+
});
30+
31+
var assertTagExists = function(el, tagName) {
32+
el.find(tagName).should.have.length(1);
33+
};
34+
35+
var assertPropertyRendered = function(el, model, propName) {
36+
el.html().should.have.string(model.get(propName));
37+
};
38+
39+
it("should render blog title", function(){
40+
assertTagExists(this.view.$el, ".blog-title");
41+
assertPropertyRendered(this.view.$el, this.story, "source");
42+
});
43+
44+
it("should render story headline", function(){
45+
assertTagExists(this.view.$el, ".story-title");
46+
assertPropertyRendered(this.view.$el, this.story, "headline");
47+
});
48+
49+
it("should render story lead", function(){
50+
assertTagExists(this.view.$el, ".story-lead");
51+
assertPropertyRendered(this.view.$el, this.story, "lead");
52+
});
53+
54+
it("should render story full title", function(){
55+
assertTagExists(this.view.$el, ".story-body");
56+
assertPropertyRendered(this.view.$el, this.story, "title");
57+
});
58+
59+
it("should render story full title as link", function(){
60+
assertTagExists(this.view.$el, ".story-body h1 a");
61+
});
62+
63+
it("should render story full body", function(){
64+
assertTagExists(this.view.$el, ".story-body");
65+
assertPropertyRendered(this.view.$el, this.story, "body");
66+
});
67+
68+
it("should render story date", function(){
69+
assertTagExists(this.view.$el, ".story-published");
70+
assertPropertyRendered(this.view.$el, this.story, "pretty_date");
71+
});
72+
73+
it("should render story permalink", function(){
74+
assertTagExists(this.view.$el, ".story-permalink");
75+
assertPropertyRendered(this.view.$el, this.story, "permalink");
76+
});
77+
78+
it("should render keep as unread button", function(){
79+
assertTagExists(this.view.$el, ".story-keep-unread");
80+
});
81+
82+
it("should autofill unread button based on item", function(){
83+
assertTagExists(this.view.$el, ".story-keep-unread .icon-check-empty");
84+
85+
this.story.set("keep_unread", true);
86+
this.view.render();
87+
88+
assertTagExists(this.view.$el, ".story-keep-unread .icon-check");
89+
});
90+
});
91+
});

‎spec/javascript/support/vendor/css/mocha.css‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ body {
128128
color: #c00;
129129
max-height: 300px;
130130
overflow: auto;
131+
max-width: 600px;
131132
}
132133

133134
#mocha .test pre {
@@ -143,6 +144,7 @@ body {
143144
-webkit-box-shadow: 0 1px 3px #eee;
144145
-moz-border-radius: 3px;
145146
-moz-box-shadow: 0 1px 3px #eee;
147+
white-space: pre-wrap;
146148
}
147149

148150
#mocha .test h2 {

‎spec/javascript/support/views/index.erb‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>JavaScript Tests</title>
4+
<title>Stringer JavaScript Test Suite</title>
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
66
<%= js :application %>
77

@@ -11,6 +11,12 @@
1111
<% css_files.each do |css_file| %>
1212
<link rel="stylesheet" type="text/css" href="<%= css_file%>">
1313
<% end %>
14+
15+
<!-- Javascript templates -->
16+
<% js_templates.each do |template| %>
17+
<%= template %>
18+
<%= render_js_template template.to_sym %>
19+
<% end %>
1420
</head>
1521
<body>
1622
<div id="mocha"></div>

‎spec/javascript/test_controller.rb‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ def self.test_path(*chunks)
66

77
get '/test' do
88
erb File.read(self.class.test_path('support', 'views', 'index.erb')), layout: false, locals: {
9-
js_files: js_files
9+
js_files: js_files,
10+
js_templates: js_templates
1011
}
1112
end
1213

@@ -59,4 +60,8 @@ def js_files
5960
def css_files
6061
vendor_css_files
6162
end
63+
64+
def js_templates
65+
[:story]
66+
end
6267
end

0 commit comments

Comments
 (0)