diff --git a/spec/api-menu-item-spec.ts b/spec/api-menu-item-spec.ts index 9454544243..9632138ff5 100644 --- a/spec/api-menu-item-spec.ts +++ b/spec/api-menu-item-spec.ts @@ -616,4 +616,59 @@ describe('MenuItems', () => { expect(menu._getAcceleratorTextAt(5)).to.equal('Ctrl+?'); }); }); + + ifdescribe(process.platform === 'darwin')('MenuItem.badge', () => { + it('should set badge from constructor options', () => { + const item = new MenuItem({ + label: 'test', + badge: { type: 'alerts', count: 3 } + }); + + expect(item.badge).to.deep.equal({ type: 'alerts', count: 3 }); + }); + + it('should support all badge types', () => { + const alerts = new MenuItem({ label: 'a', badge: { type: 'alerts', count: 1 } }); + const updates = new MenuItem({ label: 'b', badge: { type: 'updates', count: 2 } }); + const newItems = new MenuItem({ label: 'c', badge: { type: 'new-items', count: 5 } }); + const custom = new MenuItem({ label: 'd', badge: { type: 'none', content: 'Custom' } }); + + expect(alerts.badge).to.deep.equal({ type: 'alerts', count: 1 }); + expect(updates.badge).to.deep.equal({ type: 'updates', count: 2 }); + expect(newItems.badge).to.deep.equal({ type: 'new-items', count: 5 }); + expect(custom.badge).to.deep.equal({ type: 'none', content: 'Custom' }); + }); + + it('should allow dynamic badge updates', () => { + const item = new MenuItem({ + label: 'test', + badge: { type: 'alerts', count: 1 } + }); + + item.badge = { type: 'updates', count: 10 }; + expect(item.badge).to.deep.equal({ type: 'updates', count: 10 }); + }); + + it('should have undefined badge when not set', () => { + const item = new MenuItem({ label: 'test' }); + expect(item.badge).to.be.undefined(); + }); + + it('should set badge on items added to a menu', () => { + const menu = Menu.buildFromTemplate([ + { label: 'test', badge: { type: 'alerts', count: 3 } } + ]); + + expect(menu.items[0].badge).to.deep.equal({ type: 'alerts', count: 3 }); + }); + + it('should update badge after item is added to a menu', () => { + const menu = Menu.buildFromTemplate([ + { label: 'test', badge: { type: 'alerts', count: 1 } } + ]); + + menu.items[0].badge = { type: 'updates', count: 5 }; + expect(menu.items[0].badge).to.deep.equal({ type: 'updates', count: 5 }); + }); + }); }); diff --git a/spec/ts-smoke/electron/main.ts b/spec/ts-smoke/electron/main.ts index 0640727f01..ebfd58cdbd 100644 --- a/spec/ts-smoke/electron/main.ts +++ b/spec/ts-smoke/electron/main.ts @@ -633,6 +633,28 @@ menuItem.click = (passedMenuItem: Electron.MenuItem, browserWindow: Electron.Bro console.log('click', passedMenuItem, browserWindow); }; +const badgedItem = new MenuItem({ + label: 'Alerts', + badge: { type: 'alerts', count: 3 } +}); +console.log(badgedItem.badge); + +const customBadgeItem = new MenuItem({ + label: 'Custom', + badge: { type: 'none', content: 'New' } +}); +customBadgeItem.badge = { type: 'updates', count: 5 }; + +const updatesItem = new MenuItem({ + label: 'Updates', + badge: { type: 'updates', count: 10 } +}); + +const newItemsBadge = new MenuItem({ + label: 'New Items', + badge: { type: 'new-items', count: 1 } +}); + // menu // https://github.com/electron/electron/blob/main/docs/api/menu.md