Added tests covering all modifications.

This commit is contained in:
Dan Lewi Harkestad 2015-08-18 20:09:11 +02:00
parent 92ba5354f9
commit 4af10f4fae

View File

@ -14,12 +14,28 @@ myApp.config((
var matcher: ng.ui.IUrlMatcher = $urlMatcherFactory.compile("/foo/:bar?param1");
$urlMatcherFactory.caseInsensitive(false);
var isCaseInsensitive = $urlMatcherFactory.caseInsensitive();
$urlMatcherFactory.defaultSquashPolicy("nosquash");
$urlMatcherFactory.strictMode(true);
var isStrictMode = $urlMatcherFactory.strictMode();
$urlMatcherFactory.type("myType2", {
encode: function (item: any) { return item; },
decode: function (item: any) { return item; },
is: function (item: any) { return true; }
});
$urlMatcherFactory.type("fullType", {
decode: (val) => parseInt(val, 10),
encode: (val) => val && val.toString(),
equals: (a, b) => this.is(a) && a === b,
is: (val) => angular.isNumber(val) && isFinite(val) && val % 1 === 0,
pattern: /\d+/
});
var obj: Object = matcher.exec('/user/bob', { x:'1', q:'hello' });
var concat: ng.ui.IUrlMatcher = matcher.concat('/test');
var str: string = matcher.format({ id:'bob', q:'yes' });
@ -177,3 +193,35 @@ module UiViewScrollProviderTests {
$uiViewScrollProvider.useAnchorScroll();
}]);
}
interface ITestUserService {
isLoggedIn: () => boolean;
handleLogin: () => ng.IPromise<{}>;
}
module UrlRouterProviderTests {
var app = angular.module("urlRouterProviderTests", ["ui.router"]);
app.config(($urlRouterProvider: ng.ui.IUrlRouterProvider) => {
// Prevent $urlRouter from automatically intercepting URL changes;
// this allows you to configure custom behavior in between
// location changes and route synchronization:
$urlRouterProvider.deferIntercept();
}).run(($rootScope: ng.IRootScopeService, $urlRouter: ng.ui.IUrlRouterService, UserService: ITestUserService) => {
$rootScope.$on('$locationChangeSuccess', e => {
// UserService is an example service for managing user state
if (UserService.isLoggedIn()) return;
// Prevent $urlRouter's default handler from firing
e.preventDefault();
UserService.handleLogin().then(() => {
// Once the user has logged in, sync the current URL to the router:
$urlRouter.sync();
});
});
// Configures $urlRouter's listener *after* your custom listener
$urlRouter.listen();
});
}