Mailspring/app/internal_packages/notifications/specs/default-client-notif-spec.jsx

77 lines
2.5 KiB
React
Raw Normal View History

2017-09-27 02:33:08 +08:00
import { mount } from 'enzyme';
import proxyquire from 'proxyquire';
import { React } from 'mailspring-exports';
let stubIsRegistered = null;
let stubRegister = () => {};
2017-09-27 02:33:08 +08:00
const patched = proxyquire('../lib/items/default-client-notif', {
'mailspring-exports': {
2017-09-27 02:33:08 +08:00
DefaultClientHelper: class {
constructor() {
this.isRegisteredForURLScheme = (urlScheme, callback) => {
callback(stubIsRegistered);
};
this.registerForURLScheme = urlScheme => {
stubRegister(urlScheme);
};
}
},
2017-09-27 02:33:08 +08:00
},
});
const DefaultClientNotification = patched.default;
const SETTINGS_KEY = 'mailto.prompted-about-default';
2017-09-27 02:33:08 +08:00
describe('DefaultClientNotif', function DefaultClientNotifTests() {
describe("when Mailspring isn't the default mail client", () => {
beforeEach(() => {
stubIsRegistered = false;
2017-09-27 02:33:08 +08:00
});
describe('when the user has already responded', () => {
beforeEach(() => {
2017-09-27 02:36:58 +08:00
spyOn(AppEnv.config, 'get').andReturn(true);
this.notif = mount(<DefaultClientNotification />);
2017-09-27 02:36:58 +08:00
expect(AppEnv.config.get).toHaveBeenCalledWith(SETTINGS_KEY);
});
2017-09-27 02:33:08 +08:00
it('renders nothing', () => {
2017-02-10 07:17:11 +08:00
expect(this.notif.find('.notification').exists()).toEqual(false);
});
});
2017-09-27 02:33:08 +08:00
describe('when the user has yet to respond', () => {
beforeEach(() => {
2017-09-27 02:36:58 +08:00
spyOn(AppEnv.config, 'get').andReturn(false);
this.notif = mount(<DefaultClientNotification />);
2017-09-27 02:36:58 +08:00
expect(AppEnv.config.get).toHaveBeenCalledWith(SETTINGS_KEY);
});
2017-09-27 02:33:08 +08:00
it('renders a notification', () => {
2017-02-10 07:17:11 +08:00
expect(this.notif.find('.notification').exists()).toEqual(true);
});
it('allows the user to set Mailspring as the default client', () => {
let scheme = null;
2017-09-27 02:33:08 +08:00
stubRegister = urlScheme => {
scheme = urlScheme;
};
this.notif.find('#action-0').simulate('click'); // Expects first action to set Mailspring as default
expect(scheme).toEqual('mailto');
});
2017-09-27 02:33:08 +08:00
it('allows the user to decline', () => {
2017-09-27 02:36:58 +08:00
spyOn(AppEnv.config, 'set');
this.notif.find('#action-1').simulate('click'); // Expects second action to decline
2017-09-27 02:36:58 +08:00
expect(AppEnv.config.set).toHaveBeenCalledWith(SETTINGS_KEY, true);
});
2017-09-27 02:33:08 +08:00
});
});
describe('when Mailspring is the default mail client', () => {
beforeEach(() => {
stubIsRegistered = true;
2017-09-27 02:33:08 +08:00
this.notif = mount(<DefaultClientNotification />);
});
it('renders nothing', () => {
2017-02-10 07:17:11 +08:00
expect(this.notif.find('.notification').exists()).toEqual(false);
});
2017-09-27 02:33:08 +08:00
});
});