1+ /// <reference path='../../node_modules/@types/jasmine/index.d.ts' />
2+
3+ import { UIRouter } from "../../src/router" ;
4+ import { tree2Array } from "../testUtils.ts" ;
5+ import { StateRegistry } from "../../src/state/stateRegistry" ;
6+ import { ViewService } from "../../src/view/view" ;
7+ import { ActiveUIView } from "../../src/view/interface" ;
8+
9+ let router : UIRouter = null ;
10+ let registry : StateRegistry = null ;
11+ let $view : ViewService = null ;
12+ let statetree = {
13+ A : {
14+ B : {
15+ C : {
16+ D : {
17+
18+ }
19+ }
20+ }
21+ }
22+ } ;
23+
24+ let count = 0 ;
25+ const makeUIView = ( ) : ActiveUIView => ( {
26+ $type : 'test' ,
27+ id : count ++ ,
28+ name : '$default' ,
29+ fqn : '$default' ,
30+ config : null ,
31+ creationContext : null ,
32+ configUpdated : function ( ) { }
33+ } ) ;
34+
35+ describe ( "View Service" , ( ) => {
36+ beforeEach ( ( ) => {
37+ router = new UIRouter ( ) ;
38+ registry = router . stateRegistry ;
39+ $view = router . viewService ;
40+ tree2Array ( statetree , true ) . forEach ( state => registry . register ( state ) ) ;
41+ registry . stateQueue . autoFlush ( router . stateService ) ;
42+ } ) ;
43+
44+ describe ( 'registerUIView' , ( ) => {
45+ it ( "should track a ui-view" , ( ) => {
46+ expect ( $view . available ( ) . length ) . toBe ( 0 ) ;
47+ $view . registerUIView ( makeUIView ( ) ) ;
48+ expect ( $view . available ( ) . length ) . toBe ( 1 ) ;
49+ } ) ;
50+
51+ it ( "should return a deregistration function" , ( ) => {
52+ expect ( $view . available ( ) . length ) . toBe ( 0 ) ;
53+ let deregistrationFn = $view . registerUIView ( makeUIView ( ) ) ;
54+ expect ( typeof deregistrationFn ) . toBe ( 'function' ) ;
55+ expect ( $view . available ( ) . length ) . toBe ( 1 ) ;
56+ deregistrationFn ( ) ;
57+ expect ( $view . available ( ) . length ) . toBe ( 0 ) ;
58+ } ) ;
59+ } ) ;
60+ } ) ;
0 commit comments