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:
parent
c667dac248
commit
91ebff75dd
4 changed files with 50 additions and 10 deletions
|
|
@ -16,13 +16,14 @@ app.pages.Profile = app.views.Base.extend({
|
|||
},
|
||||
|
||||
editMode : false,
|
||||
|
||||
presenter : function(){
|
||||
var bio = this.model.get("bio") || ''
|
||||
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) {
|
||||
this.model = new app.models.Profile.findByGuid(options.personId)
|
||||
this.stream = options && options.stream || new app.models.Stream()
|
||||
|
|
@ -36,5 +37,12 @@ app.pages.Profile = app.views.Base.extend({
|
|||
if(evt) { evt.preventDefault() }
|
||||
this.editMode = !this.editMode
|
||||
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"))
|
||||
}
|
||||
});
|
||||
|
|
@ -2,7 +2,6 @@ app.views.ProfileInfo = app.views.Base.extend({
|
|||
templateName : "profile-info",
|
||||
|
||||
initialize : function(){
|
||||
console.log(this.model)
|
||||
this.model.bind("change", this.render, this) //this should go on profile info view when it gets Extracted
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
@ -5,12 +5,14 @@
|
|||
<section id="profile-info"/>
|
||||
|
||||
<section id="profile-controls">
|
||||
<a href="/posts/new" class="control">
|
||||
<img src='{{imageUrl "buttons/add_post.jpg"}}' />
|
||||
</a>
|
||||
<a href="#" id="edit-mode-toggle" class="control">
|
||||
<img src='{{imageUrl "buttons/edit_canvas.png"}}' />
|
||||
</a>
|
||||
{{#if isOwnProfile}}
|
||||
<a href="/posts/new" class="control">
|
||||
<img src='{{imageUrl "buttons/add_post.jpg"}}' />
|
||||
</a>
|
||||
<a href="#" id="edit-mode-toggle" class="control">
|
||||
<img src='{{imageUrl "buttons/edit_canvas.png"}}' />
|
||||
</a>
|
||||
{{/if}}
|
||||
</section>
|
||||
|
||||
<section id="canvas">
|
||||
|
|
|
|||
|
|
@ -33,6 +33,20 @@ describe("app.pages.Profile", function(){
|
|||
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(){
|
||||
beforeEach(function(){
|
||||
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()
|
||||
})
|
||||
})
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue