@@ -173,5 +173,115 @@ define(function (require, exports, module) {
173173 CommandManager . execute ( commandID ) ;
174174 expect ( receivedEvent ) . not . toBeDefined ( ) ;
175175 } ) ;
176+
177+ it ( "register command with htmlName option" , function ( ) {
178+ var htmlName = "Phoenix menu<i class='fa fa-car' style='margin-left: 4px;'></i>" ;
179+ var command = CommandManager . register ( "test command" , "test-htmlname-command" , testCommandFn , {
180+ htmlName : htmlName
181+ } ) ;
182+ expect ( command ) . toBeTruthy ( ) ;
183+ expect ( command . getName ( ) ) . toBe ( "test command" ) ;
184+ expect ( command . getOptions ( ) . htmlName ) . toBe ( htmlName ) ;
185+ } ) ;
186+
187+ it ( "getOptions should return empty object when no options provided" , function ( ) {
188+ var command = CommandManager . register ( "test command" , "test-no-options-command" , testCommandFn ) ;
189+ expect ( command ) . toBeTruthy ( ) ;
190+ expect ( command . getOptions ( ) ) . toEql ( { } ) ;
191+ } ) ;
192+
193+ it ( "getOptions should return options when provided" , function ( ) {
194+ var options = {
195+ eventSource : true ,
196+ htmlName : "Test <b>HTML</b> Name"
197+ } ;
198+ var command = CommandManager . register ( "test command" , "test-with-options-command" , testCommandFn , options ) ;
199+ expect ( command ) . toBeTruthy ( ) ;
200+ expect ( command . getOptions ( ) ) . toEql ( options ) ;
201+ } ) ;
202+
203+ it ( "setName with htmlName parameter and trigger nameChange" , function ( ) {
204+ var eventTriggered = false ;
205+ var command = CommandManager . register ( "test command" , "test-setname-html-command" , testCommandFn ) ;
206+ command . on ( "nameChange" , function ( ) {
207+ eventTriggered = true ;
208+ } ) ;
209+
210+ var newName = "new command name" ;
211+ var htmlName = "New <i class='fa fa-star'></i> Name" ;
212+ command . setName ( newName , htmlName ) ;
213+
214+ expect ( eventTriggered ) . toBeTruthy ( ) ;
215+ expect ( command . getName ( ) ) . toBe ( newName ) ;
216+ expect ( command . getOptions ( ) . htmlName ) . toBe ( htmlName ) ;
217+ } ) ;
218+
219+ it ( "setName should trigger nameChange when only htmlName changes" , function ( ) {
220+ var eventTriggered = false ;
221+ var command = CommandManager . register ( "test command" , "test-setname-htmlonly-command" , testCommandFn , {
222+ htmlName : "original html"
223+ } ) ;
224+ command . on ( "nameChange" , function ( ) {
225+ eventTriggered = true ;
226+ } ) ;
227+
228+ var newHtmlName = "Updated <span>HTML</span> Name" ;
229+ command . setName ( command . getName ( ) , newHtmlName ) ;
230+
231+ expect ( eventTriggered ) . toBeTruthy ( ) ;
232+ expect ( command . getOptions ( ) . htmlName ) . toBe ( newHtmlName ) ;
233+ } ) ;
234+
235+ it ( "setName should not trigger nameChange when name and htmlName are unchanged" , function ( ) {
236+ var eventTriggered = false ;
237+ var htmlName = "Same HTML Name" ;
238+ var command = CommandManager . register ( "test command" , "test-setname-same-command" , testCommandFn , {
239+ htmlName : htmlName
240+ } ) ;
241+ command . on ( "nameChange" , function ( ) {
242+ eventTriggered = true ;
243+ } ) ;
244+
245+ command . setName ( command . getName ( ) , htmlName ) ;
246+
247+ expect ( eventTriggered ) . toBeFalsy ( ) ;
248+ } ) ;
249+
250+ it ( "should handle edge cases for htmlName" , function ( ) {
251+ // Test with empty string htmlName
252+ var command1 = CommandManager . register ( "test command" , "test-empty-html-command" , testCommandFn , {
253+ htmlName : ""
254+ } ) ;
255+ expect ( command1 . getOptions ( ) . htmlName ) . toBe ( "" ) ;
256+
257+ // Test with null htmlName
258+ var command2 = CommandManager . register ( "test command" , "test-null-html-command" , testCommandFn , {
259+ htmlName : null
260+ } ) ;
261+ expect ( command2 . getOptions ( ) . htmlName ) . toBe ( null ) ;
262+
263+ // Test with undefined htmlName (should not be set)
264+ var command3 = CommandManager . register ( "test command" , "test-undefined-html-command" , testCommandFn , {
265+ htmlName : undefined
266+ } ) ;
267+ expect ( command3 . getOptions ( ) . htmlName ) . toBe ( undefined ) ;
268+ } ) ;
269+
270+ it ( "setName should handle edge cases for htmlName parameter" , function ( ) {
271+ var command = CommandManager . register ( "test command" , "test-setname-edge-command" , testCommandFn ) ;
272+
273+ // Test setting htmlName to empty string
274+ command . setName ( "test name" , "" ) ;
275+ expect ( command . getOptions ( ) . htmlName ) . toBe ( "" ) ;
276+
277+ // Test setting htmlName to null (should still trigger change if it was different)
278+ var eventTriggered = false ;
279+ command . on ( "nameChange" , function ( ) {
280+ eventTriggered = true ;
281+ } ) ;
282+ command . setName ( "test name" , null ) ;
283+ expect ( command . getOptions ( ) . htmlName ) . toBe ( null ) ;
284+ expect ( eventTriggered ) . toBeTruthy ( ) ;
285+ } ) ;
176286 } ) ;
177287} ) ;
0 commit comments