@@ -10,11 +10,9 @@ define([
10
10
] , function ( wysiwygAdapter , _ , tinyMCE ) {
11
11
'use strict' ;
12
12
13
- var obj , originalVarienEvents ;
13
+ var obj ;
14
14
15
15
beforeEach ( function ( ) {
16
- // Store original varienEvents if it exists
17
- originalVarienEvents = window . varienEvents ;
18
16
19
17
/**
20
18
* Dummy constructor to use for instantiation
@@ -25,115 +23,20 @@ define([
25
23
Constr . prototype = wysiwygAdapter ;
26
24
27
25
obj = new Constr ( ) ;
28
-
29
- // Ensure varienEvents is available, create comprehensive mock
30
- if ( typeof window . varienEvents === 'undefined' ) {
31
- window . varienEvents = function ( ) {
32
- this . arrEvents = { } ;
33
- this . attachEvent = function ( eventName , callback ) {
34
- try {
35
- if ( ! this . arrEvents [ eventName ] ) {
36
- this . arrEvents [ eventName ] = [ ] ;
37
- }
38
- this . arrEvents [ eventName ] . push ( callback ) ;
39
- } catch ( e ) {
40
- console . warn ( 'Error in attachEvent:' , e ) ;
41
- }
42
- } ;
43
- this . fireEvent = function ( eventName , data ) {
44
- try {
45
- if ( this . arrEvents [ eventName ] ) {
46
- this . arrEvents [ eventName ] . forEach ( function ( callback ) {
47
- if ( typeof callback === 'function' ) {
48
- callback ( data ) ;
49
- }
50
- } ) ;
51
- }
52
- } catch ( e ) {
53
- console . warn ( 'Error in fireEvent:' , e ) ;
54
- }
55
- } ;
56
- // Add other methods that might be needed
57
- this . removeEvent = function ( eventName , callback ) {
58
- if ( this . arrEvents [ eventName ] ) {
59
- var index = this . arrEvents [ eventName ] . indexOf ( callback ) ;
60
- if ( index > - 1 ) {
61
- this . arrEvents [ eventName ] . splice ( index , 1 ) ;
62
- }
63
- }
64
- } ;
65
- } ;
66
- }
67
-
68
- try {
69
- obj . eventBus = new window . varienEvents ( ) ;
70
- obj . initialize ( 'id' , {
71
- 'store_id' : 0 ,
72
- 'tinymce' : {
73
- 'content_css' : ''
74
- } ,
75
- 'files_browser_window_url' : 'url'
76
- } ) ;
77
-
78
- // Try to setup, but handle any script errors that occur
79
- if ( typeof obj . setup === 'function' ) {
80
- obj . setup ( ) ;
81
- } else {
82
- console . warn ( 'obj.setup is not a function, skipping setup' ) ;
83
- }
84
- } catch ( error ) {
85
- console . warn ( 'Error during tinymceAdapter initialization:' , error ) ;
86
- // Continue with test even if setup fails
87
- }
88
- } ) ;
89
-
90
- afterEach ( function ( ) {
91
- // Restore original varienEvents or remove mock
92
- if ( originalVarienEvents ) {
93
- window . varienEvents = originalVarienEvents ;
94
- } else if ( window . varienEvents ) {
95
- delete window . varienEvents ;
96
- }
26
+ obj . eventBus = new window . varienEvents ( ) ;
27
+ obj . initialize ( 'id' , {
28
+ 'store_id' : 0 ,
29
+ 'tinymce' : {
30
+ 'content_css' : ''
31
+ } ,
32
+ 'files_browser_window_url' : 'url'
33
+ } ) ;
34
+ obj . setup ( ) ;
97
35
} ) ;
98
36
99
37
describe ( '"openFileBrowser" method' , function ( ) {
100
38
it ( 'Opens file browser to given instance' , function ( ) {
101
- try {
102
- // Check if the object was properly initialized
103
- if ( ! obj || ! obj . eventBus ) {
104
- pending ( 'tinymceAdapter object not properly initialized' ) ;
105
- return ;
106
- }
107
-
108
- // Ensure the eventBus and arrEvents exist before accessing
109
- if ( obj . eventBus && obj . eventBus . arrEvents ) {
110
- // Check if the open_browser_callback event was registered
111
- var callbackEvents = obj . eventBus . arrEvents [ 'open_browser_callback' ] ;
112
- if ( callbackEvents && callbackEvents . length > 0 ) {
113
- expect ( _ . size ( callbackEvents ) ) . toBe ( 1 ) ;
114
- } else {
115
- // Event wasn't registered, possibly due to setup failure
116
- console . warn ( 'open_browser_callback event not found, setup may have failed' ) ;
117
- pending ( 'open_browser_callback event not registered - setup may have failed in test environment' ) ;
118
- }
119
- } else {
120
- // EventBus structure is not as expected
121
- console . warn ( 'EventBus arrEvents not found:' , obj . eventBus ) ;
122
- pending ( 'EventBus not properly structured in test environment' ) ;
123
- }
124
- } catch ( error ) {
125
- // Handle script errors that may occur
126
- if ( error && ( error . message === null || error . message === 'Script error.' ||
127
- error . message === '' ||
128
- ( typeof error . message === 'string' && error . message . includes ( 'Script error' ) ) ) ) {
129
- console . warn ( 'Script error in tinymceAdapter test, marking as pending:' , error ) ;
130
- pending ( 'Test pending due to script error in tinymceAdapter' ) ;
131
- } else {
132
- // Re-throw actual assertion failures
133
- console . error ( 'Unexpected error in tinymceAdapter test:' , error ) ;
134
- throw error ;
135
- }
136
- }
39
+ expect ( _ . size ( obj . eventBus . arrEvents [ 'open_browser_callback' ] ) ) . toBe ( 1 ) ;
137
40
} ) ;
138
41
} ) ;
139
42
0 commit comments