Files
mattermostest/src/main/views/teamDropdownView.test.js
Tasos Boulis c319038704 [MM-48184] Disallow edit/remove server if it is imported from GPO (#2353)
* Disallow edit/remove server if it is imported from GPO

* Fix width issue of team dropdown
2022-11-04 17:58:21 +02:00

109 lines
4.0 KiB
JavaScript

// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
'use strict';
import {TAB_BAR_HEIGHT, THREE_DOT_MENU_WIDTH, THREE_DOT_MENU_WIDTH_MAC, MENU_SHADOW_WIDTH} from 'common/utils/constants';
import TeamDropdownView from './teamDropdownView';
jest.mock('main/utils', () => ({
getLocalPreload: (file) => file,
getLocalURLString: (file) => file,
}));
jest.mock('electron', () => ({
BrowserView: jest.fn().mockImplementation(() => ({
webContents: {
loadURL: jest.fn(),
focus: jest.fn(),
},
setBounds: jest.fn(),
})),
ipcMain: {
on: jest.fn(),
},
}));
jest.mock('../windows/windowManager', () => ({
sendToRenderer: jest.fn(),
}));
describe('main/views/teamDropdownView', () => {
const window = {
getContentBounds: () => ({width: 500, height: 400, x: 0, y: 0}),
addBrowserView: jest.fn(),
setTopBrowserView: jest.fn(),
};
describe('getBounds', () => {
const teamDropdownView = new TeamDropdownView(window, [], false, true);
if (process.platform === 'darwin') {
it('should account for three dot menu, tab bar and shadow', () => {
expect(teamDropdownView.getBounds(400, 300)).toStrictEqual({x: THREE_DOT_MENU_WIDTH_MAC - MENU_SHADOW_WIDTH, y: TAB_BAR_HEIGHT - MENU_SHADOW_WIDTH, width: 400, height: 300});
});
} else {
it('should account for three dot menu, tab bar and shadow', () => {
expect(teamDropdownView.getBounds(400, 300)).toStrictEqual({x: THREE_DOT_MENU_WIDTH - MENU_SHADOW_WIDTH, y: TAB_BAR_HEIGHT - MENU_SHADOW_WIDTH, width: 400, height: 300});
});
}
});
it('should change the view bounds based on open/closed state', () => {
const teamDropdownView = new TeamDropdownView(window, [], false, true);
teamDropdownView.bounds = {width: 400, height: 300};
teamDropdownView.handleOpen();
expect(teamDropdownView.view.setBounds).toBeCalledWith(teamDropdownView.bounds);
teamDropdownView.handleClose();
expect(teamDropdownView.view.setBounds).toBeCalledWith({width: 0, height: 0, x: expect.any(Number), y: expect.any(Number)});
});
describe('addGpoToTeams', () => {
it('should return teams with "isGPO": false when no config.registryTeams exist', () => {
const teamDropdownView = new TeamDropdownView(window, [], false, true);
const teams = [{
name: 'team-1',
url: 'https://mattermost.team-1.com',
}, {
name: 'team-2',
url: 'https://mattermost.team-2.com',
}];
const registryTeams = [];
expect(teamDropdownView.addGpoToTeams(teams, registryTeams)).toStrictEqual([{
name: 'team-1',
url: 'https://mattermost.team-1.com',
isGpo: false,
}, {
name: 'team-2',
url: 'https://mattermost.team-2.com',
isGpo: false,
}]);
});
it('should return teams with "isGPO": true if they exist in config.registryTeams', () => {
const teamDropdownView = new TeamDropdownView(window, [], false, true);
const teams = [{
name: 'team-1',
url: 'https://mattermost.team-1.com',
}, {
name: 'team-2',
url: 'https://mattermost.team-2.com',
}];
const registryTeams = [{
name: 'team-1',
url: 'https://mattermost.team-1.com',
}];
expect(teamDropdownView.addGpoToTeams(teams, registryTeams)).toStrictEqual([{
name: 'team-1',
url: 'https://mattermost.team-1.com',
isGpo: true,
}, {
name: 'team-2',
url: 'https://mattermost.team-2.com',
isGpo: false,
}]);
});
});
});