added tests and stuff for own profile checking... for some reason something isn't getting triggered properly in the presenter call, though :(

This commit is contained in:
danielgrippi 2012-04-24 00:10:09 -07:00
parent c667dac248
commit 91ebff75dd
4 changed files with 50 additions and 10 deletions

View file

@ -16,13 +16,14 @@ app.pages.Profile = app.views.Base.extend({
}, },
editMode : false, editMode : false,
presenter : function(){ presenter : function(){
var bio = this.model.get("bio") || '' var bio = this.model.get("bio") || ''
return _.extend(this.defaultPresenter(), return _.extend(this.defaultPresenter(),
{text : this.model && app.helpers.textFormatter(bio, this.model)}) {text : this.model && app.helpers.textFormatter(bio, this.model),
isOwnProfile : true })
}, },
initialize : function(options) { initialize : function(options) {
this.model = new app.models.Profile.findByGuid(options.personId) this.model = new app.models.Profile.findByGuid(options.personId)
this.stream = options && options.stream || new app.models.Stream() this.stream = options && options.stream || new app.models.Stream()
@ -36,5 +37,12 @@ app.pages.Profile = app.views.Base.extend({
if(evt) { evt.preventDefault() } if(evt) { evt.preventDefault() }
this.editMode = !this.editMode this.editMode = !this.editMode
this.$el.toggleClass("edit-mode") this.$el.toggleClass("edit-mode")
},
isOwnProfile : function() {
// this is all tested, but does not work. there is something weird going here :(
// i'm going to return true in the presenter for now until this is resolved.
return(app.currentUser.get("diaspora_id") == this.model.get("diaspora_id"))
} }
}); });

View file

@ -2,7 +2,6 @@ app.views.ProfileInfo = app.views.Base.extend({
templateName : "profile-info", templateName : "profile-info",
initialize : function(){ initialize : function(){
console.log(this.model)
this.model.bind("change", this.render, this) //this should go on profile info view when it gets Extracted this.model.bind("change", this.render, this) //this should go on profile info view when it gets Extracted
} }
}) });

View file

@ -5,12 +5,14 @@
<section id="profile-info"/> <section id="profile-info"/>
<section id="profile-controls"> <section id="profile-controls">
<a href="/posts/new" class="control"> {{#if isOwnProfile}}
<img src='{{imageUrl "buttons/add_post.jpg"}}' /> <a href="/posts/new" class="control">
</a> <img src='{{imageUrl "buttons/add_post.jpg"}}' />
<a href="#" id="edit-mode-toggle" class="control"> </a>
<img src='{{imageUrl "buttons/edit_canvas.png"}}' /> <a href="#" id="edit-mode-toggle" class="control">
</a> <img src='{{imageUrl "buttons/edit_canvas.png"}}' />
</a>
{{/if}}
</section> </section>
<section id="canvas"> <section id="canvas">

View file

@ -33,6 +33,20 @@ describe("app.pages.Profile", function(){
this.page.render() this.page.render()
}); });
context("profile control pane", function(){
it("is shown", function() {
spyOn(this.page, "isOwnProfile").andReturn(true)
this.page.render()
expect(this.page.$("#profile-controls .control").length).not.toBe(0)
})
it("is not shown", function() {
spyOn(this.page, "isOwnProfile").andReturn(false)
this.page.render()
expect(this.page.$("#profile-controls .control").length).toBe(0)
})
})
context("clicking fav", function(){ context("clicking fav", function(){
beforeEach(function(){ beforeEach(function(){
spyOn(this.post, 'toggleFavorite') spyOn(this.post, 'toggleFavorite')
@ -64,4 +78,21 @@ describe("app.pages.Profile", function(){
}) })
}) })
}) })
describe("isOwnProfile", function(){
beforeEach(function(){
this.user = new app.models.User(factory.author())
this.page.model = this.user
})
it("returns true if app.currentUser matches the current profile's user", function(){
app.currentUser = this.user
expect(this.page.isOwnProfile()).toBeTruthy()
})
it("returns false if app.currentUser does not match the current profile's user", function(){
app.currentUser = new app.models.User(factory.author({diaspora_id : "foo@foo.com"}))
expect(this.page.isOwnProfile()).toBeFalsy()
})
})
}); });