11describe ( 'uiAce' , function ( ) {
22 'use strict' ;
33
4- // declare these up here to be global to all tests
5- var scope , $compile , uiConfig ;
6-
7- beforeEach ( module ( 'ui.ace' ) ) ;
8- beforeEach ( inject ( function ( uiAceConfig ) {
9- uiConfig = uiAceConfig ;
10- uiConfig . ace = { showGutter : false } ;
11- } ) ) ;
12-
13- // inject in angular constructs. Injector knows about leading/trailing underscores and does the right thing
14- // otherwise, you would need to inject these into each test
15- beforeEach ( inject ( function ( _$rootScope_ , _$compile_ ) {
16- scope = _$rootScope_ . $new ( ) ;
17- $compile = _$compile_ ;
18- } ) ) ;
4+ var scope , $compile ,
5+ uiConfig ;
6+
7+ beforeEach ( function ( ) {
8+
9+ module ( 'ui.ace' ) ;
10+
11+ inject ( function ( _$rootScope_ , _$compile_ , uiAceConfig ) {
12+ scope = _$rootScope_ . $new ( ) ;
13+ $compile = _$compile_ ;
14+ uiConfig = uiAceConfig ;
15+ uiConfig . ace = { showGutter : false } ;
16+ } ) ;
17+ } ) ;
1918
2019 afterEach ( function ( ) {
2120 uiConfig = { } ;
2221 } ) ;
2322
24- describe ( 'behavior ' , function ( ) {
25- var _ace ;
23+ describe ( 'require ' , function ( ) {
24+ var aceRequireFunction ;
2625
2726 beforeEach ( function ( ) {
28- _ace = window . ace ;
29- spyOn ( window . ace , 'require' ) ;
27+ aceRequireFunction = window . ace . edit ;
28+ window . ace . require = jasmine
29+ . createSpy ( 'window.ace.require' ) ;
3030 } ) ;
31- it ( 'should not call ace/config if a workerPath is not defined' , function ( ) {
32- $compile ( '<div ui-ace>' ) ( scope ) ;
33- expect ( _ace . require ) . not . toHaveBeenCalledWith ( ' ace/config' ) ;
31+
32+ afterEach ( function ( ) {
33+ window . ace . require = aceRequireFunction ;
3434 } ) ;
35- } ) ;
3635
37- describe ( 'behavior' , function ( ) {
38- var _ace , _config ;
36+ it ( 'should not call window.ace.require if there is no "require" option' , function ( ) {
37+ $compile ( '<div ui-ace>' ) ( scope ) ;
38+ expect ( window . ace . require ) . not . toHaveBeenCalled ( ) ;
39+ } ) ;
3940
40- beforeEach ( function ( ) {
41- _ace = window . ace ;
42- _config = {
43- set : function ( ) { return true ; }
44- } ;
45- spyOn ( window . ace , 'require' ) . andReturn ( _config ) ;
41+ it ( 'should not call ace/config if a workerPath is not defined' , function ( ) {
42+ $compile ( '<div ui-ace>' ) ( scope ) ;
43+ expect ( window . ace . require ) . not . toHaveBeenCalledWith ( 'ace/config' ) ;
4644 } ) ;
45+
4746 it ( 'should call ace/config if a workerPath is defined' , function ( ) {
47+ window . ace . require
48+ . and . returnValue ( {
49+ set : function ( ) { }
50+ } ) ;
51+ ////
4852 $compile ( '<div ui-ace=\'{ workerPath: "/path/to/ace" }\'>' ) ( scope ) ;
49- expect ( _ace . require ) . toHaveBeenCalledWith ( 'ace/config' ) ;
53+ expect ( window . ace . require ) . toHaveBeenCalledWith ( 'ace/config' ) ;
5054 } ) ;
51- } ) ;
5255
53- describe ( 'behavior' , function ( ) {
54- var _ace , _config ;
55-
56- beforeEach ( function ( ) {
57- _ace = window . ace ;
58- _config = {
59- set : function ( ) { return true ; }
60- } ;
61- spyOn ( window . ace , 'require' ) . andReturn ( _config ) ;
62- spyOn ( _config , 'set' ) ;
63- } ) ;
6456 it ( 'should call "set" if workerPath is defined' , function ( ) {
57+ var _config = jasmine . createSpyObj ( 'config' , [ 'set' ] ) ;
58+ window . ace . require . and . returnValue ( _config ) ;
59+ ////
6560 $compile ( '<div ui-ace=\'{ workerPath: "/path/to/ace" }\'>' ) ( scope ) ;
6661 expect ( _config . set ) . toHaveBeenCalled ( ) ;
6762 } ) ;
68- } ) ;
69-
70- describe ( 'behavior' , function ( ) {
71- var _ace ;
7263
73- beforeEach ( function ( ) {
74- _ace = window . ace ;
75- spyOn ( window . ace , 'require' ) ;
76- } ) ;
77- it ( 'should not call window.ace.require if there is no "require" option' , function ( ) {
78- $compile ( '<div ui-ace>' ) ( scope ) ;
79- expect ( _ace . require ) . not . toHaveBeenCalled ( ) ;
80- } ) ;
81- } ) ;
82-
83- describe ( 'behavior' , function ( ) {
84- var _ace ;
85-
86- beforeEach ( function ( ) {
87- _ace = window . ace ;
88- spyOn ( window . ace , 'require' ) ;
89- } ) ;
9064 it ( 'should call "window.ace.require" for each option in "require"' , function ( ) {
9165 $compile ( '<div ui-ace=\'{ require: ["ace/ext/language_tools", "ace/ext/static_highlight"]}\'>' ) ( scope ) ;
92- expect ( _ace . require ) . toHaveBeenCalled ( ) ;
93- expect ( _ace . require . callCount ) . toEqual ( 2 ) ;
66+ expect ( window . ace . require ) . toHaveBeenCalled ( ) ;
67+ expect ( window . ace . require . calls . count ( ) ) . toEqual ( 2 ) ;
9468 } ) ;
9569 } ) ;
9670
97- describe ( 'behavior ' , function ( ) {
98- var _ace ;
71+ describe ( 'options ' , function ( ) {
72+ var _ace , aceEditFunction ;
9973
10074 beforeEach ( function ( ) {
101- var aceEditFunction = window . ace . edit ;
102- spyOn ( window . ace , 'edit' ) . andCallFake ( function ( ) {
103- _ace = aceEditFunction . apply ( this , arguments ) ;
104- return _ace ;
105- } ) ;
106- } ) ;
107- it ( 'should not call "setOption" if no "advanced" options are given.' , function ( ) {
108- $compile ( '<div ui-ace>' ) ( scope ) ;
109- var session = _ace . getSession ( ) ;
110- spyOn ( session , 'setOption' ) ;
111- expect ( session . setOption ) . not . toHaveBeenCalled ( ) ;
75+ aceEditFunction = window . ace . edit ;
76+ window . ace . edit = jasmine
77+ . createSpy ( 'window.ace.edit' )
78+ . and . callFake ( function ( ) {
79+ _ace = aceEditFunction . apply ( this , arguments ) ;
80+ _ace . setOption = jasmine
81+ . createSpy ( 'ace.setOption' )
82+ . and . callThrough ( ) ;
83+ return _ace ;
84+ } ) ;
11285 } ) ;
113- } ) ;
114-
115- describe ( 'behavior' , function ( ) {
116- var _ace ;
11786
118- beforeEach ( function ( ) {
119- var aceEditFunction = window . ace . edit ;
120- spyOn ( window . ace , 'edit' ) . andCallFake ( function ( ) {
121- _ace = aceEditFunction . apply ( this , arguments ) ;
122- return _ace ;
123- } ) ;
87+ afterEach ( function ( ) {
88+ window . ace . edit = aceEditFunction ;
12489 } ) ;
90+
12591 it ( 'Given advanced option is null if not defined.' , function ( ) {
12692 $compile ( '<div ui-ace>' ) ( scope ) ;
127- var session = _ace . getSession ( ) ;
128- spyOn ( session , 'getOption' ) ;
129- expect ( session . getOption ) . toBeDefined ( ) ;
130- expect ( session . getOption ( 'enableSnippets' ) ) . not . toBeDefined ( ) ;
93+ expect ( _ace . setOption . calls . count ( ) ) . toEqual ( 0 ) ;
13194 } ) ;
132- } ) ;
133-
134- describe ( 'behavior' , function ( ) {
135- var _ace ;
13695
137- beforeEach ( function ( ) {
138- var aceEditFunction = window . ace . edit ;
139- spyOn ( window . ace , 'edit' ) . andCallFake ( function ( ) {
140- _ace = aceEditFunction . apply ( this , arguments ) ;
141- return _ace ;
142- } ) ;
143- } ) ;
14496 it ( 'given advanced options are properly defined.' , function ( ) {
14597 $compile ( '<div ui-ace=\'{ advanced: { enableSnippets: true } }\'>' ) ( scope ) ;
146- var session = _ace . getSession ( ) ;
147- spyOn ( session , 'getOption' ) ;
148- expect ( session . getOption ) . toBeDefined ( ) ;
149- expect ( session . getOption ( 'enableSnippets' ) ) . not . toBe ( null ) ;
98+ expect ( _ace . setOption . calls . count ( ) ) . toEqual ( 1 ) ;
99+ expect ( _ace . setOption ) . toHaveBeenCalledWith ( 'enableSnippets' , true ) ;
150100 } ) ;
151101 } ) ;
152102
153- describe ( 'behavior' , function ( ) {
103+ describe ( 'basic behavior' , function ( ) {
154104
155105 it ( 'should not throw an error when window.ace is defined' , function ( ) {
156106 function compile ( ) {
@@ -160,7 +110,6 @@ describe('uiAce', function () {
160110 expect ( compile ) . not . toThrow ( ) ;
161111 } ) ;
162112
163-
164113 it ( 'should watch the uiAce attribute' , function ( ) {
165114 spyOn ( scope , '$watch' ) ;
166115 $compile ( '<div ui-ace ng-model="foo">' ) ( scope ) ;
@@ -169,15 +118,20 @@ describe('uiAce', function () {
169118 } ) ;
170119
171120 describe ( 'instance' , function ( ) {
172- var _ace ;
173-
121+ var _ace , aceEditFunction ;
174122
175123 beforeEach ( function ( ) {
176- var aceEditFunction = window . ace . edit ;
177- spyOn ( window . ace , 'edit' ) . andCallFake ( function ( ) {
178- _ace = aceEditFunction . apply ( this , arguments ) ;
179- return _ace ;
180- } ) ;
124+ aceEditFunction = window . ace . edit ;
125+ window . ace . edit = jasmine
126+ . createSpy ( 'window.ace.edit' )
127+ . and . callFake ( function ( ) {
128+ _ace = aceEditFunction . apply ( this , arguments ) ;
129+ return _ace ;
130+ } ) ;
131+ } ) ;
132+
133+ afterEach ( function ( ) {
134+ window . ace . edit = aceEditFunction ;
181135 } ) ;
182136
183137 it ( 'should call ace.edit' , function ( ) {
@@ -286,8 +240,10 @@ describe('uiAce', function () {
286240
287241 it ( 'should call destroy when the element is removed' , function ( ) {
288242 var element = $compile ( '<div ui-ace ng-model="foo">' ) ( scope ) ;
289- spyOn ( _ace , 'destroy' ) . andCallThrough ( ) ;
290- spyOn ( _ace . session , '$stopWorker' ) . andCallThrough ( ) ;
243+ _ace . destroy = jasmine . createSpy ( 'ace.destroy' )
244+ . and . callThrough ( ) ;
245+ _ace . session . $stopWorker = jasmine . createSpy ( 'ace.session.$stopWorker' )
246+ . and . callThrough ( ) ;
291247
292248 element . remove ( ) ;
293249 scope . $apply ( ) ;
0 commit comments