2016-05-14 05:16:54 +08:00
|
|
|
import {mount} from 'enzyme';
|
|
|
|
import AccountErrorHeader from '../lib/headers/account-error-header';
|
2016-06-11 05:29:21 +08:00
|
|
|
import {IdentityStore, AccountStore, Account, Actions, React} from 'nylas-exports'
|
2016-05-14 05:16:54 +08:00
|
|
|
import {ipcRenderer} from 'electron';
|
|
|
|
|
|
|
|
describe("AccountErrorHeader", function AccountErrorHeaderTests() {
|
|
|
|
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 header = mount(<AccountErrorHeader />);
|
|
|
|
expect(header.find('.notifications-sticky-item')).toBeDefined();
|
|
|
|
expect(header.find('.message').text().indexOf('123@gmail.com') > 0).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows the user to refresh the account", () => {
|
|
|
|
const header = mount(<AccountErrorHeader />);
|
2016-06-11 05:29:21 +08:00
|
|
|
spyOn(IdentityStore, 'refreshStatus').andReturn(Promise.resolve());
|
2016-05-14 05:16:54 +08:00
|
|
|
spyOn(AccountStore, 'refreshHealthOfAccounts').andReturn(Promise.resolve());
|
|
|
|
header.find('.action.refresh').simulate('click');
|
2016-06-11 05:29:21 +08:00
|
|
|
expect(IdentityStore.refreshStatus).toHaveBeenCalled();
|
|
|
|
advanceClock();
|
2016-05-14 05:16:54 +08:00
|
|
|
expect(AccountStore.refreshHealthOfAccounts).toHaveBeenCalledWith(['A']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows the user to reconnect the account", () => {
|
|
|
|
const header = mount(<AccountErrorHeader />);
|
|
|
|
spyOn(ipcRenderer, 'send');
|
|
|
|
header.find('.action.default').simulate('click');
|
|
|
|
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 header = mount(<AccountErrorHeader />);
|
|
|
|
expect(header.find('.notifications-sticky-item')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows the user to refresh the accounts", () => {
|
|
|
|
const header = mount(<AccountErrorHeader />);
|
2016-06-11 05:29:21 +08:00
|
|
|
spyOn(IdentityStore, 'refreshStatus').andReturn(Promise.resolve());
|
2016-05-14 05:16:54 +08:00
|
|
|
spyOn(AccountStore, 'refreshHealthOfAccounts').andReturn(Promise.resolve());
|
|
|
|
header.find('.action.refresh').simulate('click');
|
2016-06-11 05:29:21 +08:00
|
|
|
expect(IdentityStore.refreshStatus).toHaveBeenCalled();
|
|
|
|
advanceClock();
|
2016-05-14 05:16:54 +08:00
|
|
|
expect(AccountStore.refreshHealthOfAccounts).toHaveBeenCalledWith(['A', 'B']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows the user to open preferences", () => {
|
|
|
|
spyOn(Actions, 'switchPreferencesTab')
|
|
|
|
spyOn(Actions, 'openPreferences')
|
|
|
|
const header = mount(<AccountErrorHeader />);
|
|
|
|
header.find('.action.default').simulate('click');
|
|
|
|
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 header = mount(<AccountErrorHeader />);
|
|
|
|
expect(header.html()).toEqual('<span></span>');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|