2016-05-14 05:16:54 +08:00
|
|
|
import {mount} from 'enzyme';
|
2017-01-25 23:12:09 +08:00
|
|
|
import {AccountStore, Account, Actions, React} from 'nylas-exports';
|
2016-05-14 05:16:54 +08:00
|
|
|
import {ipcRenderer} from 'electron';
|
|
|
|
|
2016-10-18 08:59:33 +08:00
|
|
|
import AccountErrorNotification from '../lib/items/account-error-notif';
|
|
|
|
|
2016-10-04 23:02:11 +08:00
|
|
|
describe("AccountErrorNotif", function AccountErrorNotifTests() {
|
2016-05-14 05:16:54 +08:00
|
|
|
describe("when one account is in the `invalid` state", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(AccountStore, 'accounts').andReturn([
|
|
|
|
new Account({id: 'A', syncState: 'invalid', emailAddress: '123@gmail.com'}),
|
|
|
|
new Account({id: 'B', syncState: 'running', emailAddress: 'other@gmail.com'}),
|
|
|
|
])
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders an error bar that mentions the account email", () => {
|
2016-10-04 23:02:11 +08:00
|
|
|
const notif = mount(<AccountErrorNotification />);
|
|
|
|
expect(notif.find('.title').text().indexOf('123@gmail.com') > 0).toBe(true);
|
2016-05-14 05:16:54 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("allows the user to refresh the account", () => {
|
2016-10-04 23:02:11 +08:00
|
|
|
const notif = mount(<AccountErrorNotification />);
|
2017-01-25 23:12:09 +08:00
|
|
|
spyOn(Actions, 'wakeLocalSyncWorkerForAccount').andReturn(Promise.resolve());
|
2016-10-04 23:02:11 +08:00
|
|
|
notif.find('#action-0').simulate('click'); // Expects first action to be the refresh action
|
2017-01-25 23:12:09 +08:00
|
|
|
expect(Actions.wakeLocalSyncWorkerForAccount).toHaveBeenCalled();
|
2016-05-14 05:16:54 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("allows the user to reconnect the account", () => {
|
2016-10-04 23:02:11 +08:00
|
|
|
const notif = mount(<AccountErrorNotification />);
|
2016-05-14 05:16:54 +08:00
|
|
|
spyOn(ipcRenderer, 'send');
|
2016-10-04 23:02:11 +08:00
|
|
|
notif.find('#action-1').simulate('click'); // Expects second action to be the reconnect action
|
2016-05-14 05:16:54 +08:00
|
|
|
expect(ipcRenderer.send).toHaveBeenCalledWith('command', 'application:add-account', {
|
|
|
|
existingAccount: AccountStore.accounts()[0],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when more than one account is in the `invalid` state", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(AccountStore, 'accounts').andReturn([
|
|
|
|
new Account({id: 'A', syncState: 'invalid', emailAddress: '123@gmail.com'}),
|
|
|
|
new Account({id: 'B', syncState: 'invalid', emailAddress: 'other@gmail.com'}),
|
|
|
|
])
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders an error bar", () => {
|
2016-10-04 23:02:11 +08:00
|
|
|
const notif = mount(<AccountErrorNotification />);
|
2017-01-25 23:12:09 +08:00
|
|
|
expect(notif.find('.notification').exists()).toEqual(true);
|
2016-05-14 05:16:54 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("allows the user to refresh the accounts", () => {
|
2016-10-04 23:02:11 +08:00
|
|
|
const notif = mount(<AccountErrorNotification />);
|
2017-01-25 23:12:09 +08:00
|
|
|
spyOn(Actions, 'wakeLocalSyncWorkerForAccount').andReturn(Promise.resolve());
|
2016-10-04 23:02:11 +08:00
|
|
|
notif.find('#action-0').simulate('click'); // Expects first action to be the refresh action
|
2017-01-25 23:12:09 +08:00
|
|
|
expect(Actions.wakeLocalSyncWorkerForAccount).toHaveBeenCalled();
|
2016-05-14 05:16:54 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("allows the user to open preferences", () => {
|
|
|
|
spyOn(Actions, 'switchPreferencesTab')
|
|
|
|
spyOn(Actions, 'openPreferences')
|
2016-10-04 23:02:11 +08:00
|
|
|
const notif = mount(<AccountErrorNotification />);
|
|
|
|
notif.find('#action-1').simulate('click'); // Expects second action to be the preferences action
|
2016-05-14 05:16:54 +08:00
|
|
|
expect(Actions.openPreferences).toHaveBeenCalled();
|
|
|
|
expect(Actions.switchPreferencesTab).toHaveBeenCalledWith('Accounts');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when all accounts are fine", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(AccountStore, 'accounts').andReturn([
|
|
|
|
new Account({id: 'A', syncState: 'running', emailAddress: '123@gmail.com'}),
|
|
|
|
new Account({id: 'B', syncState: 'running', emailAddress: 'other@gmail.com'}),
|
|
|
|
])
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders nothing", () => {
|
2016-10-04 23:02:11 +08:00
|
|
|
const notif = mount(<AccountErrorNotification />);
|
2017-01-25 23:12:09 +08:00
|
|
|
expect(notif.find('.notification').exists()).toEqual(false);
|
2016-05-14 05:16:54 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|