Newspaper theme selected by default, template picker object
This commit is contained in:
parent
9af60d520b
commit
9e50d0efb6
6 changed files with 119 additions and 45 deletions
|
|
@ -13,12 +13,8 @@ app.models.Post = Backbone.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
setFrameName : function(){
|
setFrameName : function(){
|
||||||
this.set({frame_name : findTheme(this)})
|
var templatePicker = new app.models.Post.TemplatePicker(this)
|
||||||
|
this.set({frame_name : templatePicker.getFrameName()})
|
||||||
|
|
||||||
function findTheme(model) {
|
|
||||||
return model.get("photos").length == 1 ? "Wallpaper" : "Day"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
createdAt : function() {
|
createdAt : function() {
|
||||||
|
|
|
||||||
29
app/assets/javascripts/app/models/post/template_picker.js
Normal file
29
app/assets/javascripts/app/models/post/template_picker.js
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
//require ../post
|
||||||
|
|
||||||
|
app.models.Post.TemplatePicker = function(model){
|
||||||
|
this.model = model
|
||||||
|
}
|
||||||
|
|
||||||
|
_.extend(app.models.Post.TemplatePicker.prototype, {
|
||||||
|
getFrameName : function getFrameName() {
|
||||||
|
var frameName
|
||||||
|
|
||||||
|
if(this.isNewspaper()){
|
||||||
|
frameName = "Newspaper"
|
||||||
|
} else if(this.isWallpaper()) {
|
||||||
|
frameName = "Wallpaper"
|
||||||
|
} else {
|
||||||
|
frameName = "Day"
|
||||||
|
}
|
||||||
|
|
||||||
|
return frameName
|
||||||
|
},
|
||||||
|
|
||||||
|
isNewspaper : function(){
|
||||||
|
return this.model.get("text").length > 300
|
||||||
|
},
|
||||||
|
|
||||||
|
isWallpaper : function(){
|
||||||
|
return this.model.get("photos").length == 1
|
||||||
|
}
|
||||||
|
});
|
||||||
44
spec/javascripts/app/models/post/template_picker_spec.js
Normal file
44
spec/javascripts/app/models/post/template_picker_spec.js
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
describe("app.models.Post.TemplatePicker", function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
this.post = factory.statusMessage({frame_name: undefined, text : "Lol this is a post"})
|
||||||
|
this.templatePicker = new app.models.Post.TemplatePicker(this.post)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("getFrameName", function(){
|
||||||
|
context("when the model has hella text", function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
this.post.set({text : window.hipsterIpsumFourParagraphs })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns Wallpaper", function(){
|
||||||
|
expect(this.templatePicker.getFrameName()).toBe("Newspaper")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
context("when the model has photos:", function(){
|
||||||
|
context("one photo", function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
this.post.set({photos : [factory.photoAttrs()]})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns Wallpaper", function(){
|
||||||
|
expect(this.templatePicker.getFrameName()).toBe("Wallpaper")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
context("two photos", function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
this.post.set({photos : [factory.photoAttrs(), factory.photoAttrs()]})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns Day", function(){
|
||||||
|
expect(this.templatePicker.getFrameName()).toBe("Day")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns 'Day' by default", function(){
|
||||||
|
expect(this.templatePicker.getFrameName()).toBe("Day")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -3,11 +3,6 @@ describe("app.pages.Composer", function(){
|
||||||
this.page = new app.pages.Composer()
|
this.page = new app.pages.Composer()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("stores a reference to the form as app.composer" , function(){
|
|
||||||
expect(this.page.model).toBeDefined()
|
|
||||||
expect(app.frame).toBe(this.page.model)
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("rendering", function(){
|
describe("rendering", function(){
|
||||||
beforeEach(function(){
|
beforeEach(function(){
|
||||||
this.page.render();
|
this.page.render();
|
||||||
|
|
@ -15,12 +10,12 @@ describe("app.pages.Composer", function(){
|
||||||
|
|
||||||
describe("clicking next", function(){
|
describe("clicking next", function(){
|
||||||
beforeEach(function(){
|
beforeEach(function(){
|
||||||
spyOn(app.router, "navigate")
|
this.navigateSpy = spyOn(app.router, "navigate")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("navigates to the framer", function(){
|
it("navigates to the framer", function(){
|
||||||
this.page.$("button.next").click()
|
this.page.$("button.next").click()
|
||||||
expect(app.router.navigate).toHaveBeenCalledWith("framer", true)
|
expect(this.navigateSpy).toHaveBeenCalledWith("framer", true)
|
||||||
});
|
});
|
||||||
|
|
||||||
describe(" setting the model's attributes from the various form fields", function(){
|
describe(" setting the model's attributes from the various form fields", function(){
|
||||||
|
|
@ -46,14 +41,19 @@ describe("app.pages.Composer", function(){
|
||||||
|
|
||||||
it("instantiates a post on form submit", function(){
|
it("instantiates a post on form submit", function(){
|
||||||
this.page.$("button.next").click()
|
this.page.$("button.next").click()
|
||||||
waitsFor(function(){ app.router.navigate.callCount > 1 })
|
waitsFor(function(){ return this.navigateSpy.wasCalled })
|
||||||
runs(function(){
|
runs(function(){
|
||||||
expect(this.page.model.get("aspect_ids")).toBe("public")
|
expect(this.page.model.get("aspect_ids")).toBe("public")
|
||||||
expect(this.page.model.get("services").length).toBe(2)
|
expect(this.page.model.get("services").length).toBe(2)
|
||||||
expect(this.page.model.get("text")).toBe("Oh My"))
|
expect(this.page.model.get("text")).toBe("Oh My")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("stores a reference to the form as app.composer" , function(){
|
||||||
|
expect(this.page.model).toBeDefined()
|
||||||
|
expect(app.frame).toBe(this.page.model)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -1,51 +1,29 @@
|
||||||
describe("app.views.TemplatePicker", function(){
|
describe("app.views.TemplatePicker", function(){
|
||||||
beforeEach(function(){
|
beforeEach(function(){
|
||||||
this.model = factory.statusMessage({frame_name: undefined})
|
this.model = factory.statusMessage({frame_name: undefined})
|
||||||
this.view = createView(this.model)
|
this.view = new app.views.TemplatePicker({model:this.model })
|
||||||
})
|
})
|
||||||
|
|
||||||
function createView(model){
|
|
||||||
return new app.views.TemplatePicker({model : model })
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("initialization", function(){
|
describe("initialization", function(){
|
||||||
context("when the model has photos:", function(){
|
it("calls setFrameName on the model", function(){
|
||||||
context("one photo", function(){
|
spyOn(this.model, 'setFrameName')
|
||||||
beforeEach(function(){
|
new app.views.TemplatePicker({model:this.model})
|
||||||
this.model.set({photos : [factory.photoAttrs()]})
|
expect(this.model.setFrameName).toHaveBeenCalled()
|
||||||
})
|
|
||||||
|
|
||||||
it("sets the frame name to Wallpaper", function(){
|
|
||||||
createView(this.model)
|
|
||||||
expect(this.model.get("frame_name")).toBe("Wallpaper")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
context("two photos", function(){
|
|
||||||
beforeEach(function(){
|
|
||||||
this.model.set({photos : [factory.photoAttrs(), factory.photoAttrs()]})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("sets the frame name to Wallpaper", function(){
|
|
||||||
createView(this.model)
|
|
||||||
expect(this.model.get("frame_name")).toBe("Day")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("sets the frame_name of the model to 'Day' by default", function(){
|
it("sets the frame_name of the model to 'Day' by default", function(){ //jasmine integration test, arguably unnecessary
|
||||||
createView(this.model)
|
|
||||||
expect(this.model.get("frame_name")).toBe("Day")
|
expect(this.model.get("frame_name")).toBe("Day")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("rendering", function(){
|
describe("rendering", function(){
|
||||||
beforeEach(function(){
|
beforeEach(function(){
|
||||||
|
this.model.set({frame_name : 'Wallpaper'})
|
||||||
this.view.render()
|
this.view.render()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("selects the model's frame_name from the dropdown", function(){
|
it("selects the model's frame_name from the dropdown", function(){
|
||||||
expect(this.view.$(".mood#selected_mood").data("mood")).toBe("Day")
|
expect(this.view.$(".mood#selected_mood").data("mood")).toBe("Wallpaper")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("changes the frame_name on the model when is is selected", function(){
|
it("changes the frame_name on the model when is is selected", function(){
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,33 @@ window.logout = function logout(){
|
||||||
return app.currentUser = new app.models.User()
|
return app.currentUser = new app.models.User()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.hipsterIpsumFourParagraphs = "Mcsweeney's mumblecore irony fugiat, ex iphone brunch helvetica eiusmod retro" +
|
||||||
|
" sustainable mlkshk. Pop-up gentrify velit readymade ad exercitation 3 wolf moon. Vinyl aute laboris artisan irony, " +
|
||||||
|
"farm-to-table beard. Messenger bag trust fund pork belly commodo tempor street art, nihil excepteur PBR lomo laboris." +
|
||||||
|
" Cosby sweater american apparel occupy, locavore odio put a bird on it fixie kale chips. Pariatur semiotics flexitarian " +
|
||||||
|
"veniam, irure freegan irony tempor. Consectetur sriracha pour-over vice, umami exercitation farm-to-table master " +
|
||||||
|
"cleanse art party." + "\n" +
|
||||||
|
|
||||||
|
"Quinoa nostrud street art helvetica et single-origin coffee, stumptown bushwick selvage skateboard enim godard " +
|
||||||
|
"before they sold out tumblr. Portland aesthetic freegan pork belly, truffaut occupy assumenda banksy 3 wolf moon " +
|
||||||
|
"irure forage terry richardson nulla. Anim nostrud selvage sartorial organic. Consequat pariatur aute fugiat qui, " +
|
||||||
|
"organic marfa sunt gluten-free mcsweeney's elit hella whatever wayfarers. Leggings pariatur chambray, ullamco " +
|
||||||
|
"flexitarian esse sed iphone pinterest messenger bag Austin cred DIY. Duis enim squid mcsweeney's, nisi lo-fi " +
|
||||||
|
"sapiente. Small batch vegan thundercats locavore williamsburg, non aesthetic trust fund put a bird on it gluten-free " +
|
||||||
|
"consectetur." + "\n" +
|
||||||
|
|
||||||
|
"Viral reprehenderit iphone sapiente exercitation. Enim nostrud letterpress, tempor typewriter dreamcatcher tattooed." +
|
||||||
|
" Ex godard pariatur voluptate est, polaroid hoodie ea nulla umami pickled tempor portland. Nostrud food truck" +
|
||||||
|
"single-origin coffee skateboard. Fap enim tumblr retro, nihil twee trust fund pinterest non jean shorts veniam " +
|
||||||
|
"fingerstache small batch. Cred whatever photo booth sed, et dolore gastropub duis freegan. Authentic quis butcher, " +
|
||||||
|
"fanny pack art party cupidatat readymade semiotics kogi consequat polaroid shoreditch ad four loko." + "\n" +
|
||||||
|
|
||||||
|
"PBR gluten-free ullamco exercitation narwhal in godard occaecat bespoke street art veniam aesthetic jean shorts " +
|
||||||
|
"mlkshk assumenda. Typewriter terry richardson pork belly, cupidatat tempor craft beer tofu sunt qui gentrify eiusmod " +
|
||||||
|
"id. Letterpress pitchfork wayfarers, eu sunt lomo helvetica pickled dreamcatcher bicycle rights. Aliqua banksy " +
|
||||||
|
"cliche, sapiente anim chambray williamsburg vinyl cardigan. Pork belly mcsweeney's anim aliqua. DIY vice portland " +
|
||||||
|
"thundercats est vegan etsy, gastropub helvetica aliqua. Artisan jean shorts american apparel duis esse trust fund."
|
||||||
|
|
||||||
spec.clearLiveEventBindings = function() {
|
spec.clearLiveEventBindings = function() {
|
||||||
var events = jQuery.data(document, "events");
|
var events = jQuery.data(document, "events");
|
||||||
for (prop in events) {
|
for (prop in events) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue