Skip to content

Commit

Permalink
fix(viewService): Allow root ui-view to be wrapped in ng-if
Browse files Browse the repository at this point in the history
Fixed an off-by-one error in viewService which caused the root ui-view to not be deregistered properly.
Closes #3004
  • Loading branch information
christopherthielen committed Sep 23, 2016
1 parent 5a12f92 commit 32f718a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/view/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
60 changes: 60 additions & 0 deletions test/core/viewServiceSpec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/// <reference path='../../node_modules/@types/jasmine/index.d.ts' />

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);
});
});
});
10 changes: 5 additions & 5 deletions test/ng1/viewSpec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference path='../../typings/angularjs/angular.d.ts' />
/// <reference path='../../typings/angularjs/angular-mocks.d.ts' />
/// <reference path='../../typings/jasmine/jasmine.d.ts' />

/// <reference path='../../node_modules/@types/angular/index.d.ts' />
/// <reference path='../../node_modules/@types/angular-mocks/index.d.ts' />
/// <reference path='../../node_modules/@types/jasmine/index.d.ts' />
import * as angular from "angular";
var module = angular.mock.module;

import {inherit, extend, tail} from "../../src/common/common";
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 32f718a

Please sign in to comment.