2016-10-04 23:02:11 +08:00
|
|
|
import {mount} from 'enzyme';
|
|
|
|
import {React, AccountStore, Account, Actions, MailRulesStore} from 'nylas-exports';
|
|
|
|
import DisabledMailRulesNotification from '../lib/items/disabled-mail-rules-notif';
|
|
|
|
|
|
|
|
describe("DisabledMailRulesNotification", function DisabledMailRulesNotifTests() {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(AccountStore, 'accounts').andReturn([
|
|
|
|
new Account({id: 'A', syncState: 'running', emailAddress: '123@gmail.com'}),
|
|
|
|
])
|
|
|
|
})
|
|
|
|
describe("When there is one disabled mail rule", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(MailRulesStore, "disabledRules").andReturn([{accountId: 'A'}])
|
|
|
|
this.notif = mount(<DisabledMailRulesNotification />)
|
|
|
|
})
|
|
|
|
it("displays a notification", () => {
|
2017-02-10 07:17:11 +08:00
|
|
|
expect(this.notif.find('.notification').exists()).toEqual(true);
|
2016-10-04 23:02:11 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
it("allows users to open the preferences", () => {
|
|
|
|
spyOn(Actions, "switchPreferencesTab")
|
|
|
|
spyOn(Actions, "openPreferences")
|
|
|
|
this.notif.find('#action-0').simulate('click');
|
|
|
|
expect(Actions.switchPreferencesTab).toHaveBeenCalledWith('Mail Rules', {accountId: 'A'})
|
|
|
|
expect(Actions.openPreferences).toHaveBeenCalled();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("When there are multiple disabled mail rules", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(MailRulesStore, "disabledRules").andReturn([{accountId: 'A'},
|
|
|
|
{accountId: 'A'}])
|
|
|
|
this.notif = mount(<DisabledMailRulesNotification />)
|
|
|
|
})
|
|
|
|
it("displays a notification", () => {
|
2017-02-10 07:17:11 +08:00
|
|
|
expect(this.notif.find('.notification').exists()).toEqual(true);
|
2016-10-04 23:02:11 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
it("allows users to open the preferences", () => {
|
|
|
|
spyOn(Actions, "switchPreferencesTab")
|
|
|
|
spyOn(Actions, "openPreferences")
|
|
|
|
this.notif.find('#action-0').simulate('click');
|
|
|
|
expect(Actions.switchPreferencesTab).toHaveBeenCalledWith('Mail Rules', {accountId: 'A'})
|
|
|
|
expect(Actions.openPreferences).toHaveBeenCalled();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("When there are no disabled mail rules", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(MailRulesStore, "disabledRules").andReturn([])
|
|
|
|
this.notif = mount(<DisabledMailRulesNotification />)
|
|
|
|
})
|
|
|
|
it("does not display a notification", () => {
|
2017-02-10 07:17:11 +08:00
|
|
|
expect(this.notif.find('.notification').exists()).toEqual(false);
|
2016-10-04 23:02:11 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|