[MM-40277][MM-40279][MM-40301][MM-40307][MM-40310][MM-40313] Unit tests and refactors for main module (#1876)

* Refactor autoLauncher and remove unnecessary file

* [MM-40277] Unit tests for main/badge

* [MM-40279] Unit tests for main/certificateStore

* [MM-40301] Unit tests for main/contextMenu, also remove workaround

* [MM-40307] Unit tests for main/CriticalErrorHandler

* [MM-40310] Unit tests for main/utils

* [MM-40313] Unit tests for main/Validator

* Lint fix

* Added globals

* More things that should probably already be merged

* PR feedback
This commit is contained in:
Devin Binnie
2021-11-26 11:14:26 -05:00
committed by GitHub
parent fc06dc99a2
commit 5056ec7ace
14 changed files with 740 additions and 99 deletions

79
src/main/badge.test.js Normal file
View File

@@ -0,0 +1,79 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
'use strict';
import {app} from 'electron';
import * as Badge from './badge';
import {setOverlayIcon} from './windows/windowManager';
jest.mock('electron', () => ({
app: {
dock: {
setBadge: jest.fn(),
},
},
}));
jest.mock('./appState', () => ({
updateBadge: jest.fn(),
}));
jest.mock('./windows/windowManager', () => ({
setOverlayIcon: jest.fn(),
}));
describe('main/badge', () => {
describe('showBadgeWindows', () => {
it('should show dot when session expired', () => {
Badge.showBadgeWindows(true, 7, false);
expect(setOverlayIcon).toBeCalledWith('•', expect.any(String), expect.any(Boolean));
});
it('should show mention count when has mention count', () => {
Badge.showBadgeWindows(false, 50, false);
expect(setOverlayIcon).toBeCalledWith('50', expect.any(String), false);
});
it('should show 99+ when has mention count over 99', () => {
Badge.showBadgeWindows(false, 200, false);
expect(setOverlayIcon).toBeCalledWith('99+', expect.any(String), true);
});
it('should not show dot when has unreads but setting is off', () => {
Badge.showBadgeWindows(false, 0, true);
expect(setOverlayIcon).not.toBeCalledWith('•', expect.any(String), expect.any(Boolean));
});
it('should show dot when has unreads', () => {
Badge.setUnreadBadgeSetting(true);
Badge.showBadgeWindows(false, 0, true);
expect(setOverlayIcon).toBeCalledWith('•', expect.any(String), expect.any(Boolean));
Badge.setUnreadBadgeSetting(false);
});
});
describe('showBadgeOSX', () => {
it('should show dot when session expired', () => {
Badge.showBadgeOSX(true, 7, false);
expect(app.dock.setBadge).toBeCalledWith('•');
});
it('should show mention count when has mention count', () => {
Badge.showBadgeOSX(false, 50, false);
expect(app.dock.setBadge).toBeCalledWith('50');
});
it('should not show dot when has unreads but setting is off', () => {
Badge.showBadgeOSX(false, 0, true);
expect(app.dock.setBadge).not.toBeCalledWith('•');
});
it('should show dot when has unreads', () => {
Badge.setUnreadBadgeSetting(true);
Badge.showBadgeOSX(false, 0, true);
expect(app.dock.setBadge).toBeCalledWith('•');
});
});
});