From 02e28cc4b219a46490e0af79668a48e01d310713 Mon Sep 17 00:00:00 2001 From: Peter Palotas Date: Mon, 29 Dec 2014 11:10:56 +0100 Subject: [PATCH] Added more tests to Marionette.js --- marionette/marionette-tests.ts | 84 +++++++++++++++++++++++++++++++--- marionette/marionette.d.ts | 7 +-- 2 files changed, 82 insertions(+), 9 deletions(-) diff --git a/marionette/marionette-tests.ts b/marionette/marionette-tests.ts index d646062fe..109735d21 100644 --- a/marionette/marionette-tests.ts +++ b/marionette/marionette-tests.ts @@ -25,11 +25,27 @@ module Marionette.Tests { Marionette.Behaviors.getBehaviorClass = (options, key) => { if (key === "DestroyWarn") - return new DestroyWarn(); + return DestroyWarn; return undefined; }; + class MyRouter extends Marionette.AppRouter { + // "someMethod" must exist at controller.someMethod + appRoutes = { + "some/route": "someMethod" + }; + + /* standard routes can be mixed with appRoutes/Controllers above */ + routes = { + "some/otherRoute": "someOtherMethod" + }; + + someOtherMethod() { + // do something here. + } + + } class MyApplication extends Marionette.Application { initialize(options?: any) { @@ -95,7 +111,7 @@ module Marionette.Tests { } template() { - return '

Hello from my model

'; + return '

' + this.model.getName() + '

'; } }; @@ -151,7 +167,39 @@ module Marionette.Tests { } } - export var app : MyApplication; + class MyCollectionView extends Marionette.CollectionView { + constructor() { + this.childView = MyView; + this.childEvents = { + render: function () { + console.log("a childView has been rendered"); + } + }; + + this.childViewOptions = function (model, index) { + // do some calculations based on the model + return { + foo: "bar", + childIndex: index + } + }; + + this.childViewOptions = { + foo: "bar" + }; + + this.childViewEventPrefix = "some:prefix"; + + super(); + + this.on('some:prefix:render', function () { + + }); + + } + } + + export var app: MyApplication; function ApplicationTests() { app = new MyApplication(); @@ -195,16 +243,18 @@ module Marionette.Tests { } function RegionTests() { - var myView : Marionette.View = new MyView(new MyModel()); + var myView: Marionette.View = new MyView(new MyModel()); // render and display the view app.mainRegion.show(myView); // empties the current view app.mainRegion.empty(); + + myView = new MyView(new MyModel()); app.mainRegion.show(myView, { preventDestroy: true, forceShow: true, triggerAttach: true, triggerBeforeAttach: false }); - var hasView : boolean = app.mainRegion.hasView(); + var hasView: boolean = app.mainRegion.hasView(); app.mainRegion.reset(); @@ -225,5 +275,27 @@ module Marionette.Tests { }); } - + + function CollectionViewTests() { + var cv = new MyCollectionView(); + cv.collection.add(new MyModel()); + app.mainRegion.attachView(cv); + } + + class MyController extends Marionette.Controller { + + } + + function AppRouterTests() { + var myController = new MyController(); + var router = new MyRouter(); + + router.appRoute("/foo", "fooThat"); + + router.processAppRoutes(myController, { + "foo": "doFoo", + "bar/:id": "doBar" + }); + + } } \ No newline at end of file diff --git a/marionette/marionette.d.ts b/marionette/marionette.d.ts index 2e503955d..ac4dbea25 100644 --- a/marionette/marionette.d.ts +++ b/marionette/marionette.d.ts @@ -880,7 +880,7 @@ declare module Marionette { * The keys of the hash can either be a function or a string that is the * name of a method on the collection view. */ - childViewEvents: any; + childEvents: any; /** * When a collection has no children, and you need to render a view other than @@ -1341,9 +1341,10 @@ declare module Marionette { /** * This method has a default implementation that is simple to override. It * is responsible for the lookup of single behavior from within the - * Behaviors.behaviorsLookup or elsewhere. + * Behaviors.behaviorsLookup or elsewhere. Note that it should return the type of the + * class to instantiate, not an instance of that class. */ - static getBehaviorClass(options: any, key: string): Behavior; + static getBehaviorClass(options: any, key: string): any; } }