mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 05:41:05 +08:00
17ed847240
Summary: See https://paper.dropbox.com/doc/Sync-disabling-for-N1-URZmjVpSSxWFvjC62TiFI Test Plan: Tests incoming Reviewers: juan, evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D2959
81 lines
3.2 KiB
JavaScript
81 lines
3.2 KiB
JavaScript
import {mount} from 'enzyme';
|
|
import AccountErrorHeader from '../lib/headers/account-error-header';
|
|
import {AccountStore, Account, Actions, React} from 'nylas-exports'
|
|
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 />);
|
|
spyOn(AccountStore, 'refreshHealthOfAccounts').andReturn(Promise.resolve());
|
|
header.find('.action.refresh').simulate('click');
|
|
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 />);
|
|
spyOn(AccountStore, 'refreshHealthOfAccounts').andReturn(Promise.resolve());
|
|
header.find('.action.refresh').simulate('click');
|
|
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>');
|
|
});
|
|
});
|
|
});
|