@@ -21,33 +21,107 @@ describe('inspectedApp', function() {
21
21
} ) ;
22
22
23
23
describe ( 'messaging' , function ( ) {
24
- it ( 'should track hints' , inject ( function ( $browser ) {
25
- port . onMessage . trigger ( JSON . stringify ( { message : 'hi' } ) ) ;
26
- $browser . defer . flush ( ) ;
27
- expect ( inspectedApp . hints ) . toEqual ( [ { message : 'hi' } ] ) ;
28
- } ) ) ;
24
+ var $browser ;
25
+ beforeEach ( function ( ) {
26
+ inject ( function ( _$browser_ ) {
27
+ $browser = _$browser_ ;
28
+ } ) ;
29
+ } ) ;
29
30
30
- it ( 'should track new scopes' , inject ( function ( $browser ) {
31
- port . onMessage . trigger ( JSON . stringify ( { event : 'scope:new' , data : { child : 1 } } ) ) ;
31
+ function triggerAndFlush ( object ) {
32
+ port . onMessage . trigger ( JSON . stringify ( object ) ) ;
32
33
$browser . defer . flush ( ) ;
34
+ }
35
+
36
+ it ( 'should track hints' , function ( ) {
37
+ var hint = { isHint : true } ;
38
+ triggerAndFlush ( hint ) ;
39
+
40
+ expect ( inspectedApp . hints ) . toEqual ( [ hint ] ) ;
41
+ } ) ;
42
+
43
+ it ( 'should hydrate the model' , function ( ) {
44
+ var scopes = { 1 : 'a' , 2 : 'b' } ,
45
+ hints = [ 'h1' , 'h2' ] ;
46
+ triggerAndFlush ( { event : 'hydrate' , data : { scopes : scopes , hints : hints } } ) ;
47
+
48
+ expect ( inspectedApp . scopes [ 1 ] ) . toEqual ( scopes [ 1 ] ) ;
49
+ expect ( inspectedApp . scopes [ 2 ] ) . toEqual ( scopes [ 2 ] ) ;
50
+ expect ( inspectedApp . hints [ 0 ] ) . toEqual ( hints [ 0 ] ) ;
51
+ expect ( inspectedApp . hints [ 1 ] ) . toEqual ( hints [ 1 ] ) ;
52
+ } ) ;
53
+
54
+ it ( 'should track new scopes' , function ( ) {
55
+ var id = 1 , parentId = 2 ;
56
+ inspectedApp . scopes [ parentId ] = { children : [ ] } ;
57
+ triggerAndFlush ( { event : 'scope:new' , data : { child : id , parent : parentId } } ) ;
58
+
59
+ expect ( inspectedApp . scopes [ id ] ) . toEqual ( { parent : parentId , children : [ ] , models : { } } ) ;
60
+ expect ( inspectedApp . scopes [ parentId ] . children ) . toEqual ( [ id ] ) ;
61
+ } ) ;
62
+
63
+ it ( 'should track new scopes without throwing exception when parent scope not present' , function ( ) {
64
+ var id = 1 , parentId = 2 ;
65
+ port . onMessage . trigger ( { event : 'scope:new' , data : { child : id , parent : parentId } } ) ;
66
+
67
+ expect ( $browser . defer . flush ) . not . toThrow ( ) ;
68
+ expect ( inspectedApp . scopes [ id ] ) . toEqual ( { parent : parentId , children : [ ] , models : { } } ) ;
69
+ } ) ;
33
70
34
- expect ( inspectedApp . scopes ) . toEqual ( { 1 : { parent : undefined , children : [ ] , models : { } } } ) ;
35
- } ) ) ;
71
+ it ( 'should track destruction of scopes without throwing error when parent scope not present' , function ( ) {
72
+ var id = 1 ;
73
+ inspectedApp . scopes [ id ] = true ;
74
+ port . onMessage . trigger ( { event : 'scope:destroy' , data : { id : id } } ) ;
36
75
37
- it ( 'should track updates to scope descriptors' , inject ( function ( $browser ) {
76
+ expect ( $browser . defer . flush ) . not . toThrow ( ) ;
77
+ expect ( inspectedApp . scopes . hasOwnProperty ( id ) ) . toBeFalsy ( ) ;
78
+ } ) ;
79
+
80
+ it ( 'should track model changes' , function ( ) {
81
+ var id = 1 ;
82
+ inspectedApp . scopes [ id ] = { models : { } } ;
83
+
84
+ triggerAndFlush ( {
85
+ event : 'model:change' ,
86
+ data : {
87
+ id : id ,
88
+ path : '' ,
89
+ value : '"jsonHere"'
90
+ }
91
+ } ) ;
92
+
93
+ expect ( inspectedApp . scopes [ id ] . models [ '' ] ) . toEqual ( "jsonHere" ) ;
94
+ } ) ;
95
+
96
+ it ( 'should track model changes without throwing exception when values are missing' , function ( ) {
97
+ var id = 1 ;
98
+ inspectedApp . scopes [ id ] = { models : { '' : true } } ;
99
+ expect ( inspectedApp . scopes [ id ] . models [ '' ] ) . toBeTruthy ( ) ;
100
+ port . onMessage . trigger ( JSON . stringify ( {
101
+ event : 'model:change' ,
102
+ data : {
103
+ id :id ,
104
+ path : ''
105
+ }
106
+ } ) ) ;
107
+
108
+ expect ( $browser . defer . flush ) . not . toThrow ( ) ;
109
+ expect ( inspectedApp . scopes [ id ] . models [ '' ] ) . toBeUndefined ( ) ;
110
+ } ) ;
111
+
112
+ it ( 'should track updates to scope descriptors' , function ( ) {
38
113
port . onMessage . trigger ( JSON . stringify ( { event : 'scope:new' , data : { child : 1 } } ) ) ;
39
- port . onMessage . trigger ( JSON . stringify ( { event : 'scope:link' , data : { id : 1 , descriptor : 'pasta' } } ) ) ;
40
- $browser . defer . flush ( ) ;
114
+ triggerAndFlush ( { event : 'scope:link' , data : { id : 1 , descriptor : 'pasta' } } ) ;
41
115
42
116
expect ( inspectedApp . scopes [ 1 ] . descriptor ) . toBe ( 'pasta' ) ;
43
- } ) ) ;
44
- it ( 'should broadcast message from $rootScope' , inject ( function ( $browser ) {
117
+ } ) ;
118
+
119
+ it ( 'should broadcast message from $rootScope' , function ( ) {
45
120
var message = { event : 'scope:new' , data : { child : 1 } } ;
46
- port . onMessage . trigger ( JSON . stringify ( message ) ) ;
47
- $browser . defer . flush ( ) ;
121
+ triggerAndFlush ( message ) ;
48
122
49
123
expect ( rootScope . $broadcast ) . toHaveBeenCalledWith ( message . event , message . data ) ;
50
- } ) ) ;
124
+ } ) ;
51
125
} ) ;
52
126
53
127
describe ( 'watch' , function ( ) {
0 commit comments