@@ -66,6 +66,80 @@ define(function (require, exports, module) {
6666 SpecRunnerUtils . closeTestWindow ( ) ;
6767 } ) ;
6868
69+ describe ( "Remove Menu" , function ( ) {
70+ it ( "should add then remove new menu to menu bar with a menu id" , function ( ) {
71+ runs ( function ( ) {
72+ var menuId = "Menu-test" ;
73+ Menus . addMenu ( "Custom" , menuId ) ;
74+
75+ var menu = Menus . getMenu ( menuId ) ;
76+ expect ( menu ) . toBeTruthy ( ) ;
77+
78+ Menus . removeMenu ( menuId ) ;
79+ menu = Menus . getMenu ( menuId ) ;
80+ expect ( menu ) . toBeUndefined ( ) ;
81+ } ) ;
82+ } ) ;
83+
84+ it ( "should remove all menu items and dividers in the menu when removing the menu" , function ( ) {
85+ runs ( function ( ) {
86+ var menuId = "Menu-test" ;
87+ Menus . addMenu ( "Custom" , menuId ) ;
88+
89+ var menu = Menus . getMenu ( menuId ) ;
90+ expect ( menu ) . toBeTruthy ( ) ;
91+
92+ var commandId = "Remove-Menu-test.Item-1" ;
93+ CommandManager . register ( "Remove Menu Test Command" , commandId , function ( ) { } ) ;
94+
95+ var menuItem = menu . addMenuItem ( commandId ) ;
96+ expect ( menuItem ) . toBeTruthy ( ) ;
97+
98+ var menuItemId = menuItem . id ;
99+ expect ( menuItemId ) . toBeTruthy ( ) ;
100+
101+ var menuDivider = menu . addMenuDivider ( ) ;
102+ expect ( menuDivider ) . toBeTruthy ( ) ;
103+
104+ var menuDividerId = menuDivider . id ;
105+ expect ( menuDividerId ) . toBeTruthy ( ) ;
106+
107+ menuItem = Menus . getMenuItem ( menuItemId ) ;
108+ expect ( menuItem ) . toBeTruthy ( ) ;
109+
110+ menuDivider = Menus . getMenuItem ( menuDividerId ) ;
111+ expect ( menuDivider ) . toBeTruthy ( ) ;
112+
113+ Menus . removeMenu ( menuId ) ;
114+
115+ menu = Menus . getMenu ( menuId ) ;
116+ expect ( menu ) . toBeUndefined ( ) ;
117+
118+ menuItem = Menus . getMenuItem ( menuItemId ) ;
119+ expect ( menuItem ) . toBeUndefined ( ) ;
120+
121+ menuDivider = Menus . getMenuItem ( menuDividerId ) ;
122+ expect ( menuDivider ) . toBeUndefined ( ) ;
123+ } ) ;
124+ } ) ;
125+
126+ it ( "should gracefully handle someone trying to remove a menu that doesn't exist" , function ( ) {
127+ runs ( function ( ) {
128+ var menuId = "Menu-test" ;
129+
130+ Menus . removeMenu ( menuId ) ;
131+ expect ( Menus ) . toBeTruthy ( ) ; // Verify that we got this far...
132+ } ) ;
133+ } ) ;
134+
135+ it ( "should gracefully handle someone trying to remove a menu without supplying the id" , function ( ) {
136+ runs ( function ( ) {
137+ Menus . removeMenu ( ) ;
138+ expect ( Menus ) . toBeTruthy ( ) ; // Verify that we got this far...
139+ } ) ;
140+ } ) ;
141+ } ) ;
142+
69143
70144 describe ( "Context Menus" , function ( ) {
71145 it ( "register a context menu" , function ( ) {
@@ -439,7 +513,7 @@ define(function (require, exports, module) {
439513 } ) ;
440514 } ) ;
441515
442- it ( "should add menu items to beginnging and end of menu section" , function ( ) {
516+ it ( "should add menu items to beginning and end of menu section" , function ( ) {
443517 // set up test menu and menu items
444518 CommandManager . register ( "Brackets Test Command Section 10" , "Menu-test.command10" , function ( ) { } ) ;
445519 CommandManager . register ( "Brackets Test Command Section 11" , "Menu-test.command11" , function ( ) { } ) ;
@@ -647,6 +721,63 @@ define(function (require, exports, module) {
647721 } ) ;
648722
649723
724+ describe ( "Remove Menu Divider" , function ( ) {
725+
726+ function menuDividerDOM ( menuItemId ) {
727+ return testWindow . $ ( "#" + menuItemId ) ;
728+ }
729+
730+ it ( "should add then remove new menu divider to empty menu" , function ( ) {
731+ runs ( function ( ) {
732+ var menuId = "menu-custom-removeMenuDivider-1" ;
733+ var menu = Menus . addMenu ( "Custom" , menuId ) ;
734+
735+ var menuDivider = menu . addMenuDivider ( ) ;
736+ expect ( menuDivider ) . toBeTruthy ( ) ;
737+
738+ var $listItems = menuDividerDOM ( menuDivider . id ) ;
739+ expect ( $listItems . length ) . toBe ( 1 ) ;
740+
741+ menu . removeMenuDivider ( menuDivider . id ) ;
742+ $listItems = menuDividerDOM ( menuDivider . id ) ;
743+ expect ( $listItems . length ) . toBe ( 0 ) ;
744+ } ) ;
745+ } ) ;
746+
747+ it ( "should gracefully handle someone trying to remove a menu divider without supplying the id" , function ( ) {
748+ runs ( function ( ) {
749+ var menuId = "menu-custom-removeMenuDivider-2" ;
750+ var menu = Menus . addMenu ( "Custom" , menuId ) ;
751+
752+ menu . removeMenuDivider ( ) ;
753+ expect ( menu ) . toBeTruthy ( ) ; // Verify that we got this far...
754+ } ) ;
755+ } ) ;
756+
757+ it ( "should gracefully handle someone trying to remove a menu divider with an invalid id" , function ( ) {
758+ runs ( function ( ) {
759+ var menuId = "menu-custom-removeMenuDivider-3" ;
760+ var menu = Menus . addMenu ( "Custom" , menuId ) ;
761+
762+ menu . removeMenuDivider ( "foo" ) ;
763+ expect ( menu ) . toBeTruthy ( ) ; // Verify that we got this far...
764+ } ) ;
765+ } ) ;
766+
767+ it ( "should gracefully handle someone trying to remove a menu item that is not a divider" , function ( ) {
768+ runs ( function ( ) {
769+ var menuId = "menu-custom-removeMenuDivider-4" ;
770+ var menu = Menus . addMenu ( "Custom" , menuId ) ;
771+ var menuItemId = "menu-test-removeMenuDivider1" ;
772+ var menuItem = menu . addMenuItem ( menuItemId ) ;
773+
774+ menu . removeMenuDivider ( menuItemId ) ;
775+ expect ( menu ) . toBeTruthy ( ) ; // Verify that we got this far...
776+ } ) ;
777+ } ) ;
778+ } ) ;
779+
780+
650781 describe ( "Remove Menu" , function ( ) {
651782
652783 function menuDOM ( menuId ) {
@@ -675,10 +806,8 @@ define(function (require, exports, module) {
675806 } ) ;
676807 } ) ;
677808
678- it ( "should gracefully handle someone trying to remove a menu without supply the id" , function ( ) {
809+ it ( "should gracefully handle someone trying to remove a menu without supplying the id" , function ( ) {
679810 runs ( function ( ) {
680- var menuId = "Menu-test" ;
681-
682811 Menus . removeMenu ( ) ;
683812 expect ( Menus ) . toBeTruthy ( ) ; // Verify that we got this far...
684813 } ) ;
0 commit comments