-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make FileInputView extendible for adding custom menu items via menuName. REDMINE-20881
- Loading branch information
1 parent
75d6597
commit 0822db2
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import {DropDownMenuItems} from 'pageflow/editor/api/DropDownMenuItems'; | ||
|
||
import sinon from 'sinon'; | ||
|
||
describe('DropDownMenuItems', () => { | ||
describe('#register/#findAllByMenuName', () => { | ||
it( | ||
'allows getting a list of menu items by menu name', | ||
() => { | ||
var dropDownMenuItems = new DropDownMenuItems(); | ||
|
||
dropDownMenuItems.register({ | ||
name: 'custom', | ||
label: 'Custom Item', | ||
selected: () => { | ||
} | ||
}, { | ||
menuName: 'someMenu', | ||
}); | ||
|
||
var menuItem = dropDownMenuItems.findAllByMenuName('someMenu')[0]; | ||
|
||
expect(menuItem.name).toBe('custom'); | ||
} | ||
); | ||
|
||
it( | ||
'only returns the list of menu items for the specified menu name', | ||
() => { | ||
var dropDownMenuItems = new DropDownMenuItems(); | ||
|
||
dropDownMenuItems.register({ | ||
name: 'custom', | ||
label: 'Custom Item', | ||
selected: () => { | ||
} | ||
}, { | ||
menuName: 'someOtherMenu', | ||
}); | ||
|
||
var menuItems = dropDownMenuItems.findAllByMenuName('someMenu'); | ||
|
||
expect(menuItems.length).toBe(0); | ||
} | ||
); | ||
|
||
it( | ||
'allows registering multiple menu items per menu name', | ||
() => { | ||
var dropDownMenuItems = new DropDownMenuItems(); | ||
|
||
dropDownMenuItems.register({ | ||
name: 'custom1', | ||
label: 'Custom Item 1', | ||
selected: () => { | ||
} | ||
}, { | ||
menuName: 'someMenu', | ||
}); | ||
|
||
dropDownMenuItems.register({ | ||
name: 'custom2', | ||
label: 'Custom Item 2', | ||
selected: () => { | ||
} | ||
}, { | ||
menuName: 'someMenu', | ||
}); | ||
|
||
var menuItems = dropDownMenuItems.findAllByMenuName('someMenu'); | ||
|
||
expect(menuItems.length).toBe(2); | ||
} | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {Object} from 'pageflow/ui'; | ||
|
||
export const DropDownMenuItems = Object.extend({ | ||
initialize: function() { | ||
this.menuItems = {}; | ||
}, | ||
register: function(menuItem, {menuName}) { | ||
this.menuItems[menuName] = this.menuItems[menuName] || []; | ||
this.menuItems[menuName].push(menuItem); | ||
}, | ||
findAllByMenuName: function(menuName) { | ||
return this.menuItems[menuName] || []; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters