Mailspring/internal_packages/notifications/spec/account-error-notif-spec.jsx
Evan Morikawa 0be186302a refactor(account): remove unused accont refresh methods
Summary:
This removes `refreshHealthOfAccounts`, which I originally found because I
was trying to refactor it out of the IdentityStore. We need it gone from
the IdentityStore so that store can trigger frequently as things like the
usageLimits constantly update on it.

This also fixes T7520 where we'd get `ECONNREFUSED 127.0.0.1:2578` on
launch unnecessarily.

The concept of refreshing the health of accounts by occassionally polling
the /accounts endpoint is obsolete. This depends on
D3769 which entirely removes the /accounts endpoint
from K2.

Account health is pushed to us by `Actions.updateAccount` which is fired
directly from the main local-sync sync loop.

This also removes `refreshAccounts` and `Actions.refreshAllDeltaConnections`. These were fired by the Identity Store whenever it updated. We no longer need the Identity Store to tell us to reset the delta connections with our local-sync accounts. The delta connections will either be reset by our offline notification button, or when adding or removing an account. The Identity Store was a redundant mechanisms

Test Plan:
Manually verify things work with an existing account. Add a new account
and ensure sync starts. Remove an account and ensure it gets cleaned up.

Reviewers: halla, khamidou, mark, juan

Reviewed By: juan

Maniphest Tasks: T7520

Differential Revision: https://phab.nylas.com/D3770
2017-01-25 10:12:09 -05:00

82 lines
3.4 KiB
JavaScript

import {mount} from 'enzyme';
import {AccountStore, Account, Actions, React} from 'nylas-exports';
import {ipcRenderer} from 'electron';
import AccountErrorNotification from '../lib/items/account-error-notif';
describe("AccountErrorNotif", function AccountErrorNotifTests() {
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", () => {
const notif = mount(<AccountErrorNotification />);
expect(notif.find('.title').text().indexOf('123@gmail.com') > 0).toBe(true);
});
it("allows the user to refresh the account", () => {
const notif = mount(<AccountErrorNotification />);
spyOn(Actions, 'wakeLocalSyncWorkerForAccount').andReturn(Promise.resolve());
notif.find('#action-0').simulate('click'); // Expects first action to be the refresh action
expect(Actions.wakeLocalSyncWorkerForAccount).toHaveBeenCalled();
});
it("allows the user to reconnect the account", () => {
const notif = mount(<AccountErrorNotification />);
spyOn(ipcRenderer, 'send');
notif.find('#action-1').simulate('click'); // Expects second action to be the reconnect action
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", () => {
const notif = mount(<AccountErrorNotification />);
expect(notif.find('.notification').exists()).toEqual(true);
});
it("allows the user to refresh the accounts", () => {
const notif = mount(<AccountErrorNotification />);
spyOn(Actions, 'wakeLocalSyncWorkerForAccount').andReturn(Promise.resolve());
notif.find('#action-0').simulate('click'); // Expects first action to be the refresh action
expect(Actions.wakeLocalSyncWorkerForAccount).toHaveBeenCalled();
});
it("allows the user to open preferences", () => {
spyOn(Actions, 'switchPreferencesTab')
spyOn(Actions, 'openPreferences')
const notif = mount(<AccountErrorNotification />);
notif.find('#action-1').simulate('click'); // Expects second action to be the preferences action
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", () => {
const notif = mount(<AccountErrorNotification />);
expect(notif.find('.notification').exists()).toEqual(false);
});
});
});