describe "Luca.View", -> Custom = Luca.View.extend clickHandler: sinon.spy() autoBindEventHandlers: true it "should be defined", -> expect(Luca.View).toBeDefined() it "should extend itself with the passed options", -> view = new Luca.View(name:"custom") expect(view.name).toEqual("custom") it "should create a unique id based on the name", -> view = new Luca.View(name:"boom") expect( view.cid ).toContain 'boom' it "should register the view in the cache", -> view = new Luca.View(name:"cached") expect( Luca.cache("cached") ).toBeDefined() it "should trigger after initialize", -> view = new Luca.View() expect( view ).toHaveTriggered("after:initialize") it "should auto-bind event handlers", -> # pending describe "Hooks", -> it "should have before and after render hooks", -> Custom = Luca.View.extend beforeRender: sinon.spy() afterRender: sinon.spy() view = new Custom() view.render() expect( view.beforeRender ).toHaveBeenCalled() expect( view.afterRender ).toHaveBeenCalled() it "should call custom hooks in addition to framework hooks", -> Custom = Luca.View.extend hooks:["custom:hook"] afterRender: ()-> @trigger("custom:hook") customHook: sinon.spy() view = new Custom() view.render() expect( view.customHook ).toHaveBeenCalled() describe "The Collection Events API", -> App = collections : {} App.collections.Sample = Luca.Collection.extend name: "sample" SampleView = Luca.View.extend resetHandler: sinon.spy() collectionEvents: "sample reset" : "resetHandler" class SampleManager extends Luca.CollectionManager collectionNamespace: App.collections name: "collectionEvents" beforeEach ()-> @manager ||= new SampleManager() @collection = @manager.getOrCreate("sample") it "should know which collection manager to use", -> view = new SampleView() expect( view.getCollectionManager().name ).toEqual( "collectionEvents" ) it "should create a reference to the collection", -> view = new SampleView() expect( view.sampleCollection ).toBeDefined() it "should call the resetHandler callback on the view", -> view = new SampleView() collection = @manager.get("sample") collection.reset([]) expect( view.resetHandler ).toHaveBeenCalled()