[MM-40406] Add more singletons, refactor main.ts into pieces, add tests and some cleanup + tests for additional coverage (#1890)
* Refactor main.ts dependencies into singleton pattern * Split main.ts into testable pieces, some other refactoring for singleton pattern * Unit tests for main/app/app * Unit tests for main/app/config * Unit tests for main/app/initialize * Unit tests for main/app/intercom * Unit tests for main/app/utils * Add some more tests to get to 70% coverage * Fix for linux * Fix for alternate data dir paths * Fix E2E test
This commit is contained in:
@@ -25,10 +25,27 @@ jest.mock('common/utils/url', () => {
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock('electron', () => ({
|
||||
app: {
|
||||
getPath: jest.fn(),
|
||||
},
|
||||
ipcMain: {
|
||||
on: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('electron-log', () => ({
|
||||
error: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('main/trustedOrigins', () => ({
|
||||
addPermission: jest.fn(),
|
||||
checkPermission: (url) => {
|
||||
return url.toString() === 'http://haspermissionurl.com/';
|
||||
},
|
||||
save: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('main/windows/windowManager', () => ({
|
||||
getMainWindow: jest.fn().mockImplementation(() => ({})),
|
||||
}));
|
||||
@@ -90,17 +107,9 @@ const config = {
|
||||
}],
|
||||
};
|
||||
|
||||
const trustedOriginsStore = {
|
||||
addPermission: jest.fn(),
|
||||
checkPermission: (url) => {
|
||||
return url.toString() === 'http://haspermissionurl.com/';
|
||||
},
|
||||
save: jest.fn(),
|
||||
};
|
||||
|
||||
describe('main/authManager', () => {
|
||||
describe('handleAppLogin', () => {
|
||||
const authManager = new AuthManager(config, trustedOriginsStore);
|
||||
const authManager = new AuthManager(config);
|
||||
authManager.popLoginModal = jest.fn();
|
||||
authManager.popPermissionModal = jest.fn();
|
||||
|
||||
@@ -148,7 +157,7 @@ describe('main/authManager', () => {
|
||||
});
|
||||
|
||||
describe('popLoginModal', () => {
|
||||
const authManager = new AuthManager(config, trustedOriginsStore);
|
||||
const authManager = new AuthManager(config);
|
||||
|
||||
it('should not pop modal when no main window exists', () => {
|
||||
WindowManager.getMainWindow.mockImplementationOnce(() => null);
|
||||
@@ -216,7 +225,7 @@ describe('main/authManager', () => {
|
||||
});
|
||||
|
||||
describe('popPermissionModal', () => {
|
||||
const authManager = new AuthManager(config, trustedOriginsStore);
|
||||
const authManager = new AuthManager(config);
|
||||
|
||||
it('should not pop modal when no main window exists', () => {
|
||||
WindowManager.getMainWindow.mockImplementationOnce(() => null);
|
||||
@@ -261,7 +270,7 @@ describe('main/authManager', () => {
|
||||
});
|
||||
|
||||
describe('handleLoginCredentialsEvent', () => {
|
||||
const authManager = new AuthManager(config, trustedOriginsStore);
|
||||
const authManager = new AuthManager(config);
|
||||
const callback = jest.fn();
|
||||
|
||||
beforeEach(() => {
|
||||
|
Reference in New Issue
Block a user