From cce035e0c3916fcc47667d6ec4e09948725299aa Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 19 Apr 2017 08:27:36 -0700 Subject: [PATCH] Remove more unnecessary namespaces in tests (#15978) --- .../angular-gettext/angular-gettext-tests.ts | 100 ++- .../angular-signalr-hub-tests.ts | 128 ++-- .../angular-spinner/angular-spinner-tests.ts | 12 +- .../animation-frame/animation-frame-tests.ts | 10 +- .../backbone-associations-tests.ts | 133 ++-- .../backbone.marionette-tests.ts | 553 ++++++++-------- .../backbone.paginator-tests.ts | 544 ++++++++-------- types/bardjs/bardjs-tests.ts | 544 ++++++++-------- types/handsontable/test/global.ts | 588 +++++++++--------- .../jquery-galleria/jquery-galleria-tests.ts | 27 +- types/lokijs/lokijs-tests.ts | 176 +++--- types/redlock/redlock-tests.ts | 60 +- types/yfiles/yfiles-tests.ts | 246 ++++---- 13 files changed, 1515 insertions(+), 1606 deletions(-) diff --git a/types/angular-gettext/angular-gettext-tests.ts b/types/angular-gettext/angular-gettext-tests.ts index d7c330c3eb..766b16a963 100644 --- a/types/angular-gettext/angular-gettext-tests.ts +++ b/types/angular-gettext/angular-gettext-tests.ts @@ -1,61 +1,55 @@ +// Configuring angular-gettext +// https://angular-gettext.rocketeer.be/dev-guide/configure/ +//Setting the language +angular.module('myApp').run(function (gettextCatalog: angular.gettext.gettextCatalog) { + gettextCatalog.setCurrentLanguage('nl'); +}); + +//Highlighting untranslated strings +angular.module('myApp').run(function (gettextCatalog: angular.gettext.gettextCatalog) { + gettextCatalog.debug = true; +}); -namespace angular_gettext_tests { +// Marking strings in JavaScript code as translatable. +// https://angular-gettext.rocketeer.be/dev-guide/annotate-js/ +angular.module("myApp").controller("helloController", function (gettext: angular.gettext.gettextFunction) { + var myString = gettext("Hello"); +}); +//Translating directly in JavaScript. +angular.module("myApp").controller("helloController", function (gettextCatalog: angular.gettext.gettextCatalog) { + var translated: string = gettextCatalog.getString("Hello"); +}); - // Configuring angular-gettext - // https://angular-gettext.rocketeer.be/dev-guide/configure/ - //Setting the language - angular.module('myApp').run(function (gettextCatalog: angular.gettext.gettextCatalog) { - gettextCatalog.setCurrentLanguage('nl'); - }); - - //Highlighting untranslated strings - angular.module('myApp').run(function (gettextCatalog: angular.gettext.gettextCatalog) { - gettextCatalog.debug = true; +angular.module("myApp").controller("helloController", function (gettextCatalog: angular.gettext.gettextCatalog) { + var myString2: string = gettextCatalog.getPlural(3, "Bird", "Birds"); +}); + +angular.module("myApp").controller("helloController", function (gettextCatalog: angular.gettext.gettextCatalog) { + var translated: string = gettextCatalog.getString("Hello {{name}}", { name: "Ruben" }); +}); + +// Setting strings manually +// https://angular-gettext.rocketeer.be/dev-guide/manual-setstrings/ + +angular.module("myApp").run(function (gettextCatalog: angular.gettext.gettextCatalog) { + // Load the strings automatically during initialization. + gettextCatalog.setStrings("nl", { + "Hello": "Hallo", + "One boat": ["Een boot", "{{$count}} boats"] }); +}); - // Marking strings in JavaScript code as translatable. - // https://angular-gettext.rocketeer.be/dev-guide/annotate-js/ - angular.module("myApp").controller("helloController", function (gettext: angular.gettext.gettextFunction) { - var myString = gettext("Hello"); - }); - - //Translating directly in JavaScript. - angular.module("myApp").controller("helloController", function (gettextCatalog: angular.gettext.gettextCatalog) { - var translated: string = gettextCatalog.getString("Hello"); - }); - - angular.module("myApp").controller("helloController", function (gettextCatalog: angular.gettext.gettextCatalog) { - var myString2: string = gettextCatalog.getPlural(3, "Bird", "Birds"); - }); - - angular.module("myApp").controller("helloController", function (gettextCatalog: angular.gettext.gettextCatalog) { - var translated: string = gettextCatalog.getString("Hello {{name}}", { name: "Ruben" }); - }); - - // Setting strings manually - // https://angular-gettext.rocketeer.be/dev-guide/manual-setstrings/ - - angular.module("myApp").run(function (gettextCatalog: angular.gettext.gettextCatalog) { - // Load the strings automatically during initialization. - gettextCatalog.setStrings("nl", { - "Hello": "Hallo", - "One boat": ["Een boot", "{{$count}} boats"] - }); - }); - - - interface helloControllerScope extends ng.IScope { - switchLanguage: (lang: string) => void; - } - // Lazy-loading languages - // https://angular-gettext.rocketeer.be/dev-guide/lazy-loading/ - angular.module("myApp").controller("helloController", function ($scope: helloControllerScope, gettextCatalog: angular.gettext.gettextCatalog) { - $scope.switchLanguage = function (lang: string) { - gettextCatalog.setCurrentLanguage(lang); - gettextCatalog.loadRemote("/languages/" + lang + ".json"); - }; - }); +interface helloControllerScope extends ng.IScope { + switchLanguage: (lang: string) => void; } +// Lazy-loading languages +// https://angular-gettext.rocketeer.be/dev-guide/lazy-loading/ +angular.module("myApp").controller("helloController", function ($scope: helloControllerScope, gettextCatalog: angular.gettext.gettextCatalog) { + $scope.switchLanguage = function (lang: string) { + gettextCatalog.setCurrentLanguage(lang); + gettextCatalog.loadRemote("/languages/" + lang + ".json"); + }; +}); diff --git a/types/angular-signalr-hub/angular-signalr-hub-tests.ts b/types/angular-signalr-hub/angular-signalr-hub-tests.ts index 771e49cdff..14d202e171 100644 --- a/types/angular-signalr-hub/angular-signalr-hub-tests.ts +++ b/types/angular-signalr-hub/angular-signalr-hub-tests.ts @@ -1,74 +1,72 @@ -angular - .module('app', ['SignalR']) - .factory('Employees', ngSignalrTest.EmployeesFactory); +class EmployeesFactory { + static $inject = ['$rootScope', 'Hub', '$timeout']; + private hub: ngSignalr.Hub; + public all: Array; -namespace ngSignalrTest { - export class EmployeesFactory { - static $inject = ['$rootScope', 'Hub', '$timeout']; - private hub: ngSignalr.Hub; - public all: Array; - - constructor($rootScope: ng.IRootScopeService, Hub: ngSignalr.HubFactory, $timeout: ng.ITimeoutService) { - // declaring the hub connection - this.hub = new Hub('employee', { - // client-side methods - listeners: { - 'lockEmployee': (id: number) => { - var employee = this.find(id); - employee.Locked = true; - $rootScope.$apply(); - }, - 'unlockEmployee': (id: number) => { - var employee = this.find(id); - employee.Locked = false; - $rootScope.$apply(); - } + constructor($rootScope: ng.IRootScopeService, Hub: ngSignalr.HubFactory, $timeout: ng.ITimeoutService) { + // declaring the hub connection + this.hub = new Hub('employee', { + // client-side methods + listeners: { + 'lockEmployee': (id: number) => { + var employee = this.find(id); + employee.Locked = true; + $rootScope.$apply(); }, - - // server-side methods - methods: ['lock', 'unlock'], - - // query params sent on initial connection - queryParams:{ - 'token': 'exampletoken' - }, - - // handle connection error - errorHandler: (message: string) => { - console.error(message); - }, - - stateChanged: (state: SignalR.StateChanged) => { - // your code here + 'unlockEmployee': (id: number) => { + var employee = this.find(id); + employee.Locked = false; + $rootScope.$apply(); } - }); - } + }, - private find(id: number) { - for (var i = 0; i < this.all.length; i++) { - if (this.all[i].Id === id) return this.all[i]; + // server-side methods + methods: ['lock', 'unlock'], + + // query params sent on initial connection + queryParams:{ + 'token': 'exampletoken' + }, + + // handle connection error + errorHandler: (message: string) => { + console.error(message); + }, + + stateChanged: (state: SignalR.StateChanged) => { + // your code here } - - return null; - } - - public edit = (employee: Employee) => { - employee.Edit = true; - this.hub.invoke('lock', employee.Id); - }; - - public done = (employee: Employee) => { - employee.Edit = false; - this.hub.invoke('unlock', employee.Id); - } + }); } - interface Employee { - Id: number; - Name: string; - Email: string; - Salary: number; - Edit: boolean; - Locked: boolean; + private find(id: number) { + for (var i = 0; i < this.all.length; i++) { + if (this.all[i].Id === id) return this.all[i]; + } + + return null; + } + + public edit = (employee: Employee) => { + employee.Edit = true; + this.hub.invoke('lock', employee.Id); + }; + + public done = (employee: Employee) => { + employee.Edit = false; + this.hub.invoke('unlock', employee.Id); } } + +interface Employee { + Id: number; + Name: string; + Email: string; + Salary: number; + Edit: boolean; + Locked: boolean; +} + +angular + .module('app', ['SignalR']) + .factory('Employees', EmployeesFactory); diff --git a/types/angular-spinner/angular-spinner-tests.ts b/types/angular-spinner/angular-spinner-tests.ts index c8d9e42479..82a47a40a4 100644 --- a/types/angular-spinner/angular-spinner-tests.ts +++ b/types/angular-spinner/angular-spinner-tests.ts @@ -2,11 +2,9 @@ var myApp = angular.module('testModule'); -namespace AngularSpinnerTest { - var app = angular.module("angularSpinnerTest", ["angular-spinner"]); +var app = angular.module("angularSpinnerTest", ["angular-spinner"]); - app.config(['usSpinnerService', function(usSpinnerService: ISpinnerService) { - usSpinnerService.spin('key1'); - usSpinnerService.stop('key2'); - }]); -} +app.config(['usSpinnerService', function(usSpinnerService: ISpinnerService) { + usSpinnerService.spin('key1'); + usSpinnerService.stop('key2'); +}]); diff --git a/types/animation-frame/animation-frame-tests.ts b/types/animation-frame/animation-frame-tests.ts index 2e0486f6ab..470f7e18ee 100644 --- a/types/animation-frame/animation-frame-tests.ts +++ b/types/animation-frame/animation-frame-tests.ts @@ -1,8 +1,6 @@ -namespace AnimationFrameTests { - var animation = new AnimationFrame(); - function frame() { - animation.request(frame); - } - +var animation = new AnimationFrame(); +function frame() { animation.request(frame); } + +animation.request(frame); diff --git a/types/backbone-associations/backbone-associations-tests.ts b/types/backbone-associations/backbone-associations-tests.ts index eebd48895d..411e1e5ec4 100644 --- a/types/backbone-associations/backbone-associations-tests.ts +++ b/types/backbone-associations/backbone-associations-tests.ts @@ -3,77 +3,72 @@ import * as Backbone from 'backbone'; -namespace BackboneAssociationsTests { - namespace OneToOne { - class EmployeeWithManager extends Backbone.AssociatedModel { - constructor(options?) { - super(options); - this.relations = [ - { - type: Backbone.One, //nature of the relationship - key: 'manager', // attribute of Employee - relatedModel: 'Employee' //AssociatedModel for attribute key - } - ]; +// one-to-one tests +class EmployeeWithManager extends Backbone.AssociatedModel { + constructor(options?) { + super(options); + this.relations = [ + { + type: Backbone.One, //nature of the relationship + key: 'manager', // attribute of Employee + relatedModel: 'Employee' //AssociatedModel for attribute key } - - defaults() { - return { - age: 0, - fname: "", - lname: "", - manager: null - }; - } - } + ]; } - namespace OneToMany { - class Location extends Backbone.AssociatedModel { - defaults() { - return { - add1: "", - add2: null, - zip: "", - state: "" - }; - } - } - - class Locations extends Backbone.Collection { - comparator = (c: Backbone.Model) => { - return c.get("Number"); - } - } - - class Project extends Backbone.AssociatedModel { - constructor(options?) { - super(options); - this.relations = [ - { - type: Backbone.Many, //nature of the relation - key: 'locations', //attribute of Project - collectionType: Locations, //Collection to be used. - relatedModel: Location //Optional - } - ]; - } - - defaults() { - return { - name: "", - number: 0, - locations: [] - } - } - } - - function reverseAssociationTest() { - var local = new Location({ state: "Hertfordshire" }); - var project = new Project({ name: "The Old Pond Project" }); - local.set("oddRelationTo", project); - var parents = project.parents; - } + defaults() { + return { + age: 0, + fname: "", + lname: "", + manager: null + }; } - +} + +// one-to-many tests +class Location extends Backbone.AssociatedModel { + defaults() { + return { + add1: "", + add2: null, + zip: "", + state: "" + }; + } +} + +class Locations extends Backbone.Collection { + comparator = (c: Backbone.Model) => { + return c.get("Number"); + } +} + +class Project extends Backbone.AssociatedModel { + constructor(options?) { + super(options); + this.relations = [ + { + type: Backbone.Many, //nature of the relation + key: 'locations', //attribute of Project + collectionType: Locations, //Collection to be used. + relatedModel: Location //Optional + } + ]; + } + + defaults() { + return { + name: "", + number: 0, + locations: [] + } + } +} + +function reverseAssociationTest() { + var local = new Location({ state: "Hertfordshire" }); + var project = new Project({ name: "The Old Pond Project" }); + local.set("oddRelationTo", project); + var parents = project.parents; } diff --git a/types/backbone.marionette/backbone.marionette-tests.ts b/types/backbone.marionette/backbone.marionette-tests.ts index 2c1f5b68bd..46f504e18e 100644 --- a/types/backbone.marionette/backbone.marionette-tests.ts +++ b/types/backbone.marionette/backbone.marionette-tests.ts @@ -1,322 +1,321 @@ import * as Marionette from 'backbone.marionette'; import * as Backbone from 'backbone'; -namespace MarionetteTests { - class DestroyWarn extends Marionette.Behavior { - // you can set default options - // just like you can in your Backbone Models - // they will be overriden if you pass in an option with the same key - defaults = { - "message": "you are destroying!" - }; - - // behaviors have events that are bound to the views DOM - events = { - "click @ui.destroy": "warnBeforeDestroy" - }; - - warnBeforeDestroy() { - alert(this.options.message); - // every Behavior has a hook into the - // view that it is attached to - this.view.destroy(); - } - } - - - Marionette.Behaviors.getBehaviorClass = (options, key) => { - if (key === "DestroyWarn") - return DestroyWarn; - - return undefined; +class DestroyWarn extends Marionette.Behavior { + // you can set default options + // just like you can in your Backbone Models + // they will be overriden if you pass in an option with the same key + defaults = { + "message": "you are destroying!" }; - 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) { - console.log("initializing application"); - this.layoutView = new AppLayoutView(); - } - - layoutView: AppLayoutView; - mainRegion: Marionette.Region; - - onStart() { - this.mainRegion = new Marionette.Region({ el: '#main' }); - this.layoutView.addRegion('main', this.mainRegion); - this.layoutView.render(); - this.layoutView.showChildView('main', new MyView(new MyModel)); - let view: Backbone.View = this.layoutView.getChildView('main'); - let regions: {[key: string]: Marionette.Region} = this.layoutView.getRegions(); - let prefix: string = this.layoutView.childViewEventPrefix; - let region: Marionette.Region = this.layoutView.removeRegion('main'); - let layout: Marionette.View = this.layoutView.destroy(); - } - } - - class AppLayoutView extends Marionette.View { - constructor() { - super({ el: 'body' }); - } - - template() { - return "
"; - } - - initialize(options?: any) { - console.log("initializing layoutview"); - } - } - - class MyModel extends Backbone.Model { - - constructor(options?: any) { - super(options); - } - - getName(): string { - return this.get('name'); - } - - setName(value: string) { - this.set(value); - } - } - - class MyBaseView extends Marionette.View { - - constructor() { - super(); - this.getOption('foo'); - this.triggers = { - 'click .foo': 'bar' - }; - } - - } - - class MyView extends Marionette.View { - behaviors: any; - - constructor(model: MyModel) { - super({ model: model }); - - this.ui = { - destroy: '.destroy' - }; - - this.behaviors = { - DestroyWarn: { - message: 'hello' - } - }; - } - - template() { - return '

' + this.model.getName() + '

'; - } + // behaviors have events that are bound to the views DOM + events = { + "click @ui.destroy": "warnBeforeDestroy" }; + warnBeforeDestroy() { + alert(this.options.message); + // every Behavior has a hook into the + // view that it is attached to + this.view.destroy(); + } +} - class MainRegion extends Marionette.Region { - constructor() { - super(); - this.el = '#main'; - } + +Marionette.Behaviors.getBehaviorClass = (options, key) => { + if (key === "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 MyObject extends Marionette.Object { - name: string; - options: any; - - constructor() { - super(); - this.name = 'Adam'; - - this.options = { - name: 'Foo' - }; - - this.on("before:destroy", () => { - console.log("before:destroy"); - }); - } - - onBeforeDestroy(arg: any) { - console.log("in onBeforeDestroy with arg " + arg); - } +class MyApplication extends Marionette.Application { + initialize(options?: any) { + console.log("initializing application"); + this.layoutView = new AppLayoutView(); } - class MyRegion extends Marionette.Region { - constructor() { - super(); - this.el = '#main-nav'; - } + layoutView: AppLayoutView; + mainRegion: Marionette.Region; + + onStart() { + this.mainRegion = new Marionette.Region({ el: '#main' }); + this.layoutView.addRegion('main', this.mainRegion); + this.layoutView.render(); + this.layoutView.showChildView('main', new MyView(new MyModel)); + let view: Backbone.View = this.layoutView.getChildView('main'); + let regions: {[key: string]: Marionette.Region} = this.layoutView.getRegions(); + let prefix: string = this.layoutView.childViewEventPrefix; + let region: Marionette.Region = this.layoutView.removeRegion('main'); + let layout: Marionette.View = this.layoutView.destroy(); + } +} + +class AppLayoutView extends Marionette.View { + constructor() { + super({ el: 'body' }); } - class MyJQueryRegion extends Marionette.Region { - constructor() { - super(); - this.el = $('#main-nav'); - } + template() { + return "
"; } - class MyHtmlElRegion extends Marionette.Region { - constructor() { - super(); - this.el = document.querySelector("body"); - } + initialize(options?: any) { + console.log("initializing layoutview"); + } +} + +class MyModel extends Backbone.Model { + + constructor(options?: any) { + super(options); } - class MyCollectionView extends Marionette.CollectionView { - constructor() { - super(); - this.childView = MyView; - this.childViewEvents = { - render: function () { - console.log("a childView has been rendered"); - } - }; - - this.childViewOptions = function (model: any, index: any): any { - // do some calculations based on the model - return { - foo: "bar", - childIndex: index - } - }; - - this.childViewOptions = { - foo: "bar" - }; - - this.childViewEventPrefix = "some:prefix"; - - this.on('some:prefix:render', function () { - - }); - - } + getName(): string { + return this.get('name'); } - export var app: MyApplication; + setName(value: string) { + this.set(value); + } +} - function ApplicationTests() { - app = new MyApplication(); +class MyBaseView extends Marionette.View { - app.start(); - - var view = new MyView(new MyModel()); - app.mainRegion.show(view); + constructor() { + super(); + this.getOption('foo'); + this.triggers = { + 'click .foo': 'bar' + }; } - function ObjectTests() { - var obj = new MyObject(); - console.log(obj.getOption('name')); - obj.destroy("goodbye"); - } +} - function RegionManagerTests() { - var rm = new Marionette.RegionManager(); - rm.addRegions({ - contentRegion: { - el: '#content', - regionClass: MainRegion - }, +class MyView extends Marionette.View { + behaviors: any; - navigationRegion: { - el: '#navigation', - regionClass: MainRegion, + constructor(model: MyModel) { + super({ model: model }); - // Options passed to instance of `MyOtherRegion` for - // the `navigationRegion` on `App` - navigationOption: 42, - anotherNavigationOption: 'foo' - }, + this.ui = { + destroy: '.destroy' + }; - footerRegion: { - regionClass: MainRegion, - someOption: 42, - someValue: 'value' + this.behaviors = { + DestroyWarn: { + message: 'hello' } + }; + } + + template() { + return '

' + this.model.getName() + '

'; + } +}; + + +class MainRegion extends Marionette.Region { + constructor() { + super(); + this.el = '#main'; + } +} + + +class MyObject extends Marionette.Object { + name: string; + options: any; + + constructor() { + super(); + this.name = 'Adam'; + + this.options = { + name: 'Foo' + }; + + this.on("before:destroy", () => { + console.log("before:destroy"); }); } - function RegionTests() { - 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(); - - app.mainRegion.reset(); - - Marionette.Region.prototype.attachHtml = function (view: any): void { - this.$el.empty().append(view.el); - } - - myView = new Marionette.View({ - el: $("#existing-view-stuff") - }); - - app.mainRegion.attachView(myView); - - app.mainRegion.on("empty", function (view: any, region: any, options: any) { - // manipulate the `view` or do something extra - // with the `region` - // you also have access to the `options` that were passed to the Region.show call - }); - + onBeforeDestroy(arg: any) { + console.log("in onBeforeDestroy with arg " + arg); } +} - function CollectionViewTests() { - var cv = new MyCollectionView(); - cv.collection.add(new MyModel()); - app.mainRegion.attachView(cv); - cv.addEmptyView(new MyModel, MyView); - cv.proxyChildEvents(new MyView(new MyModel)); - let children: Backbone.ChildViewContainer> = cv.destroyChildren(); - let view: Marionette.CollectionView> = cv.destroy(); +class MyRegion extends Marionette.Region { + constructor() { + super(); + this.el = '#main-nav'; } +} - class MyController extends Marionette.Controller { - +class MyJQueryRegion extends Marionette.Region { + constructor() { + super(); + this.el = $('#main-nav'); } +} - function AppRouterTests() { - var myController = new MyController(); - var router = new MyRouter(); +class MyHtmlElRegion extends Marionette.Region { + constructor() { + super(); + this.el = document.querySelector("body"); + } +} - router.appRoute("/foo", "fooThat"); +class MyCollectionView extends Marionette.CollectionView { + constructor() { + super(); + this.childView = MyView; + this.childViewEvents = { + render: function () { + console.log("a childView has been rendered"); + } + }; + + this.childViewOptions = function (model: any, index: any): any { + // do some calculations based on the model + return { + foo: "bar", + childIndex: index + } + }; + + this.childViewOptions = { + foo: "bar" + }; + + this.childViewEventPrefix = "some:prefix"; + + this.on('some:prefix:render', function () { - router.processAppRoutes(myController, { - "foo": "doFoo", - "bar/:id": "doBar" }); } } + +var app: MyApplication; + +function ApplicationTests() { + app = new MyApplication(); + + app.start(); + + var view = new MyView(new MyModel()); + app.mainRegion.show(view); +} + +function ObjectTests() { + var obj = new MyObject(); + console.log(obj.getOption('name')); + obj.destroy("goodbye"); +} + +function RegionManagerTests() { + var rm = new Marionette.RegionManager(); + rm.addRegions({ + contentRegion: { + el: '#content', + regionClass: MainRegion + }, + + navigationRegion: { + el: '#navigation', + regionClass: MainRegion, + + // Options passed to instance of `MyOtherRegion` for + // the `navigationRegion` on `App` + navigationOption: 42, + anotherNavigationOption: 'foo' + }, + + footerRegion: { + regionClass: MainRegion, + someOption: 42, + someValue: 'value' + } + }); +} + +function RegionTests() { + 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(); + + app.mainRegion.reset(); + + Marionette.Region.prototype.attachHtml = function (view: any): void { + this.$el.empty().append(view.el); + } + + myView = new Marionette.View({ + el: $("#existing-view-stuff") + }); + + app.mainRegion.attachView(myView); + + app.mainRegion.on("empty", function (view: any, region: any, options: any) { + // manipulate the `view` or do something extra + // with the `region` + // you also have access to the `options` that were passed to the Region.show call + }); + +} + +function CollectionViewTests() { + var cv = new MyCollectionView(); + cv.collection.add(new MyModel()); + app.mainRegion.attachView(cv); + cv.addEmptyView(new MyModel, MyView); + cv.proxyChildEvents(new MyView(new MyModel)); + let children: Backbone.ChildViewContainer> = cv.destroyChildren(); + let view: Marionette.CollectionView> = cv.destroy(); +} + +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" + }); + +} + diff --git a/types/backbone.paginator/backbone.paginator-tests.ts b/types/backbone.paginator/backbone.paginator-tests.ts index 28b09d4fc5..f4f5765988 100644 --- a/types/backbone.paginator/backbone.paginator-tests.ts +++ b/types/backbone.paginator/backbone.paginator-tests.ts @@ -1,306 +1,258 @@ /// - import * as Backbone from 'backbone'; -namespace BackbonePaginatorTests { +class TestModel extends Backbone.Model{}; - class TestModel extends Backbone.Model{}; - - var makeFetchOptions = >() => { - return { - reset: true, - url: 'example.com', - beforeSend: (jqxhr: JQueryXHR) => {}, - success: (model: TestModel, response: any, options: any) => {}, - error: (collection: TCol, jqxhr: JQueryXHR, options: any) => {}, - parse: '', - }; +var makeFetchOptions = >() => { + return { + reset: true, + url: 'example.com', + beforeSend: (jqxhr: JQueryXHR) => {}, + success: (model: TestModel, response: any, options: any) => {}, + error: (collection: TCol, jqxhr: JQueryXHR, options: any) => {}, + parse: '', }; +}; - - namespace InitializingWithNoOption { - - class TestCollection extends Backbone.PageableCollection { - constructor(){ - super(); - } +namespace InitializingWithNoOption { + class TestCollection extends Backbone.PageableCollection { + constructor(){ + super(); } - - var testCollection = new TestCollection(); - } - - - - namespace InitializingWithOptions { - - class TestCollection extends Backbone.PageableCollection { - - constructor(models?: TestModel[], - options?: Backbone.PageableInitialOptions){ - super(); - } - - } - - var testCollection1 = new TestCollection(); - - var testCollection2 = new TestCollection([ - new TestModel(), - new TestModel() - ]); - - var testCollection3 = new TestCollection([], {}); - - var testCollection4 = new TestCollection([],{ - comparator: ()=>1, - full: true, - state: {}, - queryParam: {}, - }); - - var testCollection5 = new TestCollection([],{ - state: { - firstPage: 0, - lastPage: 0, - currentPage: 0, - pageSize: 1, - totalPages: 1, - totalRecords: 1, - sortKey: 'id', - order: 1, - }, - queryParam: { - currentPage: 'current_page', - pageSize: 'page_size', - totalPages: 'total_pages', - totalRecords: 'total_records', - sortKey: 'sort_key', - order: 'order', - directions: '', - }, - }); - - var testCollection6 = new TestCollection([ - {}, - {}, - ]); - - } - - - - namespace Fetching { - - class TestCollection extends Backbone.PageableCollection { - constructor(models?: TestModel[], - options?: Backbone.PageableInitialOptions){ - super(); - } - } - - - var testCollection = new TestCollection(); - - var result:JQueryXHR = testCollection.fetch(); - - testCollection.fetch({}); - - testCollection.fetch(makeFetchOptions()); - - } - - - - namespace Paging { - - class TestCollection extends Backbone.PageableCollection { - constructor(models?: TestModel[], - options?: Backbone.PageableInitialOptions){ - super(); - } - } - - var options = makeFetchOptions(); - - var testCollection = new TestCollection(); - - - var result:JQueryXHR|TestCollection = testCollection.getFirstPage(); - - testCollection.getFirstPage(options); - - // 'silent's type is boolean. (structural subtyping) - testCollection.getFirstPage({silent: 'aa'}); - // 'url's type is string. (structural subtyping) - testCollection.getFirstPage({url: true}); - - - result = testCollection.getLastPage(); - - testCollection.getLastPage(options); - - // 'silent's type is boolean. (structural subtyping) - testCollection.getLastPage({silent: 'aa'}); - // 'url's type is string. (structural subtyping) - testCollection.getLastPage({url: true}); - - - result = testCollection.getNextPage(); - - testCollection.getNextPage(options); - - // 'silent's type is boolean. (structural subtyping) - testCollection.getNextPage({silent: 'aa'}); - // 'url's type is string. (structural subtyping) - testCollection.getNextPage({url: true}); - - - result = testCollection.getPage(1); - - testCollection.getPage("1", options); - - // 'silent's type is boolean. (structural subtyping) - testCollection.getPage(1, {silent: 'aa'}); - // 'url's type is string. (structural subtyping) - testCollection.getPage(1, {url: true}); - - - result = testCollection.getPageByOffset(1); - - testCollection.getPageByOffset(1, options); - - // 'silent's type is boolean. (structural subtyping) - testCollection.getPageByOffset(1, {silent: 'aa'}); - // 'url's type is string. (structural subtyping) - testCollection.getPageByOffset(1, {url: true}); - - - result = testCollection.getPreviousPage(); - - testCollection.getPreviousPage(options); - - // 'silent's type is boolean. (structural subtyping) - testCollection.getPreviousPage({silent: 'aa'}); - // 'url's type is string. (structural subtyping) - testCollection.getPreviousPage({url: true}); - - - var hasPage:boolean = testCollection.hasNextPage(); - - hasPage = testCollection.hasPreviousPage(); - - } - - - - - namespace Parse { - - class TestCollection extends Backbone.PageableCollection { - constructor(models?: TestModel[], - options?: Backbone.PageableInitialOptions){ - super(); - } - } - - var testCollection = new TestCollection(); - - var result:any[] = testCollection.parse({}, {}); - - - var resultLinks:any = testCollection.parseLinks({}, {}); - - resultLinks = testCollection.parseLinks({}, { xhr: $.ajax({}) } ); - - - result = testCollection.parseRecords({}, {}); - - - var resultState: Backbone.PageableState = testCollection.parseState( - {}, - { - currentPage: 'current_page', - pageSize: 'page_size', - totalPages: 'total_pages', - totalRecords: 'total_records', - sortKey: 'sort_key', - order: 'order', - directions: '', - }, - { - firstPage: 0, - lastPage: 0, - currentPage: 0, - pageSize: 1, - totalPages: 1, - totalRecords: 1, - sortKey: 'id', - order: 1, - }, - {}); - - } - - - - namespace Setting { - - class TestCollection extends Backbone.PageableCollection { - constructor(models?: TestModel[], - options?: Backbone.PageableInitialOptions){ - super(); - } - } - - var testCollection = new TestCollection(); - - var options = makeFetchOptions(); - - - var result1:JQueryXHR|TestCollection - = testCollection.setPageSize(1, options); - - - var result2:TestCollection - = testCollection.setSorting('id', 1, options); - - - result1 = testCollection.switchMode( - 'server', - {fetch: true, resetState: true} - ); - - } - - - - namespace Syncing { - - class TestCollection extends Backbone.PageableCollection { - constructor(models?: TestModel[], - options?: Backbone.PageableInitialOptions){ - super(); - } - } - - var testCollection = new TestCollection(); - - - var result:JQueryXHR = testCollection.sync('server', new TestModel(), {}); - - result = testCollection.sync('server', testCollection, {}); - - } - - - - namespace Confllict { - - var result:typeof Backbone.PageableCollection - = Backbone.PageableCollection.noConflict(); - - } - + var testCollection = new TestCollection(); +} + +namespace InitializingWithOptions { + class TestCollection extends Backbone.PageableCollection { + constructor(models?: TestModel[], options?: Backbone.PageableInitialOptions){ + super(); + } + } + + var testCollection1 = new TestCollection(); + + var testCollection2 = new TestCollection([ + new TestModel(), + new TestModel() + ]); + + var testCollection3 = new TestCollection([], {}); + + var testCollection4 = new TestCollection([],{ + comparator: ()=>1, + full: true, + state: {}, + queryParam: {}, + }); + + var testCollection5 = new TestCollection([],{ + state: { + firstPage: 0, + lastPage: 0, + currentPage: 0, + pageSize: 1, + totalPages: 1, + totalRecords: 1, + sortKey: 'id', + order: 1, + }, + queryParam: { + currentPage: 'current_page', + pageSize: 'page_size', + totalPages: 'total_pages', + totalRecords: 'total_records', + sortKey: 'sort_key', + order: 'order', + directions: '', + }, + }); + + var testCollection6 = new TestCollection([ + {}, + {}, + ]); +} + +namespace Fetching { + class TestCollection extends Backbone.PageableCollection { + constructor(models?: TestModel[], options?: Backbone.PageableInitialOptions){ + super(); + } + } + + var testCollection = new TestCollection(); + + var result:JQueryXHR = testCollection.fetch(); + + testCollection.fetch({}); + + testCollection.fetch(makeFetchOptions()); +} + +namespace Paging { + class TestCollection extends Backbone.PageableCollection { + constructor(models?: TestModel[], options?: Backbone.PageableInitialOptions){ + super(); + } + } + + var options = makeFetchOptions(); + + var testCollection = new TestCollection(); + + + var result:JQueryXHR|TestCollection = testCollection.getFirstPage(); + + testCollection.getFirstPage(options); + + // 'silent's type is boolean. (structural subtyping) + testCollection.getFirstPage({silent: 'aa'}); + // 'url's type is string. (structural subtyping) + testCollection.getFirstPage({url: true}); + + + result = testCollection.getLastPage(); + + testCollection.getLastPage(options); + + // 'silent's type is boolean. (structural subtyping) + testCollection.getLastPage({silent: 'aa'}); + // 'url's type is string. (structural subtyping) + testCollection.getLastPage({url: true}); + + + result = testCollection.getNextPage(); + + testCollection.getNextPage(options); + + // 'silent's type is boolean. (structural subtyping) + testCollection.getNextPage({silent: 'aa'}); + // 'url's type is string. (structural subtyping) + testCollection.getNextPage({url: true}); + + + result = testCollection.getPage(1); + + testCollection.getPage("1", options); + + // 'silent's type is boolean. (structural subtyping) + testCollection.getPage(1, {silent: 'aa'}); + // 'url's type is string. (structural subtyping) + testCollection.getPage(1, {url: true}); + + + result = testCollection.getPageByOffset(1); + + testCollection.getPageByOffset(1, options); + + // 'silent's type is boolean. (structural subtyping) + testCollection.getPageByOffset(1, {silent: 'aa'}); + // 'url's type is string. (structural subtyping) + testCollection.getPageByOffset(1, {url: true}); + + + result = testCollection.getPreviousPage(); + + testCollection.getPreviousPage(options); + + // 'silent's type is boolean. (structural subtyping) + testCollection.getPreviousPage({silent: 'aa'}); + // 'url's type is string. (structural subtyping) + testCollection.getPreviousPage({url: true}); + + + var hasPage:boolean = testCollection.hasNextPage(); + + hasPage = testCollection.hasPreviousPage(); +} + + + + +namespace Parse { + class TestCollection extends Backbone.PageableCollection { + constructor(models?: TestModel[], + options?: Backbone.PageableInitialOptions){ + super(); + } + } + + var testCollection = new TestCollection(); + + var result:any[] = testCollection.parse({}, {}); + + + var resultLinks:any = testCollection.parseLinks({}, {}); + + resultLinks = testCollection.parseLinks({}, { xhr: $.ajax({}) } ); + + + result = testCollection.parseRecords({}, {}); + + var resultState: Backbone.PageableState = testCollection.parseState( + {}, + { + currentPage: 'current_page', + pageSize: 'page_size', + totalPages: 'total_pages', + totalRecords: 'total_records', + sortKey: 'sort_key', + order: 'order', + directions: '', + }, + { + firstPage: 0, + lastPage: 0, + currentPage: 0, + pageSize: 1, + totalPages: 1, + totalRecords: 1, + sortKey: 'id', + order: 1, + }, + {}); +} + +namespace Setting { + class TestCollection extends Backbone.PageableCollection { + constructor(models?: TestModel[], options?: Backbone.PageableInitialOptions){ + super(); + } + } + + var testCollection = new TestCollection(); + + var options = makeFetchOptions(); + + var result1:JQueryXHR|TestCollection + = testCollection.setPageSize(1, options); + + + var result2:TestCollection + = testCollection.setSorting('id', 1, options); + + result1 = testCollection.switchMode( + 'server', + {fetch: true, resetState: true} + ); +} + +namespace Syncing { + class TestCollection extends Backbone.PageableCollection { + constructor(models?: TestModel[], options?: Backbone.PageableInitialOptions){ + super(); + } + } + + var testCollection = new TestCollection(); + + var result:JQueryXHR = testCollection.sync('server', new TestModel(), {}); + + result = testCollection.sync('server', testCollection, {}); +} + +namespace Confllict { + var result: typeof Backbone.PageableCollection = Backbone.PageableCollection.noConflict(); } diff --git a/types/bardjs/bardjs-tests.ts b/types/bardjs/bardjs-tests.ts index 91172b7255..52f5ab1d3f 100644 --- a/types/bardjs/bardjs-tests.ts +++ b/types/bardjs/bardjs-tests.ts @@ -1,281 +1,279 @@ import * as angular from 'angular'; import 'angular-mocks'; -namespace bardTests { - var expect = chai.expect, - assert = chai.assert; +var expect = chai.expect, + assert = chai.assert; - class MyService { - constructor(private $q: angular.IQService) {} +class MyService { + constructor(private $q: angular.IQService) {} - remoteCall(): angular.IPromise { - return new this.$q((resolve, reject) => { - resolve(['Hello', 'World']); - }); - } - } - - function myService($q: angular.IQService) { - return new MyService($q); - } - namespace myService { - export var $inject = ['$q']; - } - - class MyController { - myProperty: string; - } - - angular - .module('myModule') - .service('myService', myService) - .controller('MyController', MyController); - - /* - * bard.$httpBackend - */ - function test_$httpBackend() { - var myService: MyService; - var $rootScope: angular.IRootScopeService; - - beforeEach(angular.mock.module(bard.$httpBackend, 'myModule')); - - beforeEach(inject(function(_myService_: MyService, _$rootScope_: angular.IRootScopeService) { - myService = _myService_; - $rootScope = _$rootScope_; - })); - - it('should return valid data', function(done) { - myService.remoteCall() - .then(function(data) { - expect(data).to.exist; - }) - .then(done, done); - - $rootScope.$apply; // Because not using bard.$q, must flush the $http and $q queues + remoteCall(): angular.IPromise { + return new this.$q((resolve, reject) => { + resolve(['Hello', 'World']); }); } - - /* - * bard.$q - */ - function test_$q() { - var myService: MyService; - - beforeEach(angular.mock.module(bard.$q, bard.$httpBackend, 'myModule')); - - beforeEach(inject(function(_myService_: MyService) { - myService = _myService_; - })); - - it('should return valid data', (done) => { - myService.remoteCall() - .then((data) => { - expect(data).to.exist; - }) - .then(done, done); - - // No need to flush - }); - } - - /* - * bard.addGlobals - */ - function test_addGlobals() { - describe('someting', function() { - var ctx = this; - - it('should work', function() { - var bar = 'bar'; - bard.addGlobals(this, 'foo'); // where `this` is the spec context - bard.addGlobals(this, 'foo', bar); - bard.addGlobals.bind(this)('foo', 'bar'); - bard.addGlobals(ctx, ['foo', 'bar']) // where ctx is the spec context - }); - }) - } - - /* - * bard.appModule - */ - function test_appModule() { - beforeEach(bard.appModule('myModule')); - //// - beforeEach(bard.appModule('myModule', function() {}, {})); - } - - /* - * bard.assertFail - */ - function test_assertFail() { - bard.assertFail('FAIL!'); - } - - /* - * bard.asyncModule - */ - function test_asyncModule() { - beforeEach(bard.asyncModule('myModule')); - //// - beforeEach(bard.asyncModule('myModule', function() {}, {})); - } - - /* - * bard.debugging - */ - function test_debugging() { - console.log( - bard.debugging(true), // should return true - bard.debugging(false), // should return false - bard.debugging(42), // should return true - bard.debugging(''), // should return false - bard.debugging() // should return false - ); - } - - /* - * bard.fakeLogger - */ - function test_fakeLogger() { - beforeEach(angular.mock.module('myModule', bard.fakeLogger)); - //// - beforeEach(bard.appModule('myModule', bard.fakeLogger)); - //// - beforeEach(bard.asyncModule('myModule', bard.fakeLogger)); - } - - /* - * bard.fakeRouteHelperProvider - */ - function test_fakeRouteHelperProvider() { - beforeEach(angular.mock.module('myModule', bard.fakeRouteHelperProvider)); - //// - beforeEach(bard.appModule('myModule', bard.fakeRouteHelperProvider)); - //// - beforeEach(bard.asyncModule('myModule', bard.fakeRouteHelperProvider)); - } - - /* - * bard.fakeRouteProvider - */ - function test_fakeRouteProvider() { - beforeEach(angular.mock.module('myModule', bard.fakeRouteProvider)); - //// - beforeEach(bard.appModule('myModule', bard.fakeRouteProvider)); - //// - beforeEach(bard.asyncModule('myModule', bard.fakeRouteProvider)); - } - - /* - * bard.fakeStateProvider - */ - function test_fakeStateProvider() { - beforeEach(angular.mock.module('myModule', bard.fakeStateProvider)); - //// - beforeEach(bard.appModule('myModule', bard.fakeStateProvider)); - //// - beforeEach(bard.asyncModule('myModule', bard.fakeStateProvider)); - } - - /* - * bard.fakeToastr - */ - function test_fakeToastr() { - beforeEach(angular.mock.module('myModule', bard.fakeToastr)); - //// - beforeEach(bard.appModule('myModule', bard.fakeToastr)); - //// - beforeEach(bard.asyncModule('myModule', bard.fakeToastr)); - } - - /* - * bard.inject - */ - function test_inject() { - beforeEach(() => bard.inject(this, '$controller', '$log', '$q', '$rootScope', 'myService')); - } - - /* - * bard.log - */ - function test_log() { - bard.log('We got the goods'); - } - - /* - * bard.mochaRunnerListener - */ - function test_mochaRunnerListener() { - var runner = mocha.run(); - bard.mochaRunnerListener(runner); - } - - /* - * bard.mockService - */ - function test_mockService() { - var controller: MyController, - myArray = ['This', 'is', 'some', 'mocked', 'data']; - var $controller: angular.IControllerService, - $q: angular.IQService, - $rootScope: angular.IRootScopeService, - myService: MyService; - - beforeEach(function() { - bard.appModule('myModule'); - bard.inject(this, '$controller', '$q', '$rootScope', 'myService'); - - bard.mockService(myService, { - remoteCall: $q.when(myArray), - _default: $q.when([]) - }); - - controller = $controller('MyController'); - $rootScope.$apply(); - }); - } - - /* - * bard.replaceAccentChars - */ - function test_replaceAccentChars() { - console.log(bard.replaceAccentChars('àáâãäåèéêëìíîïòóôõöùúûüýÿ') === 'aaaaaaeeeeeeeeooooouuuuyy'); - } - - /* - * bard.verifyNoOutstandingHttpRequests - */ - function test_verifyNoOutstandingHttpRequests() { - var controller: MyController, - myArray = ['This', 'is', 'some', 'mocked', 'data']; - var $controller: angular.IControllerService, - $q: angular.IQService, - $rootScope: angular.IRootScopeService, - myService: MyService; - - beforeEach(function() { - bard.appModule('myModule'); - bard.inject(this, '$controller', '$q', '$rootScope', 'myService'); - - bard.mockService(myService, { - remoteCall: $q.when(myArray), - _default: $q.when([]) - }); - - controller = $controller('MyController'); - $rootScope.$apply(); - }); - - bard.verifyNoOutstandingHttpRequests(); - } - - /* - * bard.wrapWithDone - */ - function test_wrapWithDone() { - function callback() { console.log('Doing something...'); } - function done() { console.log('...Done'); } - bard.wrapWithDone(callback, done); - } +} + +function myService($q: angular.IQService) { + return new MyService($q); +} +namespace myService { + export var $inject = ['$q']; +} + +class MyController { + myProperty: string; +} + +angular + .module('myModule') + .service('myService', myService) + .controller('MyController', MyController); + +/* + * bard.$httpBackend + */ +function test_$httpBackend() { + var myService: MyService; + var $rootScope: angular.IRootScopeService; + + beforeEach(angular.mock.module(bard.$httpBackend, 'myModule')); + + beforeEach(inject(function(_myService_: MyService, _$rootScope_: angular.IRootScopeService) { + myService = _myService_; + $rootScope = _$rootScope_; + })); + + it('should return valid data', function(done) { + myService.remoteCall() + .then(function(data) { + expect(data).to.exist; + }) + .then(done, done); + + $rootScope.$apply; // Because not using bard.$q, must flush the $http and $q queues + }); +} + +/* + * bard.$q + */ +function test_$q() { + var myService: MyService; + + beforeEach(angular.mock.module(bard.$q, bard.$httpBackend, 'myModule')); + + beforeEach(inject(function(_myService_: MyService) { + myService = _myService_; + })); + + it('should return valid data', (done) => { + myService.remoteCall() + .then((data) => { + expect(data).to.exist; + }) + .then(done, done); + + // No need to flush + }); +} + +/* + * bard.addGlobals + */ +function test_addGlobals() { + describe('someting', function() { + var ctx = this; + + it('should work', function() { + var bar = 'bar'; + bard.addGlobals(this, 'foo'); // where `this` is the spec context + bard.addGlobals(this, 'foo', bar); + bard.addGlobals.bind(this)('foo', 'bar'); + bard.addGlobals(ctx, ['foo', 'bar']) // where ctx is the spec context + }); + }) +} + +/* + * bard.appModule + */ +function test_appModule() { + beforeEach(bard.appModule('myModule')); + //// + beforeEach(bard.appModule('myModule', function() {}, {})); +} + +/* + * bard.assertFail + */ +function test_assertFail() { + bard.assertFail('FAIL!'); +} + +/* + * bard.asyncModule + */ +function test_asyncModule() { + beforeEach(bard.asyncModule('myModule')); + //// + beforeEach(bard.asyncModule('myModule', function() {}, {})); +} + +/* + * bard.debugging + */ +function test_debugging() { + console.log( + bard.debugging(true), // should return true + bard.debugging(false), // should return false + bard.debugging(42), // should return true + bard.debugging(''), // should return false + bard.debugging() // should return false + ); +} + +/* + * bard.fakeLogger + */ +function test_fakeLogger() { + beforeEach(angular.mock.module('myModule', bard.fakeLogger)); + //// + beforeEach(bard.appModule('myModule', bard.fakeLogger)); + //// + beforeEach(bard.asyncModule('myModule', bard.fakeLogger)); +} + +/* + * bard.fakeRouteHelperProvider + */ +function test_fakeRouteHelperProvider() { + beforeEach(angular.mock.module('myModule', bard.fakeRouteHelperProvider)); + //// + beforeEach(bard.appModule('myModule', bard.fakeRouteHelperProvider)); + //// + beforeEach(bard.asyncModule('myModule', bard.fakeRouteHelperProvider)); +} + +/* + * bard.fakeRouteProvider + */ +function test_fakeRouteProvider() { + beforeEach(angular.mock.module('myModule', bard.fakeRouteProvider)); + //// + beforeEach(bard.appModule('myModule', bard.fakeRouteProvider)); + //// + beforeEach(bard.asyncModule('myModule', bard.fakeRouteProvider)); +} + +/* + * bard.fakeStateProvider + */ +function test_fakeStateProvider() { + beforeEach(angular.mock.module('myModule', bard.fakeStateProvider)); + //// + beforeEach(bard.appModule('myModule', bard.fakeStateProvider)); + //// + beforeEach(bard.asyncModule('myModule', bard.fakeStateProvider)); +} + +/* + * bard.fakeToastr + */ +function test_fakeToastr() { + beforeEach(angular.mock.module('myModule', bard.fakeToastr)); + //// + beforeEach(bard.appModule('myModule', bard.fakeToastr)); + //// + beforeEach(bard.asyncModule('myModule', bard.fakeToastr)); +} + +/* + * bard.inject + */ +function test_inject() { + beforeEach(() => bard.inject(this, '$controller', '$log', '$q', '$rootScope', 'myService')); +} + +/* + * bard.log + */ +function test_log() { + bard.log('We got the goods'); +} + +/* + * bard.mochaRunnerListener + */ +function test_mochaRunnerListener() { + var runner = mocha.run(); + bard.mochaRunnerListener(runner); +} + +/* + * bard.mockService + */ +function test_mockService() { + var controller: MyController, + myArray = ['This', 'is', 'some', 'mocked', 'data']; + var $controller: angular.IControllerService, + $q: angular.IQService, + $rootScope: angular.IRootScopeService, + myService: MyService; + + beforeEach(function() { + bard.appModule('myModule'); + bard.inject(this, '$controller', '$q', '$rootScope', 'myService'); + + bard.mockService(myService, { + remoteCall: $q.when(myArray), + _default: $q.when([]) + }); + + controller = $controller('MyController'); + $rootScope.$apply(); + }); +} + +/* + * bard.replaceAccentChars + */ +function test_replaceAccentChars() { + console.log(bard.replaceAccentChars('àáâãäåèéêëìíîïòóôõöùúûüýÿ') === 'aaaaaaeeeeeeeeooooouuuuyy'); +} + +/* + * bard.verifyNoOutstandingHttpRequests + */ +function test_verifyNoOutstandingHttpRequests() { + var controller: MyController, + myArray = ['This', 'is', 'some', 'mocked', 'data']; + var $controller: angular.IControllerService, + $q: angular.IQService, + $rootScope: angular.IRootScopeService, + myService: MyService; + + beforeEach(function() { + bard.appModule('myModule'); + bard.inject(this, '$controller', '$q', '$rootScope', 'myService'); + + bard.mockService(myService, { + remoteCall: $q.when(myArray), + _default: $q.when([]) + }); + + controller = $controller('MyController'); + $rootScope.$apply(); + }); + + bard.verifyNoOutstandingHttpRequests(); +} + +/* + * bard.wrapWithDone + */ +function test_wrapWithDone() { + function callback() { console.log('Doing something...'); } + function done() { console.log('...Done'); } + bard.wrapWithDone(callback, done); } diff --git a/types/handsontable/test/global.ts b/types/handsontable/test/global.ts index d5134f0fa0..d4516d80e1 100644 --- a/types/handsontable/test/global.ts +++ b/types/handsontable/test/global.ts @@ -1,301 +1,299 @@ -namespace HandsontableGlobalTest { - function test_HandsontableInit() { - const elem = document.createElement('div'); - const hot = new Handsontable(elem, { - allowEmpty: true, - allowInsertColumn: true, - allowInsertRow: true, - allowInvalid: true, - allowRemoveColumn: true, - allowRemoveRow: true, - autoColumnSize: true, - autoComplete: [], - autoRowSize: true, - autoWrapCol: true, - autoWrapRow: true, - bindRowsWithHeaders: 'foo', - cell: [], - cells: () => { return; }, - checkedTemplate: true, - className: [], - colHeaders: true, - collapsibleColumns: true, - columnHeaderHeight: 123, - columns: [], - columnSorting: {}, - columnSummary: {}, - colWidths: 123, - commentedCellClassName: 'foo', - comments: [], - contextMenu: true, - contextMenuCopyPaste: {}, - copyable: true, - copyColsLimit: 123, - copyPaste: true, - copyRowsLimit: 123, - correctFormat: true, - currentColClassName: 'foo', - currentRowClassName: 'foo', - customBorders: true, - data: [], - dataSchema: {}, - dateFormat: 'foo', - debug: true, - defaultDate: 'foo', - disableVisualSelection: true, - dropdownMenu: [], - editor: true, - enterBeginsEditing: true, - enterMoves: {}, - fillHandle: true, - filter: true, - filteringCaseSensitive: true, - filters: false, - fixedColumnsLeft: 123, - fixedRowsBottom: 123, - fixedRowsTop: 123, - format: 'foo', - fragmentSelection: true, - ganttChart: {}, - headerTooltips: true, - height: 123, - hiddenColumns: true, - hiddenRows: {}, - invalidCellClassName: 'foo', - label: {}, - language: 'foo', - manualColumnFreeze: true, - manualColumnMove: true, - manualColumnResize: true, - manualRowMove: true, - manualRowResize: true, - maxCols: 123, - maxRows: 123, - mergeCells: true, - minCols: 123, - minRows: 123, - minSpareCols: 123, - minSpareRows: 123, - multiSelect: true, - nestedHeaders: [], - noWordWrapClassName: 'foo', - observeChanges: true, - observeDOMVisibility: true, - outsideClickDeselects: true, - pasteMode: 'foo', - persistentState: true, - placeholder: 123, - placeholderCellClassName: 'foo', - preventOverflow: true, - readOnly: true, - readOnlyCellClassName: 'foo', - renderAllRows: true, - renderer: 'foo', - rowHeaders: true, - rowHeaderWidth: 123, - rowHeights: 123, - search: true, - selectOptions: [], - skipColumnOnPaste: true, - sortByRelevance: true, - sortFunction: () => { return; }, - sortIndicator: true, - source: [], - startCols: 123, - startRows: 123, - stretchH: 'foo', - strict: true, - tableClassName: 'foo', - tabMoves: {}, - title: 'foo', - trimDropdown: true, - trimWhitespace: true, - type: 'foo', - uncheckedTemplate: true, - undo: true, - validator: () => {return; }, - viewportColumnRenderingOffset: 123, - viewportRowRenderingOffset: 123, - visibleRows: 123, - width: 1232, - wordWrap: true, +function test_HandsontableInit() { + const elem = document.createElement('div'); + const hot = new Handsontable(elem, { + allowEmpty: true, + allowInsertColumn: true, + allowInsertRow: true, + allowInvalid: true, + allowRemoveColumn: true, + allowRemoveRow: true, + autoColumnSize: true, + autoComplete: [], + autoRowSize: true, + autoWrapCol: true, + autoWrapRow: true, + bindRowsWithHeaders: 'foo', + cell: [], + cells: () => { return; }, + checkedTemplate: true, + className: [], + colHeaders: true, + collapsibleColumns: true, + columnHeaderHeight: 123, + columns: [], + columnSorting: {}, + columnSummary: {}, + colWidths: 123, + commentedCellClassName: 'foo', + comments: [], + contextMenu: true, + contextMenuCopyPaste: {}, + copyable: true, + copyColsLimit: 123, + copyPaste: true, + copyRowsLimit: 123, + correctFormat: true, + currentColClassName: 'foo', + currentRowClassName: 'foo', + customBorders: true, + data: [], + dataSchema: {}, + dateFormat: 'foo', + debug: true, + defaultDate: 'foo', + disableVisualSelection: true, + dropdownMenu: [], + editor: true, + enterBeginsEditing: true, + enterMoves: {}, + fillHandle: true, + filter: true, + filteringCaseSensitive: true, + filters: false, + fixedColumnsLeft: 123, + fixedRowsBottom: 123, + fixedRowsTop: 123, + format: 'foo', + fragmentSelection: true, + ganttChart: {}, + headerTooltips: true, + height: 123, + hiddenColumns: true, + hiddenRows: {}, + invalidCellClassName: 'foo', + label: {}, + language: 'foo', + manualColumnFreeze: true, + manualColumnMove: true, + manualColumnResize: true, + manualRowMove: true, + manualRowResize: true, + maxCols: 123, + maxRows: 123, + mergeCells: true, + minCols: 123, + minRows: 123, + minSpareCols: 123, + minSpareRows: 123, + multiSelect: true, + nestedHeaders: [], + noWordWrapClassName: 'foo', + observeChanges: true, + observeDOMVisibility: true, + outsideClickDeselects: true, + pasteMode: 'foo', + persistentState: true, + placeholder: 123, + placeholderCellClassName: 'foo', + preventOverflow: true, + readOnly: true, + readOnlyCellClassName: 'foo', + renderAllRows: true, + renderer: 'foo', + rowHeaders: true, + rowHeaderWidth: 123, + rowHeights: 123, + search: true, + selectOptions: [], + skipColumnOnPaste: true, + sortByRelevance: true, + sortFunction: () => { return; }, + sortIndicator: true, + source: [], + startCols: 123, + startRows: 123, + stretchH: 'foo', + strict: true, + tableClassName: 'foo', + tabMoves: {}, + title: 'foo', + trimDropdown: true, + trimWhitespace: true, + type: 'foo', + uncheckedTemplate: true, + undo: true, + validator: () => {return; }, + viewportColumnRenderingOffset: 123, + viewportRowRenderingOffset: 123, + visibleRows: 123, + width: 1232, + wordWrap: true, - // Hooks - afterAutofillApplyValues: () => {return; }, - afterCellMetaReset: () => {return; }, - afterChange: () => {return; }, - afterChangesObserved: () => {return; }, - afterColumnMove: () => {return; }, - afterColumnResize: () => {return; }, - afterColumnSort: () => {return; }, - afterContextMenuDefaultOptions: () => {return; }, - afterContextMenuHide: () => {return; }, - afterContextMenuShow: () => {return; }, - afterCopyLimit: () => {return; }, - afterCreateCol: () => {return; }, - afterCreateRow: () => {return; }, - afterDeselect: () => {return; }, - afterDestroy: () => {return; }, - afterDocumentKeyDown: () => {return; }, - afterFilter: () => {return; }, - afterGetCellMeta: () => {return; }, - afterGetColHeader: () => {return; }, - afterGetColumnHeaderRenderers: () => {return; }, - afterGetRowHeader: () => {return; }, - afterGetRowHeaderRenderers: () => {return; }, - afterInit: () => {return; }, - afterLoadData: () => {return; }, - afterMomentumScroll: () => {return; }, - afterOnCellCornerMouseDown: () => {return; }, - afterOnCellMouseDown: () => {return; }, - afterOnCellMouseOver: () => {return; }, - afterRemoveCol: () => {return; }, - afterRemoveRow: () => {return; }, - afterRender: () => {return; }, - afterRenderer: () => {return; }, - afterRowMove: () => {return; }, - afterRowResize: () => {return; }, - afterScrollHorizontally: () => {return; }, - afterScrollVertically: () => {return; }, - afterSelection: () => {return; }, - afterSelectionByProp: () => {return; }, - afterSelectionEnd: () => {return; }, - afterSelectionEndByProp: () => {return; }, - afterSetCellMeta: () => {return; }, - afterUpdateSettings: () => {return; }, - afterValidate: () => {return; }, - beforeAutofill: () => {return; }, - beforeCellAlignment: () => {return; }, - beforeChange: () => {return; }, - beforeChangeRender: () => {return; }, - beforeColumnMove: () => {return; }, - beforeColumnResize: () => {return; }, - beforeColumnSort: () => {return; }, - beforeDrawBorders: () => {return; }, - beforeFilter: () => {return; }, - beforeGetCellMeta: () => {return; }, - beforeInit: () => {return; }, - beforeInitWalkontable: () => {return; }, - beforeKeyDown: () => {return; }, - beforeOnCellMouseDown: () => {return; }, - beforeRemoveCol: () => {return; }, - beforeRemoveRow: () => {return; }, - beforeRender: () => {return; }, - beforeRenderer: () => {return; }, - beforeRowMove: () => {return; }, - beforeRowResize: () => {return; }, - beforeSetRangeEnd: () => {return; }, - beforeStretchingColumnWidth: () => {return; }, - beforeTouchScroll: () => {return; }, - beforeValidate: () => {return; }, - construct: () => {return; }, - init: () => {return; }, - modifyCol: () => {return; }, - modifyColHeader: () => {return; }, - modifyColWidth: () => {return; }, - modifyCopyableRange: () => {return; }, - modifyRow: () => {return; }, - modifyRowHeader: () => {return; }, - modifyRowHeight: () => {return; }, - persistentStateLoad: () => {return; }, - persistentStateReset: () => {return; }, - persistentStateSave: () => {return; }, - unmodifyCol: () => {return; } - }); - } + // Hooks + afterAutofillApplyValues: () => {return; }, + afterCellMetaReset: () => {return; }, + afterChange: () => {return; }, + afterChangesObserved: () => {return; }, + afterColumnMove: () => {return; }, + afterColumnResize: () => {return; }, + afterColumnSort: () => {return; }, + afterContextMenuDefaultOptions: () => {return; }, + afterContextMenuHide: () => {return; }, + afterContextMenuShow: () => {return; }, + afterCopyLimit: () => {return; }, + afterCreateCol: () => {return; }, + afterCreateRow: () => {return; }, + afterDeselect: () => {return; }, + afterDestroy: () => {return; }, + afterDocumentKeyDown: () => {return; }, + afterFilter: () => {return; }, + afterGetCellMeta: () => {return; }, + afterGetColHeader: () => {return; }, + afterGetColumnHeaderRenderers: () => {return; }, + afterGetRowHeader: () => {return; }, + afterGetRowHeaderRenderers: () => {return; }, + afterInit: () => {return; }, + afterLoadData: () => {return; }, + afterMomentumScroll: () => {return; }, + afterOnCellCornerMouseDown: () => {return; }, + afterOnCellMouseDown: () => {return; }, + afterOnCellMouseOver: () => {return; }, + afterRemoveCol: () => {return; }, + afterRemoveRow: () => {return; }, + afterRender: () => {return; }, + afterRenderer: () => {return; }, + afterRowMove: () => {return; }, + afterRowResize: () => {return; }, + afterScrollHorizontally: () => {return; }, + afterScrollVertically: () => {return; }, + afterSelection: () => {return; }, + afterSelectionByProp: () => {return; }, + afterSelectionEnd: () => {return; }, + afterSelectionEndByProp: () => {return; }, + afterSetCellMeta: () => {return; }, + afterUpdateSettings: () => {return; }, + afterValidate: () => {return; }, + beforeAutofill: () => {return; }, + beforeCellAlignment: () => {return; }, + beforeChange: () => {return; }, + beforeChangeRender: () => {return; }, + beforeColumnMove: () => {return; }, + beforeColumnResize: () => {return; }, + beforeColumnSort: () => {return; }, + beforeDrawBorders: () => {return; }, + beforeFilter: () => {return; }, + beforeGetCellMeta: () => {return; }, + beforeInit: () => {return; }, + beforeInitWalkontable: () => {return; }, + beforeKeyDown: () => {return; }, + beforeOnCellMouseDown: () => {return; }, + beforeRemoveCol: () => {return; }, + beforeRemoveRow: () => {return; }, + beforeRender: () => {return; }, + beforeRenderer: () => {return; }, + beforeRowMove: () => {return; }, + beforeRowResize: () => {return; }, + beforeSetRangeEnd: () => {return; }, + beforeStretchingColumnWidth: () => {return; }, + beforeTouchScroll: () => {return; }, + beforeValidate: () => {return; }, + construct: () => {return; }, + init: () => {return; }, + modifyCol: () => {return; }, + modifyColHeader: () => {return; }, + modifyColWidth: () => {return; }, + modifyCopyableRange: () => {return; }, + modifyRow: () => {return; }, + modifyRowHeader: () => {return; }, + modifyRowHeight: () => {return; }, + persistentStateLoad: () => {return; }, + persistentStateReset: () => {return; }, + persistentStateSave: () => {return; }, + unmodifyCol: () => {return; } + }); +} - function test_HandsontableMethods() { - const elem = document.createElement('div'); - const hot = new Handsontable(elem, {}); - hot.addHook('foo', []); - hot.addHookOnce('foo', []); - hot.alter('foo', 123, 123, 'foo', true); - hot.clear(); - hot.colOffset(); - hot.colToProp(123); - hot.countCols(); - hot.countEmptyCols(true); - hot.countEmptyRows(true); - hot.countRenderedCols(); - hot.countRenderedRows(); - hot.countRows(); - hot.countSourceRows(); - hot.countVisibleCols(); - hot.countVisibleRows(); - hot.deselectCell(); - hot.destroy(); - hot.destroyEditor(true); - hot.getActiveEditor(); - hot.getCell(123, 123, true); - hot.getCellEditor(123, 123); - hot.getCellMeta(123, 123); - hot.getCellRenderer(123, 123); - hot.getCellValidator(123, 123); - hot.getColHeader(123); - hot.getColWidth(123); - hot.getCoords(elem.querySelector('td')); - hot.getCopyableData(123, 123); - hot.getCopyableText(123, 123, 123, 123); - hot.getData(123, 123, 123, 123); - hot.getDataAtCell(123, 123); - hot.getDataAtCol(123); - hot.getDataAtProp(123); - hot.getDataAtRow(123); - hot.getDataAtRowProp(123, 'foo'); - hot.getDataType(123, 123, 123, 123); - hot.getInstance(); - hot.getPlugin('foo'); - hot.getRowHeader(123); - hot.getRowHeight(123); - hot.getSchema(); - hot.getSelected(); - const range: Handsontable.Range = hot.getSelectedRange(); - hot.getSettings(); - hot.getSourceData(123, 123, 123, 123); - hot.getSourceDataAtCell(123, 123); - hot.getSourceDataAtCol(123); - hot.getSourceDataAtRow(123); - hot.getValue(); - hot.hasColHeaders(); - hot.hasHook('foo'); - hot.hasRowHeaders(); - hot.isEmptyCol(123); - hot.isEmptyRow(123); - hot.isListening(); - hot.listen(); - hot.loadData([]); - hot.populateFromArray(123, 123, [], 123, 123, 'foo', 'foo', 'foo', []); - hot.propToCol('foo'); - hot.propToCol(123); - hot.removeCellMeta(123, 123, 'foo'); - hot.removeHook('foo', () => {return; }); - hot.render(); - hot.rowOffset(); - hot.runHooks('foo', 123, 'foo', true, {}, [], () => {return; }); - hot.selectCell(123, 123, 123, 123, true, true); - hot.selectCellByProp(123, 'foo', 123, 'foo', true); - hot.setCellMeta(123, 123, 'foo', 'foo'); - hot.setCellMetaObject(123, 123, {}); - hot.setDataAtCell(123, 123, 'foo', 'foo'); - hot.setDataAtRowProp(123, 'foo', 'foo', 'foo'); - hot.spliceCol(123, 123, 123, 'foo'); - hot.spliceRow(123, 123, 123, 'foo'); - hot.toPhysicalRow(123); - hot.toPhysicalColumn(123); - hot.toVisualRow(123); - hot.toVisualColumn(123); - hot.unlisten(); - hot.updateSettings({}, true); - hot.validateCells(() => {return; }); +function test_HandsontableMethods() { + const elem = document.createElement('div'); + const hot = new Handsontable(elem, {}); + hot.addHook('foo', []); + hot.addHookOnce('foo', []); + hot.alter('foo', 123, 123, 'foo', true); + hot.clear(); + hot.colOffset(); + hot.colToProp(123); + hot.countCols(); + hot.countEmptyCols(true); + hot.countEmptyRows(true); + hot.countRenderedCols(); + hot.countRenderedRows(); + hot.countRows(); + hot.countSourceRows(); + hot.countVisibleCols(); + hot.countVisibleRows(); + hot.deselectCell(); + hot.destroy(); + hot.destroyEditor(true); + hot.getActiveEditor(); + hot.getCell(123, 123, true); + hot.getCellEditor(123, 123); + hot.getCellMeta(123, 123); + hot.getCellRenderer(123, 123); + hot.getCellValidator(123, 123); + hot.getColHeader(123); + hot.getColWidth(123); + hot.getCoords(elem.querySelector('td')); + hot.getCopyableData(123, 123); + hot.getCopyableText(123, 123, 123, 123); + hot.getData(123, 123, 123, 123); + hot.getDataAtCell(123, 123); + hot.getDataAtCol(123); + hot.getDataAtProp(123); + hot.getDataAtRow(123); + hot.getDataAtRowProp(123, 'foo'); + hot.getDataType(123, 123, 123, 123); + hot.getInstance(); + hot.getPlugin('foo'); + hot.getRowHeader(123); + hot.getRowHeight(123); + hot.getSchema(); + hot.getSelected(); + const range: Handsontable.Range = hot.getSelectedRange(); + hot.getSettings(); + hot.getSourceData(123, 123, 123, 123); + hot.getSourceDataAtCell(123, 123); + hot.getSourceDataAtCol(123); + hot.getSourceDataAtRow(123); + hot.getValue(); + hot.hasColHeaders(); + hot.hasHook('foo'); + hot.hasRowHeaders(); + hot.isEmptyCol(123); + hot.isEmptyRow(123); + hot.isListening(); + hot.listen(); + hot.loadData([]); + hot.populateFromArray(123, 123, [], 123, 123, 'foo', 'foo', 'foo', []); + hot.propToCol('foo'); + hot.propToCol(123); + hot.removeCellMeta(123, 123, 'foo'); + hot.removeHook('foo', () => {return; }); + hot.render(); + hot.rowOffset(); + hot.runHooks('foo', 123, 'foo', true, {}, [], () => {return; }); + hot.selectCell(123, 123, 123, 123, true, true); + hot.selectCellByProp(123, 'foo', 123, 'foo', true); + hot.setCellMeta(123, 123, 'foo', 'foo'); + hot.setCellMetaObject(123, 123, {}); + hot.setDataAtCell(123, 123, 'foo', 'foo'); + hot.setDataAtRowProp(123, 'foo', 'foo', 'foo'); + hot.spliceCol(123, 123, 123, 'foo'); + hot.spliceRow(123, 123, 123, 'foo'); + hot.toPhysicalRow(123); + hot.toPhysicalColumn(123); + hot.toVisualRow(123); + hot.toVisualColumn(123); + hot.unlisten(); + hot.updateSettings({}, true); + hot.validateCells(() => {return; }); - Handsontable.renderers.NumericRenderer(hot, new HTMLTableDataCellElement(), 0, 0, "prop", 1.235, {}); - Handsontable.renderers.TextRenderer(hot, new HTMLTableDataCellElement(), 0, 0, "prop", 1.235, {}); - Handsontable.Dom.addEvent(new HTMLElement(), "eventName", () => { return; }); - } + Handsontable.renderers.NumericRenderer(hot, new HTMLTableDataCellElement(), 0, 0, "prop", 1.235, {}); + Handsontable.renderers.TextRenderer(hot, new HTMLTableDataCellElement(), 0, 0, "prop", 1.235, {}); + Handsontable.Dom.addEvent(new HTMLElement(), "eventName", () => { return; }); +} - class MyCustomHotPlugin extends Handsontable.plugins.BasePlugin { - isEnabled(): boolean { - return !!this.hot.getSettings().manualRowMove; - } +class MyCustomHotPlugin extends Handsontable.plugins.BasePlugin { + isEnabled(): boolean { + return !!this.hot.getSettings().manualRowMove; } } diff --git a/types/jquery-galleria/jquery-galleria-tests.ts b/types/jquery-galleria/jquery-galleria-tests.ts index edf0ceb3cc..b51393b78a 100644 --- a/types/jquery-galleria/jquery-galleria-tests.ts +++ b/types/jquery-galleria/jquery-galleria-tests.ts @@ -1,23 +1,20 @@ +var container = document.createElement("galleria"); -namespace JqueryGalleriaTests { - var container = document.createElement("galleria"); +var gOptions: GalleriaJS.GalleriaOptions; - var gOptions: GalleriaJS.GalleriaOptions; +gOptions.lightbox = true; +gOptions.autoplay = true; - gOptions.lightbox = true; - gOptions.autoplay = true; +Galleria.run("galleria", gOptions); - Galleria.run("galleria", gOptions); +gOptions.lightbox = false; - gOptions.lightbox = false; +Galleria.ready(function() { + this.configure(gOptions).refreshImage(); + }); - Galleria.ready(function() { - this.configure(gOptions).refreshImage(); - }); +Galleria.run("galleria"); - Galleria.run("galleria"); +gOptions.autoplay = false; - gOptions.autoplay = false; - - Galleria.run(); -} +Galleria.run(); diff --git a/types/lokijs/lokijs-tests.ts b/types/lokijs/lokijs-tests.ts index a020b27535..2e08370c02 100644 --- a/types/lokijs/lokijs-tests.ts +++ b/types/lokijs/lokijs-tests.ts @@ -2,102 +2,96 @@ import Loki = require("lokijs"); -namespace LokijsTest { +class Ant { + static uniqueId = 1; - class Ant { - static uniqueId = 1; - - id: number; - dob: Date; - health: number; // range [0.0, 1.0] - lengthMm: number; // in millimeters - weightMg: number; // in milligrams - - constructor(id: number) { - this.id = id; - } - - static createAnt() { - return new Ant(Ant.uniqueId++); - } + id: number; + dob: Date; + health: number; // range [0.0, 1.0] + lengthMm: number; // in millimeters + weightMg: number; // in milligrams + constructor(id: number) { + this.id = id; } - - class QueenAnt extends Ant { - eggsBirthed: number; - - constructor(id: number) { - super(id); - } - - static createQueenAnt() { - return new QueenAnt(Ant.uniqueId++); - } - - } - - - class AntColony { - ants: LokiCollection; - queens: LokiCollection; - - constructor(ants?: LokiCollection, queens?: LokiCollection) { - this.ants = ants; - this.queens = queens; - } - } - - - export class Test { - - static runAllTests() { - var lokiInst = new Loki("ant-colony", { autosave: false }); - var colony = Test.createAntColony(lokiInst, 250); - var topAnts = colony.ants.addDynamicView("top-ants"); - var topAntAry = topAnts.applyFind({ $gt: { health: 0.75 } }).data(); - - if (colony.ants.binaryIndices["id"] == null) { - throw new Error("missing 'id' binary index"); - } - - if (lokiInst.getCollection("ants") != colony.ants) { - throw new Error("ant collections don't match"); - } - - var collNames = lokiInst.listCollections().map((coll) => coll.name); - if (collNames.length != 2 || collNames.indexOf("ants") < 0 || collNames.indexOf("queenAnts") < 0) { - throw new Error("collections [" + collNames + "] does not equal expected ['ants', 'queenAnts']"); - } - - var firstQueenId = (colony.queens.findOne({}))["$loki"]; - if (firstQueenId == null || colony.queens.get(firstQueenId) == null) { - throw new Error("queen object's '.$loki' property lookup failed"); - } - - var anotherColl = new Loki.Collection("anotherCollection"); - - } - - - static createAntColony(lokiInst: Loki, antCount: number, queenCount: number = 1) { - var ants = lokiInst.addCollection("ants", { indices: "id" }); - var queens = lokiInst.addCollection("queenAnts", { indices: "id" }); - var antColony = new AntColony(ants, queens); - - for (var i = 0; i < antCount; i++) { - ants.add(Ant.createAnt()); - } - - for (var i = 0; i < antCount; i++) { - queens.add(QueenAnt.createQueenAnt()); - } - - return antColony; - } - + static createAnt() { + return new Ant(Ant.uniqueId++); } } -export = LokijsTest; + +class QueenAnt extends Ant { + eggsBirthed: number; + + constructor(id: number) { + super(id); + } + + static createQueenAnt() { + return new QueenAnt(Ant.uniqueId++); + } + +} + + +class AntColony { + ants: LokiCollection; + queens: LokiCollection; + + constructor(ants?: LokiCollection, queens?: LokiCollection) { + this.ants = ants; + this.queens = queens; + } +} + + +class Test { + + static runAllTests() { + var lokiInst = new Loki("ant-colony", { autosave: false }); + var colony = Test.createAntColony(lokiInst, 250); + var topAnts = colony.ants.addDynamicView("top-ants"); + var topAntAry = topAnts.applyFind({ $gt: { health: 0.75 } }).data(); + + if (colony.ants.binaryIndices["id"] == null) { + throw new Error("missing 'id' binary index"); + } + + if (lokiInst.getCollection("ants") != colony.ants) { + throw new Error("ant collections don't match"); + } + + var collNames = lokiInst.listCollections().map((coll) => coll.name); + if (collNames.length != 2 || collNames.indexOf("ants") < 0 || collNames.indexOf("queenAnts") < 0) { + throw new Error("collections [" + collNames + "] does not equal expected ['ants', 'queenAnts']"); + } + + var firstQueenId = (colony.queens.findOne({}))["$loki"]; + if (firstQueenId == null || colony.queens.get(firstQueenId) == null) { + throw new Error("queen object's '.$loki' property lookup failed"); + } + + var anotherColl = new Loki.Collection("anotherCollection"); + + } + + + static createAntColony(lokiInst: Loki, antCount: number, queenCount: number = 1) { + var ants = lokiInst.addCollection("ants", { indices: "id" }); + var queens = lokiInst.addCollection("queenAnts", { indices: "id" }); + var antColony = new AntColony(ants, queens); + + for (var i = 0; i < antCount; i++) { + ants.add(Ant.createAnt()); + } + + for (var i = 0; i < antCount; i++) { + queens.add(QueenAnt.createQueenAnt()); + } + + return antColony; + } + +} diff --git a/types/redlock/redlock-tests.ts b/types/redlock/redlock-tests.ts index f00fa00f95..311103ad2d 100644 --- a/types/redlock/redlock-tests.ts +++ b/types/redlock/redlock-tests.ts @@ -3,44 +3,36 @@ import { Callback as NodeifyCallback, Options, Lock } from 'redlock'; import * as Promise from 'bluebird'; import {RedisClient} from 'redis'; -namespace RedlockTest { +let redlock: Redlock; +let client: RedisClient; +let lock: Lock; - let redlock: Redlock; - let client: RedisClient; - let lock: Lock; +redlock = new Redlock([client]); +redlock = new Redlock([client], { + driftFactor: 0.1, + retryCount: 2, + retryDelay: 3 +}); - redlock = new Redlock([client]); - redlock = new Redlock([client], { - driftFactor: 0.1, - retryCount: 2, - retryDelay: 3 - }); +redlock.acquire('resource', 30).then((lock: Lock) => { }); +redlock.acquire('resource', 30, (err: any, lock: Lock) => { }); +redlock.lock('resource', 30).then((lock: Lock) => { }); +redlock.lock('resource', 30, (err: any, lock: Lock) => { }); - redlock.acquire('resource', 30).then((lock: Lock) => { }); - redlock.acquire('resource', 30, (err: any, lock: Lock) => { }); - redlock.lock('resource', 30).then((lock: Lock) => { }); - redlock.lock('resource', 30, (err: any, lock: Lock) => { }); +// There is currently no way to test the disposer as the bluebird typings does not +// expose the .using method. +// promise.using(redlock.disposer('resource', 30), (lock: Lock) => {}); - // There is currently no way to test the disposer as the bluebird typings does not - // expose the .using method. - // promise.using(redlock.disposer('resource', 30), (lock: Lock) => {}); +redlock.release(lock); +redlock.release(lock, (err: any) => { }); +redlock.unlock(lock); +redlock.unlock(lock, (err: any) => { }); - redlock.release(lock); - redlock.release(lock, (err: any) => { }); - redlock.unlock(lock); - redlock.unlock(lock, (err: any) => { }); +redlock.extend(lock, 30).then((lock: Lock) => { }); +redlock.extend(lock, 30, (err: any, lock: Lock) => { }); - redlock.extend(lock, 30).then((lock: Lock) => { }); - redlock.extend(lock, 30, (err: any, lock: Lock) => { }); -} +lock.unlock(); +lock.unlock((err) => { }); -namespace LockTest { - - let lock: Lock; - - lock.unlock(); - lock.unlock((err) => { }); - - lock.extend(30).then((lock: Lock) => { }); - lock.extend(30, (err: any, lock: Lock) => { }); -} +lock.extend(30).then((lock: Lock) => { }); +lock.extend(30, (err: any, lock: Lock) => { }); diff --git a/types/yfiles/yfiles-tests.ts b/types/yfiles/yfiles-tests.ts index 40f6ce8540..9f227aced5 100644 --- a/types/yfiles/yfiles-tests.ts +++ b/types/yfiles/yfiles-tests.ts @@ -1,148 +1,144 @@ -namespace yfilesTest { +class BasicTest { + private graphComponent:yfiles.view.GraphComponent; - export class BasicTest { - private graphComponent:yfiles.view.GraphComponent; + constructor() { + this.graphComponent = new yfiles.view.GraphComponent("graphControl"); - constructor() { - this.graphComponent = new yfiles.view.GraphComponent("graphControl"); + let graphEditorInputMode = new yfiles.input.GraphEditorInputMode(); - let graphEditorInputMode = new yfiles.input.GraphEditorInputMode(); + // Modify the MyHitTestable class to be usable with our class framework + yfiles.lang.Class.injectInterfaces(MyHitTestable.prototype, [yfiles.input.IHitTestable]); + let myHitTestable = new MyHitTestable(); - // Modify the MyHitTestable class to be usable with our class framework - yfiles.lang.Class.injectInterfaces(MyHitTestable.prototype, [yfiles.input.IHitTestable]); - let myHitTestable = new MyHitTestable(); - - if (yfiles.input.IHitTestable.isInstance(myHitTestable)) { - // If myHitTestable is recognized as instance of yfiles.drawing.IHitTestable by the yFiles class - // framework, set it as hit testable to prevent clicking any item. - // If you cannot click-select the nodes in the GraphControl, this worked correctly. - graphEditorInputMode.clickInputMode.validClickHitTestable = myHitTestable; - } - - this.graphComponent.inputMode = graphEditorInputMode; - - this.graphComponent.graph.nodeDefaults.style = new yfiles.styles.ShinyPlateNodeStyle(yfiles.view.Fill.ORANGE); - - this.graphComponent.graph.createNode(new yfiles.geometry.Rect(0, 0, 10, 10), new MyNodeStyle()); - - this.layout(); + if (yfiles.input.IHitTestable.isInstance(myHitTestable)) { + // If myHitTestable is recognized as instance of yfiles.drawing.IHitTestable by the yFiles class + // framework, set it as hit testable to prevent clicking any item. + // If you cannot click-select the nodes in the GraphControl, this worked correctly. + graphEditorInputMode.clickInputMode.validClickHitTestable = myHitTestable; } - start() { - for (let i = 0; i < 5; i++) { - for (let j = 0; j < 5; j++) { - this.graphComponent.graph.createNodeAt(new yfiles.geometry.Point(100 * i, 100 * j)); - } - } - this.graphComponent.graph.nodes.forEach((node) => this.graphComponent.graph.addLabel(node, "Label")); - this.graphComponent.fitGraphBounds(); - } + this.graphComponent.inputMode = graphEditorInputMode; + this.graphComponent.graph.nodeDefaults.style = new yfiles.styles.ShinyPlateNodeStyle(yfiles.view.Fill.ORANGE); - /** - * Runs a layout algorithm and animates the transition to the new layout. - */ - layout() { - let layouter = new yfiles.hierarchic.HierarchicLayout(); - let layoutExecutor = new yfiles.layout.LayoutExecutor(this.graphComponent, - new yfiles.layout.MinimumNodeSizeStage(layouter)); + this.graphComponent.graph.createNode(new yfiles.geometry.Rect(0, 0, 10, 10), new MyNodeStyle()); - layoutExecutor.duration = yfiles.lang.TimeSpan.fromSeconds(1); - layoutExecutor.animateViewport = true; - layoutExecutor.updateContentRect = true; - layoutExecutor.start().then(() => { - return null; - }) - .catch(error => { - throw error; - }); - } + this.layout(); + } - /** - * Runs a shortest path analysis. - */ - analyze() { - let graph = this.graphComponent.graph; - - // Create the graph model adapter to get a proper analysis graph structure. - let graphAdapter = new yfiles.layout.YGraphAdapter(graph); - - // Create an array the size of the edge set with costs for each edge. - let cost = new Array(graph.edges.size); - for (let i = 0; i < graph.edges.size; i++) { - cost[i] = Math.random(); - } - - let pred:yfiles.algorithms.Edge[] = null; - - // Suppose the first node from the graph is the node named "Start." - let startNode = graphAdapter.getCopiedNode(graph.nodes.first()); - // Suppose the last node from the graph is the node named "Destination." - let destinationNode = graphAdapter.getCopiedNode(graph.nodes.last()); - - // Run the single-source single-sink algorithm on the graph. - let result = yfiles.algorithms.ShortestPaths.singleSourceSingleSink(graphAdapter.yGraph, startNode, - destinationNode, true, cost, pred); - // Transfer back the result. - let predIGraph = new Array(pred.length); - for (let i = 0; i < pred.length; i++) { - predIGraph[i] = graphAdapter.getOriginalEdge(pred[i]); + start() { + for (let i = 0; i < 5; i++) { + for (let j = 0; j < 5; j++) { + this.graphComponent.graph.createNodeAt(new yfiles.geometry.Point(100 * i, 100 * j)); } } + this.graphComponent.graph.nodes.forEach((node) => this.graphComponent.graph.addLabel(node, "Label")); + this.graphComponent.fitGraphBounds(); + } - coreLib() { - new yfiles.lang.AttributeDefinition(() => { return {} }); - new yfiles.lang.ClassDefinition(() => { return {} }); - new yfiles.lang.EnumDefinition(() => { return {} }); - new yfiles.lang.StructDefinition(() => { return {} }); + /** + * Runs a layout algorithm and animates the transition to the new layout. + */ + layout() { + let layouter = new yfiles.hierarchic.HierarchicLayout(); + let layoutExecutor = new yfiles.layout.LayoutExecutor(this.graphComponent, + new yfiles.layout.MinimumNodeSizeStage(layouter)); + + layoutExecutor.duration = yfiles.lang.TimeSpan.fromSeconds(1); + layoutExecutor.animateViewport = true; + layoutExecutor.updateContentRect = true; + layoutExecutor.start().then(() => { + return null; + }) + .catch(error => { + throw error; + }); + } + + /** + * Runs a shortest path analysis. + */ + analyze() { + let graph = this.graphComponent.graph; + + // Create the graph model adapter to get a proper analysis graph structure. + let graphAdapter = new yfiles.layout.YGraphAdapter(graph); + + // Create an array the size of the edge set with costs for each edge. + let cost = new Array(graph.edges.size); + for (let i = 0; i < graph.edges.size; i++) { + cost[i] = Math.random(); } - namespacesExist() { - let a01 = new yfiles.algorithms.AbortHandler(); - let a02 = new yfiles.binding.AdjacentNodesGraphBuilder(this.graphComponent.graph); - let a03 = new yfiles.circular.CircularLayout(); - let a04 = new yfiles.collections.List(); - let a05 = new yfiles.genealogy.FamilyTreeLayout(); - let a06 = new yfiles.geometry.Matrix(); - let a07 = new yfiles.graph.GraphClipboard(); - let a08:yfiles.graphml.ChildParseContext; - let a09 = new yfiles.hierarchic.AsIsLayerer(); - let a10 = new yfiles.input.GraphEditorInputMode(); - let a11 = new yfiles.labeling.GenericLabeling(); - let a12 = new yfiles.lang.Attribute(); - let a13 = new yfiles.layout.BendConverter(); - let a14 = new yfiles.multipage.DefaultElementFactory(); - let a15 = new yfiles.organic.OrganicLayout(); - let a16 = new yfiles.orthogonal.CompactOrthogonalLayout(); - let a17 = new yfiles.partial.PartialLayout(); - let a18 = new yfiles.radial.RadialLayout(); - let a19 = new yfiles.router.BusRouter(); - let a20 = new yfiles.seriesparallel.SeriesParallelLayout(); - let a21 = new yfiles.styles.ArcEdgeStyle(); - let a22 = new yfiles.tree.AspectRatioTreeLayout(); - let a23 = new yfiles.view.GraphComponent(); - } + let pred:yfiles.algorithms.Edge[] = null; - testsForVersion2001() { - var element:SVGElement; - yfiles.view.SvgVisual.setScale(element, 4, 2); - yfiles.view.SvgVisual.setTranslate(element, 4, 2); - - var args = new yfiles.lang.EventArgs(); - yfiles.input.KeyEventRecognizers.META_PRESSED(null, args); + // Suppose the first node from the graph is the node named "Start." + let startNode = graphAdapter.getCopiedNode(graph.nodes.first()); + // Suppose the last node from the graph is the node named "Destination." + let destinationNode = graphAdapter.getCopiedNode(graph.nodes.last()); + + // Run the single-source single-sink algorithm on the graph. + let result = yfiles.algorithms.ShortestPaths.singleSourceSingleSink(graphAdapter.yGraph, startNode, + destinationNode, true, cost, pred); + // Transfer back the result. + let predIGraph = new Array(pred.length); + for (let i = 0; i < pred.length; i++) { + predIGraph[i] = graphAdapter.getOriginalEdge(pred[i]); } } - class MyHitTestable extends yfiles.lang.BaseClass(yfiles.input.IHitTestable) implements yfiles.input.IHitTestable { - isHit(ctx:yfiles.input.IInputModeContext, p:yfiles.geometry.Point):boolean { - return false; - } + coreLib() { + new yfiles.lang.AttributeDefinition(() => { return {} }); + new yfiles.lang.ClassDefinition(() => { return {} }); + new yfiles.lang.EnumDefinition(() => { return {} }); + new yfiles.lang.StructDefinition(() => { return {} }); } - class MyNodeStyle extends yfiles.styles.NodeStyleBase { - createVisual(renderContext:yfiles.view.IRenderContext, node:yfiles.graph.INode):yfiles.view.SvgVisual { - let g = document.createElementNS("http://www.w3.org/2000/svg", "g"); - return new yfiles.view.SvgVisual(g); - } + namespacesExist() { + let a01 = new yfiles.algorithms.AbortHandler(); + let a02 = new yfiles.binding.AdjacentNodesGraphBuilder(this.graphComponent.graph); + let a03 = new yfiles.circular.CircularLayout(); + let a04 = new yfiles.collections.List(); + let a05 = new yfiles.genealogy.FamilyTreeLayout(); + let a06 = new yfiles.geometry.Matrix(); + let a07 = new yfiles.graph.GraphClipboard(); + let a08:yfiles.graphml.ChildParseContext; + let a09 = new yfiles.hierarchic.AsIsLayerer(); + let a10 = new yfiles.input.GraphEditorInputMode(); + let a11 = new yfiles.labeling.GenericLabeling(); + let a12 = new yfiles.lang.Attribute(); + let a13 = new yfiles.layout.BendConverter(); + let a14 = new yfiles.multipage.DefaultElementFactory(); + let a15 = new yfiles.organic.OrganicLayout(); + let a16 = new yfiles.orthogonal.CompactOrthogonalLayout(); + let a17 = new yfiles.partial.PartialLayout(); + let a18 = new yfiles.radial.RadialLayout(); + let a19 = new yfiles.router.BusRouter(); + let a20 = new yfiles.seriesparallel.SeriesParallelLayout(); + let a21 = new yfiles.styles.ArcEdgeStyle(); + let a22 = new yfiles.tree.AspectRatioTreeLayout(); + let a23 = new yfiles.view.GraphComponent(); + } + + testsForVersion2001() { + var element:SVGElement; + yfiles.view.SvgVisual.setScale(element, 4, 2); + yfiles.view.SvgVisual.setTranslate(element, 4, 2); + + var args = new yfiles.lang.EventArgs(); + yfiles.input.KeyEventRecognizers.META_PRESSED(null, args); + } +} + +class MyHitTestable extends yfiles.lang.BaseClass(yfiles.input.IHitTestable) implements yfiles.input.IHitTestable { + isHit(ctx:yfiles.input.IInputModeContext, p:yfiles.geometry.Point):boolean { + return false; + } +} + +class MyNodeStyle extends yfiles.styles.NodeStyleBase { + createVisual(renderContext:yfiles.view.IRenderContext, node:yfiles.graph.INode):yfiles.view.SvgVisual { + let g = document.createElementNS("http://www.w3.org/2000/svg", "g"); + return new yfiles.view.SvgVisual(g); } }