Mailspring/internal_packages/notifications/spec/default-client-notif-spec.jsx
Ben Gotow 8df4f6d744 feat(win32): Allow N1 to become the system-wide mailto: handler
Summary: This will address the longstanding concern in #417

Test Plan: No new tests

Reviewers: juan, evan

Reviewed By: juan, evan

Maniphest Tasks: T7065

Differential Revision: https://phab.nylas.com/D3322
2016-10-12 16:05:36 -07:00

73 lines
2.5 KiB
JavaScript

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