Mailspring/app/internal_packages/notifications/specs/disabled-mail-rules-notif-spec.jsx

57 lines
2.2 KiB
React
Raw Normal View History

2017-09-27 02:33:08 +08:00
import { mount } from 'enzyme';
import { React, AccountStore, Account, Actions, MailRulesStore } from 'mailspring-exports';
import DisabledMailRulesNotification from '../lib/items/disabled-mail-rules-notif';
2017-09-27 02:33:08 +08:00
describe('DisabledMailRulesNotification', function DisabledMailRulesNotifTests() {
beforeEach(() => {
spyOn(AccountStore, 'accounts').andReturn([
2017-09-27 02:33:08 +08:00
new Account({ id: 'A', syncState: Account.SYNC_STATE_OK, emailAddress: '123@gmail.com' }),
]);
});
describe('When there is one disabled mail rule', () => {
beforeEach(() => {
2017-09-27 02:33:08 +08:00
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);
2017-09-27 02:33:08 +08:00
});
2017-09-27 02:33:08 +08:00
it('allows users to open the preferences', () => {
spyOn(Actions, 'switchPreferencesTab');
spyOn(Actions, 'openPreferences');
this.notif.find('#action-0').simulate('click');
2017-09-27 02:33:08 +08:00
expect(Actions.switchPreferencesTab).toHaveBeenCalledWith('Mail Rules', { accountId: 'A' });
expect(Actions.openPreferences).toHaveBeenCalled();
2017-09-27 02:33:08 +08:00
});
});
2017-09-27 02:33:08 +08:00
describe('When there are multiple disabled mail rules', () => {
beforeEach(() => {
2017-09-27 02:33:08 +08:00
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);
2017-09-27 02:33:08 +08:00
});
2017-09-27 02:33:08 +08:00
it('allows users to open the preferences', () => {
spyOn(Actions, 'switchPreferencesTab');
spyOn(Actions, 'openPreferences');
this.notif.find('#action-0').simulate('click');
2017-09-27 02:33:08 +08:00
expect(Actions.switchPreferencesTab).toHaveBeenCalledWith('Mail Rules', { accountId: 'A' });
expect(Actions.openPreferences).toHaveBeenCalled();
2017-09-27 02:33:08 +08:00
});
});
2017-09-27 02:33:08 +08:00
describe('When there are no disabled mail rules', () => {
beforeEach(() => {
2017-09-27 02:33:08 +08:00
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);
2017-09-27 02:33:08 +08:00
});
});
});