[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:
79
src/main/badge.test.js
Normal file
79
src/main/badge.test.js
Normal 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('•');
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user