Skip to content

Commit 83bd52a

Browse files
test(Transition): Switch to Typescript and fix parts of the transition test harness
1 parent 7a4a116 commit 83bd52a

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

test/transitionSpec.js renamed to test/transitionSpec.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
1+
import Node from "../src/path/node";
12
var module = angular.mock.module;
2-
var uiRouter = require("ui-router");
3-
var common = uiRouter.common.common;
4-
var RejectType = uiRouter.transition.rejectFactory.RejectType;
5-
var extend = common.extend,
6-
forEach = common.forEach,
7-
map = common.map,
8-
omit = common.omit,
9-
pick = common.pick,
10-
pluck = common.pluck;
11-
var PathFactory = uiRouter.path.pathFactory.default;
12-
var state = uiRouter.state;
13-
var StateMatcher = state.stateMatcher.default;
14-
var StateBuilder = state.stateBuilder.default;
15-
var TargetState = state.targetState.default;
16-
var StateQueueManager = state.stateQueueManager.default;
17-
var TransitionRejection = uiRouter.transition.rejectFactory.TransitionRejection;
3+
import uiRouter from "../src/ui-router";
4+
import { RejectType } from "../src/transition/rejectFactory";
5+
import { extend, forEach, map, omit, pick, pluck } from "../src/common/common";
6+
import PathFactory from "../src/path/pathFactory";
7+
import StateMatcher from "../src/state/stateMatcher";
8+
import StateBuilder from "../src/state/stateBuilder";
9+
import TargetState from "../src/state/targetState";
10+
import StateQueueManager from "../src/state/stateQueueManager";
11+
import {TransitionRejection} from "../src/transition/rejectFactory";
1812

1913
describe('transition', function () {
2014

2115
var transitionProvider, matcher, pathFactory, statesMap, queue;
2216

23-
var targetState = function(identifier, params, options) {
17+
var targetState = function(identifier, params = {}, options?) {
2418
options = options || {};
2519
var stateDefinition = matcher.find(identifier, options.relative);
2620
return new TargetState(identifier, stateDefinition, params, options);
@@ -52,7 +46,7 @@ describe('transition', function () {
5246
matcher = new StateMatcher(statesMap = {});
5347
pathFactory = new PathFactory(function() { return root; });
5448
var builder = new StateBuilder(function() { return root; }, matcher, $urlMatcherFactoryProvider);
55-
queue = new StateQueueManager(statesMap, builder, { when: function() {} });
49+
queue = new StateQueueManager(statesMap, builder, { when: function() {} }, null);
5650
var root = queue.register({ name: '', url: '^', views: null, 'abstract': true});
5751
root.navigable = null;
5852

@@ -79,15 +73,15 @@ describe('transition', function () {
7973
matcher = new StateMatcher(statesMap);
8074
queue.flush($state);
8175
makeTransition = function makeTransition(from, to, options) {
82-
var paramsPath = PathFactory.makeParamsPath(targetState(from));
83-
var fromPath = PathFactory.bindTransNodesToPath(paramsPath.adapt(PathFactory.makeResolveNode));
76+
let fromState = targetState(from).$state();
77+
let fromPath = fromState.path.map(state => new Node(state));
8478
return $transitions.create(fromPath, targetState(to, null, options));
8579
};
8680
}));
8781

8882
describe('provider', function() {
8983
describe('async event hooks:', function() {
90-
function PromiseResult(promise) {
84+
function PromiseResult(promise?) {
9185
var self = this, _promise;
9286
var resolve, reject, complete;
9387

@@ -280,7 +274,7 @@ describe('transition', function () {
280274
}));
281275

282276
it('should be called if any part of the transition fails.', inject(function($transitions, $q) {
283-
transitionProvider.onEnter({ from: "A", to: "C" }, function($transition$) { throw new Erorr("oops!"); });
277+
transitionProvider.onEnter({ from: "A", to: "C" }, function($transition$) { throw new Error("oops!"); });
284278
transitionProvider.onError({ from: "*", to: "*" }, function($transition$) { states.push($transition$.to().name); });
285279

286280
var states = [];
@@ -289,7 +283,7 @@ describe('transition', function () {
289283
}));
290284

291285
it('should be called for only handlers matching the transition.', inject(function($transitions, $q) {
292-
transitionProvider.onEnter({ from: "A", to: "C" }, function($transition$) { throw new Erorr("oops!"); });
286+
transitionProvider.onEnter({ from: "A", to: "C" }, function($transition$) { throw new Error("oops!"); });
293287
transitionProvider.onError({ from: "*", to: "*" }, function($transition$) { hooks.push("splatsplat"); });
294288
transitionProvider.onError({ from: "A", to: "C" }, function($transition$) { hooks.push("AC"); });
295289
transitionProvider.onError({ from: "A", to: "D" }, function($transition$) { hooks.push("AD"); });
@@ -440,7 +434,7 @@ describe('transition', function () {
440434
}));
441435

442436
it('should not include already entered elements', inject(function($transitions) {
443-
t = makeTransition("B", "D");
437+
let t = makeTransition("B", "D");
444438
expect(pluck(t.entering(), 'name')).toEqual([ "C", "D" ]);
445439
}));
446440
});

0 commit comments

Comments
 (0)