added more jasmine spec; NSFW wip

This commit is contained in:
danielgrippi 2011-12-12 17:05:34 -08:00 committed by Dennis Collinson
parent cec2d27204
commit ffae0f8e85
4 changed files with 84 additions and 32 deletions

View file

@ -21,6 +21,7 @@
</a>
<div class="content">
<div class="post_initial_info">
<span class="from">
<a href="/people/<%= author.id %>">
@ -36,6 +37,12 @@
</span>
</div>
<% if(text !== null && text.match(/#nsfw/)) { %>
<div class="shield">
This post has been flagged as NSFW by its author.
</div>
<% } %>
<div class="post-content"> </div>
<div class="info">
@ -46,13 +53,13 @@
</span>
<% } %>
<span class="post_scope">
<%= public === true ? "Public" : "Limited" %>
<%= public ? "Public" : "Limited" %>
-
</span>
<span class="like_action">
<% if(user_like !== null) { %>
<a href="/posts/<%= id %>/likes/<%= user_like.id %>" class="unlike" data-method='delete' data-remote='true' rel='nofollow'>
<% if(user_like) { %>
<a href="/posts/<%= id %>/likes/<%= user_like.id %>" class="unlike" data-method='delete' data-remote='true' rel='nofollow'>
Unlike
</a>
<% } else { %>
@ -63,6 +70,23 @@
</span>
·
<% if(public) { %>
<span class="reshare_action">
<% if(root) {
var rootGuid = root.guid;
}
else {
var rootGuid = guid;
} %>
<a href="/reshares?root_guid=<%= rootGuid %>" data-confirm="Reshare Bob Grimm's post?" data-method="post" data-remote="true" rel="nofollow">
Reshare
</a>
·
</span>
<% } %>
<a href="#" class="focus_comment_textarea">
Comment
</a>

View file

@ -1,15 +0,0 @@
App.Views.Reshare = Backbone.View.extend({
initialize: function(options) {
this.model = options.model;
this.template = _.template($("#reshare-template").html());
},
render: function() {
this.el = $(this.template($.extend(
this.model.toJSON(),
App.user()
)));
return this;
}
});

View file

@ -10,17 +10,66 @@ describe("App.views.Post", function(){
this.collection = new App.Collections.Stream(posts);
this.statusMessage = this.collection.models[0];
this.view = new App.Views.Post({model : this.statusMessage}).render();
this.statusElement = $(this.view.el)
})
context("comment clicking", function(){
it("shows the status message in the content area", function(){
console.log(this.statusElement);
//expect(this.statusElement).toBe("hella infos yo!")
context("NSFW", function(){
it("contains a shield element", function(){
this.statusMessage.set({text : "this is safe for work. #sfw"});
var view = new App.Views.Post({model : this.statusMessage}).render();
var statusElement = $(view.el)
expect(statusElement.find(".shield").html()).toBeNull();
})
it("does not contain a shield element", function(){
this.statusMessage.set({text : "nudie magazine day! #nsfw"});
var view = new App.Views.Post({model : this.statusMessage}).render();
var statusElement = $(view.el)
expect(statusElement.find(".shield").html()).toNotBe(null);
})
})
context("Reshare link", function(){
it("is present if the post is public", function(){
this.statusMessage.set({"public" : true});
var view = new App.Views.Post({model : this.statusMessage}).render();
var statusElement = $(view.el)
expect(statusElement.find(".reshare_action")).toNotBe(null);
})
it("is not present if the post is not public", function(){
this.statusMessage.set({"public" : false});
var view = new App.Views.Post({model : this.statusMessage}).render();
var statusElement = $(view.el)
expect(statusElement.find(".reshare_action").html()).toBeNull();
})
})
context("Like link", function(){
it("displays 'Unlike' if the current user has already liked the post", function(){
this.statusMessage.set({user_like : null});
var view = new App.Views.Post({model : this.statusMessage}).render();
var statusElement = $(view.el)
expect(statusElement.find(".like_action a").text()).toContain('Like');
})
it("displays 'Like' if the current user has not already liked the post", function(){
this.statusMessage.set({user_like : { id : 1 }});
var view = new App.Views.Post({model : this.statusMessage}).render();
var statusElement = $(view.el)
expect(statusElement.find(".like_action a").text()).toContain('Unlike');
})
})
})
})

View file

@ -20,13 +20,7 @@ describe("App.views.Stream", function(){
context("when rendering a Status Mesasage", function(){
it("shows the status message in the content area", function(){
expect($.trim(this.statusElement.find(".post-content p").text())).toBe("hella infos yo!")
})
})
context("when rendering a Reshare", function(){
it("shows the reshare in the content area", function(){
expect($.trim(this.reshareElement.find(".content h2").text())).toBe("this is a reshare");
expect(this.statusElement.find(".post-content p").text()).toContain("jimmy's 2 whales")
})
})
})