mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Added more tests to Marionette.js
This commit is contained in:
@@ -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 '<h1>Hello from my model</h1> <button class="destroy">Destroy Me</button>';
|
||||
return '<h1>' + this.model.getName() + '</h1> <button class="destroy">Destroy Me</button>';
|
||||
}
|
||||
};
|
||||
|
||||
@@ -151,7 +167,39 @@ module Marionette.Tests {
|
||||
}
|
||||
}
|
||||
|
||||
export var app : MyApplication;
|
||||
class MyCollectionView extends Marionette.CollectionView<MyModel> {
|
||||
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<MyModel> = new MyView(new MyModel());
|
||||
var myView: Marionette.View<MyModel> = 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"
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
Vendored
+4
-3
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user