Files
mattermostest/src/main/app/utils.test.js
Guillermo Vayá d2435a561c [MM-18552] Autoupdater (#1714)
* wip

* background download

* various fixes

* wip

* wokring autoupgrade

* fix menu

* fix windows

* cleanup

* add publishername

* fix messages and titles

* Test updates

* Moved module and added functionality to click icon to install (instead of just download)

* Add auto update setting, update on close app if downloaded

* Tests, changes for security fixes, update version number

* Update E2E tests

* Lint fix

* Update to latest electron-updater

* Revert to stable electron-builder (only needed to update electron-updater)

* Fix package-lock

* skip flaky test

* Update package

* Fix E2E test

* Fixes for enabling/disabled autoupdater

* Fixed GPO definitions

* [MM-38300] Set localhost as the test server

* blank

* Switch to s3 bucket for testing

* Update icons to match spec

* Add menu items for download/update actions

* Type and test fixes

* Fix notification circle

* Fix macOS app not restarting on Restart/Update

* Update dialog box titles

* Turn off file system check for Linux

* Changes to support deployments

* Testing autoupdater deployments to s3

* disable tests for now

* asfrehwf

* fine no windows WHATEVER

* remove windows again

* Try universal all in one

* pffftttngggguhhhh

* make sure it's working

* Missed artifacts script

* Modify destination as well

* one more time!

* Update yml files

* Oops

* add yq manually

* oof

* Fix the script to work properly

* Fix release script

* Fix script again so it runs in time

* Build version 2

* Revert build specific changes

* Lint override

* Fix build apps for PR builds

* One more change

* Add file generation for .deb repo

* Deb repo test

* skip tests for now

* Fix artifact push

* Persist after repo creation

* Put tests back

* Fix unit tests

* Enable mac generated builds temp

* Temporarily disable tests

* Fix issue where notification doesn't pop dialog box

* Try version 2 again

* Put the version back

* Attempting to debug mac app path issue

* Fix issue where Mac app will quarantine itself after first update

* Lock versions of yq

* Fix yq for mac

* As usual, Mac is difficult :P

* Add quotes to anti-quarantine command

* Change to spawn to avoid command injection

* Oops

* Nightly deployment changes (#2005)

* Test nightly deploy

* I fixed a some things

* aaaaaaaaa

* Restore old bucket

* Added progress indicator via tooltip

* Ship nightly builds to main S3 bucket

* PR feedback

* Fix a couple security exploits

* Fix opacity on light mode button

* Use large app icon

* Resize icon for Windows

* Resize icon for Mac

* Update to electron-updater final

* Remove Mac support and deb repo

* Typo

* Remove deb script

* Remove checksum function

* Removed autoUpdateSettingsPath

* Update URL

Co-authored-by: = <=>
Co-authored-by: Devin Binnie <devin.binnie@mattermost.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Devin Binnie <52460000+devinbinnie@users.noreply.github.com>
2022-03-08 11:38:38 -05:00

194 lines
6.8 KiB
JavaScript

// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import Config from 'common/config';
import {TAB_MESSAGING, TAB_FOCALBOARD, TAB_PLAYBOOKS} from 'common/tabs/TabView';
import Utils from 'common/utils/util';
import {ServerInfo} from 'main/server/serverInfo';
import {getDeeplinkingURL, updateServerInfos, resizeScreen} from './utils';
jest.mock('electron-log', () => ({
info: jest.fn(),
}));
jest.mock('common/config', () => ({
set: jest.fn(),
}));
jest.mock('common/utils/util', () => ({
isVersionGreaterThanOrEqualTo: jest.fn(),
getDisplayBoundaries: jest.fn(),
}));
jest.mock('main/autoUpdater', () => ({}));
jest.mock('main/menus/app', () => ({}));
jest.mock('main/menus/tray', () => ({}));
jest.mock('main/server/serverInfo', () => ({
ServerInfo: jest.fn(),
}));
jest.mock('main/tray/tray', () => ({}));
jest.mock('main/windows/windowManager', () => ({}));
jest.mock('./initialize', () => ({
mainProtocol: 'mattermost',
}));
describe('main/app/utils', () => {
describe('updateServerInfos', () => {
const tabs = [
{
name: TAB_MESSAGING,
order: 0,
isOpen: true,
},
{
name: TAB_FOCALBOARD,
order: 2,
},
{
name: TAB_PLAYBOOKS,
order: 1,
},
];
const teams = [
{
name: 'server-1',
url: 'http://server-1.com',
tabs,
},
];
beforeEach(() => {
Utils.isVersionGreaterThanOrEqualTo.mockImplementation((version) => version === '6.0.0');
Config.set.mockImplementation((name, value) => {
Config[name] = value;
});
const teamsCopy = JSON.parse(JSON.stringify(teams));
Config.teams = teamsCopy;
});
afterEach(() => {
delete Config.teams;
});
it('should open all tabs', async () => {
ServerInfo.mockReturnValue({promise: {
name: 'server-1',
serverVersion: '6.0.0',
hasPlaybooks: true,
hasFocalboard: true,
}});
updateServerInfos(Config.teams);
await new Promise(setImmediate); // workaround since Promise.all seems to not let me wait here
expect(Config.teams.find((team) => team.name === 'server-1').tabs.find((tab) => tab.name === TAB_PLAYBOOKS).isOpen).toBe(true);
expect(Config.teams.find((team) => team.name === 'server-1').tabs.find((tab) => tab.name === TAB_FOCALBOARD).isOpen).toBe(true);
});
it('should open only playbooks', async () => {
ServerInfo.mockReturnValue({promise: {
name: 'server-1',
serverVersion: '6.0.0',
hasPlaybooks: true,
hasFocalboard: false,
}});
updateServerInfos(Config.teams);
await new Promise(setImmediate); // workaround since Promise.all seems to not let me wait here
expect(Config.teams.find((team) => team.name === 'server-1').tabs.find((tab) => tab.name === TAB_PLAYBOOKS).isOpen).toBe(true);
expect(Config.teams.find((team) => team.name === 'server-1').tabs.find((tab) => tab.name === TAB_FOCALBOARD).isOpen).toBeUndefined();
});
it('should open none when server version is too old', async () => {
ServerInfo.mockReturnValue({promise: {
name: 'server-1',
serverVersion: '5.0.0',
hasPlaybooks: true,
hasFocalboard: true,
}});
updateServerInfos(Config.teams);
await new Promise(setImmediate); // workaround since Promise.all seems to not let me wait here
expect(Config.teams.find((team) => team.name === 'server-1').tabs.find((tab) => tab.name === TAB_PLAYBOOKS).isOpen).toBeUndefined();
expect(Config.teams.find((team) => team.name === 'server-1').tabs.find((tab) => tab.name === TAB_FOCALBOARD).isOpen).toBeUndefined();
});
});
describe('getDeeplinkingURL', () => {
it('should return undefined if deeplinking URL is not last argument', () => {
expect(getDeeplinkingURL(['mattermost', 'mattermost://server-1.com', '--oops'])).toBeUndefined();
});
it('should return undefined if deeplinking URL is not valid', () => {
expect(getDeeplinkingURL(['mattermost', 'mattermost://,a<lolbad'])).toBeUndefined();
});
it('should return url if deeplinking URL is valid', () => {
expect(getDeeplinkingURL(['mattermost', 'mattermost://server-1.com'])).toBe('mattermost://server-1.com');
});
});
describe('resizeScreen', () => {
beforeEach(() => {
Utils.getDisplayBoundaries.mockReturnValue([{
minX: 400,
minY: 300,
maxX: 2320,
maxY: 1380,
width: 1920,
height: 1080,
}]);
});
it('should keep the same position if it is within a display', () => {
const browserWindow = {
getPosition: () => [500, 400],
getSize: () => [1280, 720],
setPosition: jest.fn(),
center: jest.fn(),
on: jest.fn(),
};
resizeScreen(browserWindow);
expect(browserWindow.setPosition).toHaveBeenCalledWith(500, 400);
});
it('should keep the same position if it is halfway within a display', () => {
let browserWindow = {
getPosition: () => [1680, 400],
getSize: () => [1280, 720],
setPosition: jest.fn(),
center: jest.fn(),
on: jest.fn(),
};
resizeScreen(browserWindow);
expect(browserWindow.setPosition).toHaveBeenCalledWith(1680, 400);
browserWindow = {
getPosition: () => [500, 1020],
getSize: () => [1280, 720],
setPosition: jest.fn(),
center: jest.fn(),
on: jest.fn(),
};
resizeScreen(browserWindow);
expect(browserWindow.setPosition).toHaveBeenCalledWith(500, 1020);
});
it('should center if it is outside a display', () => {
const browserWindow = {
getPosition: () => [2400, 2000],
getSize: () => [1280, 720],
setPosition: jest.fn(),
center: jest.fn(),
on: jest.fn(),
};
resizeScreen(browserWindow);
expect(browserWindow.setPosition).not.toHaveBeenCalled();
expect(browserWindow.center).toHaveBeenCalled();
});
});
});