2016-03-15 08:15:34 +08:00
|
|
|
import {ipcRenderer} from 'electron';
|
2016-03-22 08:36:18 +08:00
|
|
|
import {BadgeStore} from 'nylas-exports';
|
2016-03-15 08:15:34 +08:00
|
|
|
import SystemTrayIconStore from '../lib/system-tray-icon-store';
|
|
|
|
|
|
|
|
const {
|
|
|
|
INBOX_ZERO_ICON,
|
|
|
|
INBOX_UNREAD_ICON,
|
|
|
|
INBOX_UNREAD_ALT_ICON,
|
|
|
|
} = SystemTrayIconStore;
|
|
|
|
|
|
|
|
|
2016-05-05 05:03:15 +08:00
|
|
|
describe('SystemTrayIconStore', function systemTrayIconStore() {
|
2016-05-06 13:30:34 +08:00
|
|
|
beforeEach(() => {
|
2016-03-15 08:15:34 +08:00
|
|
|
spyOn(ipcRenderer, 'send')
|
|
|
|
this.iconStore = new SystemTrayIconStore()
|
|
|
|
});
|
|
|
|
|
|
|
|
function getCallData() {
|
|
|
|
const {args} = ipcRenderer.send.calls[0]
|
|
|
|
return {iconPath: args[1], isTemplateImg: args[3]}
|
|
|
|
}
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
describe('_getIconImageData', () => {
|
|
|
|
it('shows inbox zero icon when isInboxZero and window is focused', () => {
|
2016-03-22 08:36:18 +08:00
|
|
|
const {iconPath, isTemplateImg} = this.iconStore._getIconImageData(true, false)
|
2016-03-15 08:15:34 +08:00
|
|
|
expect(iconPath).toBe(INBOX_ZERO_ICON)
|
|
|
|
expect(isTemplateImg).toBe(true)
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('shows inbox zero icon when isInboxZero and window is blurred', () => {
|
2016-03-22 08:36:18 +08:00
|
|
|
const {iconPath, isTemplateImg} = this.iconStore._getIconImageData(true, true)
|
2016-03-15 08:15:34 +08:00
|
|
|
expect(iconPath).toBe(INBOX_ZERO_ICON)
|
|
|
|
expect(isTemplateImg).toBe(true)
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('shows inbox full icon when not isInboxZero and window is focused', () => {
|
2016-03-22 08:36:18 +08:00
|
|
|
const {iconPath, isTemplateImg} = this.iconStore._getIconImageData(false, false)
|
2016-03-15 08:15:34 +08:00
|
|
|
expect(iconPath).toBe(INBOX_UNREAD_ICON)
|
|
|
|
expect(isTemplateImg).toBe(true)
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('shows inbox full /alt/ icon when not isInboxZero and window is blurred', () => {
|
2016-03-22 08:36:18 +08:00
|
|
|
const {iconPath, isTemplateImg} = this.iconStore._getIconImageData(false, true)
|
2016-03-15 08:15:34 +08:00
|
|
|
expect(iconPath).toBe(INBOX_UNREAD_ALT_ICON)
|
|
|
|
expect(isTemplateImg).toBe(false)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
describe('updating the icon based on focus and blur', () => {
|
|
|
|
it('always shows inbox full icon when the window gets focused', () => {
|
2016-03-22 08:36:18 +08:00
|
|
|
spyOn(BadgeStore, 'total').andReturn(1)
|
2016-03-15 08:15:34 +08:00
|
|
|
this.iconStore._onWindowFocus()
|
|
|
|
const {iconPath} = getCallData()
|
|
|
|
expect(iconPath).toBe(INBOX_UNREAD_ICON)
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('shows inbox full /alt/ icon ONLY when window is currently blurred and total count changes', () => {
|
2016-03-15 08:15:34 +08:00
|
|
|
this.iconStore._windowBlurred = false
|
|
|
|
this.iconStore._onWindowBlur()
|
|
|
|
expect(ipcRenderer.send).not.toHaveBeenCalled()
|
|
|
|
|
2016-03-22 08:36:18 +08:00
|
|
|
// BadgeStore triggers a change
|
|
|
|
spyOn(BadgeStore, 'total').andReturn(1)
|
2016-03-15 08:15:34 +08:00
|
|
|
this.iconStore._updateIcon()
|
|
|
|
|
|
|
|
const {iconPath} = getCallData()
|
|
|
|
expect(iconPath).toBe(INBOX_UNREAD_ALT_ICON)
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('does not show inbox full /alt/ icon when window is currently focused and total count changes', () => {
|
2016-03-15 08:15:34 +08:00
|
|
|
this.iconStore._windowBlurred = false
|
|
|
|
|
2016-03-22 08:36:18 +08:00
|
|
|
// BadgeStore triggers a change
|
|
|
|
spyOn(BadgeStore, 'total').andReturn(1)
|
2016-03-15 08:15:34 +08:00
|
|
|
this.iconStore._updateIcon()
|
|
|
|
|
|
|
|
const {iconPath} = getCallData()
|
|
|
|
expect(iconPath).toBe(INBOX_UNREAD_ICON)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|