From 32f718ab9ad42cb59bd825b6d9c3f0aee4076c6b Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Fri, 23 Sep 2016 00:22:57 -0500 Subject: [PATCH] fix(viewService): Allow root ui-view to be wrapped in ng-if Fixed an off-by-one error in viewService which caused the root ui-view to not be deregistered properly. Closes #3004 --- src/view/view.ts | 2 +- test/core/viewServiceSpec.ts | 60 ++++++++++++++++++++++++++++++++++++ test/ng1/viewSpec.ts | 10 +++--- 3 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 test/core/viewServiceSpec.ts diff --git a/src/view/view.ts b/src/view/view.ts index bb3f7bf1f..5bbf5f04e 100644 --- a/src/view/view.ts +++ b/src/view/view.ts @@ -185,7 +185,7 @@ export class ViewService { return () => { let idx = uiViews.indexOf(uiView); - if (idx <= 0) { + if (idx === -1) { trace.traceViewServiceUIViewEvent("Tried removing non-registered uiView", uiView); return; } diff --git a/test/core/viewServiceSpec.ts b/test/core/viewServiceSpec.ts new file mode 100644 index 000000000..f37967fd4 --- /dev/null +++ b/test/core/viewServiceSpec.ts @@ -0,0 +1,60 @@ +/// + +import {UIRouter} from "../../src/router"; +import {tree2Array} from "../testUtils.ts"; +import {StateRegistry} from "../../src/state/stateRegistry"; +import {ViewService} from "../../src/view/view"; +import {ActiveUIView} from "../../src/view/interface"; + +let router: UIRouter = null; +let registry: StateRegistry = null; +let $view: ViewService = null; +let statetree = { + A: { + B: { + C: { + D: { + + } + } + } + } +}; + +let count = 0; +const makeUIView = (): ActiveUIView => ({ + $type: 'test', + id: count++, + name: '$default', + fqn: '$default', + config: null, + creationContext: null, + configUpdated: function() {} +}); + +describe("View Service", () => { + beforeEach(() => { + router = new UIRouter(); + registry = router.stateRegistry; + $view = router.viewService; + tree2Array(statetree, true).forEach(state => registry.register(state)); + registry.stateQueue.autoFlush(router.stateService); + }); + + describe('registerUIView', () => { + it("should track a ui-view", () => { + expect($view.available().length).toBe(0); + $view.registerUIView(makeUIView()); + expect($view.available().length).toBe(1); + }); + + it("should return a deregistration function", () => { + expect($view.available().length).toBe(0); + let deregistrationFn = $view.registerUIView(makeUIView()); + expect(typeof deregistrationFn).toBe('function'); + expect($view.available().length).toBe(1); + deregistrationFn(); + expect($view.available().length).toBe(0); + }); + }); +}); \ No newline at end of file diff --git a/test/ng1/viewSpec.ts b/test/ng1/viewSpec.ts index dcf136178..60a29411b 100644 --- a/test/ng1/viewSpec.ts +++ b/test/ng1/viewSpec.ts @@ -1,7 +1,7 @@ -/// -/// -/// - +/// +/// +/// +import * as angular from "angular"; var module = angular.mock.module; import {inherit, extend, tail} from "../../src/common/common"; @@ -52,7 +52,7 @@ describe('view', function() { })); describe('controller handling', function() { - let state, path, ctrlExpression; + let state, path: PathNode[], ctrlExpression; beforeEach(() => { ctrlExpression = null; state = register({