Refactor config, move ipc calls to app module, some cleanup (#2669)
This commit is contained in:
@@ -65,55 +65,53 @@ jest.mock('common/tabs/TabView', () => ({
|
||||
|
||||
describe('main/menus/app', () => {
|
||||
const config = {
|
||||
data: {
|
||||
enableServerManagement: true,
|
||||
teams: [{
|
||||
name: 'example',
|
||||
url: 'http://example.com',
|
||||
order: 0,
|
||||
tabs: [
|
||||
{
|
||||
name: 'TAB_MESSAGING',
|
||||
order: 0,
|
||||
isOpen: true,
|
||||
},
|
||||
{
|
||||
name: 'TAB_FOCALBOARD',
|
||||
order: 1,
|
||||
isOpen: true,
|
||||
},
|
||||
{
|
||||
name: 'TAB_PLAYBOOKS',
|
||||
order: 2,
|
||||
isOpen: true,
|
||||
},
|
||||
],
|
||||
lastActiveTab: 0,
|
||||
}, {
|
||||
name: 'github',
|
||||
url: 'https://github.com/',
|
||||
order: 1,
|
||||
tabs: [
|
||||
{
|
||||
name: 'TAB_MESSAGING',
|
||||
order: 0,
|
||||
isOpen: true,
|
||||
},
|
||||
{
|
||||
name: 'TAB_FOCALBOARD',
|
||||
order: 1,
|
||||
isOpen: true,
|
||||
},
|
||||
{
|
||||
name: 'TAB_PLAYBOOKS',
|
||||
order: 2,
|
||||
isOpen: true,
|
||||
},
|
||||
],
|
||||
lastActiveTab: 0,
|
||||
}],
|
||||
helpLink: 'http://link-to-help.site.com',
|
||||
},
|
||||
enableServerManagement: true,
|
||||
teams: [{
|
||||
name: 'example',
|
||||
url: 'http://example.com',
|
||||
order: 0,
|
||||
tabs: [
|
||||
{
|
||||
name: 'TAB_MESSAGING',
|
||||
order: 0,
|
||||
isOpen: true,
|
||||
},
|
||||
{
|
||||
name: 'TAB_FOCALBOARD',
|
||||
order: 1,
|
||||
isOpen: true,
|
||||
},
|
||||
{
|
||||
name: 'TAB_PLAYBOOKS',
|
||||
order: 2,
|
||||
isOpen: true,
|
||||
},
|
||||
],
|
||||
lastActiveTab: 0,
|
||||
}, {
|
||||
name: 'github',
|
||||
url: 'https://github.com/',
|
||||
order: 1,
|
||||
tabs: [
|
||||
{
|
||||
name: 'TAB_MESSAGING',
|
||||
order: 0,
|
||||
isOpen: true,
|
||||
},
|
||||
{
|
||||
name: 'TAB_FOCALBOARD',
|
||||
order: 1,
|
||||
isOpen: true,
|
||||
},
|
||||
{
|
||||
name: 'TAB_PLAYBOOKS',
|
||||
order: 2,
|
||||
isOpen: true,
|
||||
},
|
||||
],
|
||||
lastActiveTab: 0,
|
||||
}],
|
||||
helpLink: 'http://link-to-help.site.com',
|
||||
};
|
||||
beforeEach(() => {
|
||||
getDarwinDoNotDisturb.mockReturnValue(false);
|
||||
@@ -218,7 +216,7 @@ describe('main/menus/app', () => {
|
||||
const menu = createTemplate(modifiedConfig);
|
||||
const fileMenu = menu.find((item) => item.label === '&AppName' || item.label === '&File');
|
||||
const signInOption = fileMenu.submenu.find((item) => item.label === 'Sign in to Another Server');
|
||||
expect(signInOption).not.toBe(undefined);
|
||||
expect(signInOption).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should not show `Sign in to Another Server` if no teams are configured', () => {
|
||||
@@ -239,7 +237,7 @@ describe('main/menus/app', () => {
|
||||
const menu = createTemplate(modifiedConfig);
|
||||
const fileMenu = menu.find((item) => item.label === '&AppName' || item.label === '&File');
|
||||
const signInOption = fileMenu.submenu.find((item) => item.label === 'Sign in to Another Server');
|
||||
expect(signInOption).not.toBe(undefined);
|
||||
expect(signInOption).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should show the first 9 servers (using order) in the Window menu', () => {
|
||||
@@ -250,21 +248,18 @@ describe('main/menus/app', () => {
|
||||
return id;
|
||||
});
|
||||
const modifiedConfig = {
|
||||
data: {
|
||||
...config.data,
|
||||
teams: [...Array(15).keys()].map((key) => ({
|
||||
name: `server-${key}`,
|
||||
url: `http://server-${key}.com`,
|
||||
order: (key + 5) % 15,
|
||||
lastActiveTab: 0,
|
||||
tab: [
|
||||
{
|
||||
name: 'TAB_MESSAGING',
|
||||
isOpen: true,
|
||||
},
|
||||
],
|
||||
})),
|
||||
},
|
||||
teams: [...Array(15).keys()].map((key) => ({
|
||||
name: `server-${key}`,
|
||||
url: `http://server-${key}.com`,
|
||||
order: (key + 5) % 15,
|
||||
lastActiveTab: 0,
|
||||
tab: [
|
||||
{
|
||||
name: 'TAB_MESSAGING',
|
||||
isOpen: true,
|
||||
},
|
||||
],
|
||||
})),
|
||||
};
|
||||
const menu = createTemplate(modifiedConfig);
|
||||
const windowMenu = menu.find((item) => item.label === '&Window');
|
||||
@@ -292,22 +287,19 @@ describe('main/menus/app', () => {
|
||||
}
|
||||
return id;
|
||||
});
|
||||
WindowManager.getCurrentTeamName.mockImplementation(() => config.data.teams[0].name);
|
||||
WindowManager.getCurrentTeamName.mockImplementation(() => config.teams[0].name);
|
||||
|
||||
const modifiedConfig = {
|
||||
data: {
|
||||
...config.data,
|
||||
teams: [
|
||||
{
|
||||
...config.data.teams[0],
|
||||
tabs: [...Array(15).keys()].map((key) => ({
|
||||
name: `tab-${key}`,
|
||||
isOpen: true,
|
||||
order: (key + 5) % 15,
|
||||
})),
|
||||
},
|
||||
],
|
||||
},
|
||||
teams: [
|
||||
{
|
||||
...config.teams[0],
|
||||
tabs: [...Array(15).keys()].map((key) => ({
|
||||
name: `tab-${key}`,
|
||||
isOpen: true,
|
||||
order: (key + 5) % 15,
|
||||
})),
|
||||
},
|
||||
],
|
||||
};
|
||||
const menu = createTemplate(modifiedConfig);
|
||||
const windowMenu = menu.find((item) => item.label === '&Window');
|
||||
|
@@ -49,7 +49,7 @@ export function createTemplate(config: Config, updateManager: UpdateManager) {
|
||||
},
|
||||
});
|
||||
|
||||
if (config.data?.enableServerManagement === true && config.data?.teams.length > 0) {
|
||||
if (config.enableServerManagement === true && config.teams.length > 0) {
|
||||
platformAppMenu.push({
|
||||
label: localizeMessage('main.menus.app.file.signInToAnotherServer', 'Sign in to Another Server'),
|
||||
click() {
|
||||
@@ -203,7 +203,7 @@ export function createTemplate(config: Config, updateManager: UpdateManager) {
|
||||
viewSubMenu.push({
|
||||
label: localizeMessage('main.menus.app.view.toggleDarkMode', 'Toggle Dark Mode'),
|
||||
click() {
|
||||
config.toggleDarkModeManually();
|
||||
config.set('darkMode', !config.darkMode);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -231,7 +231,7 @@ export function createTemplate(config: Config, updateManager: UpdateManager) {
|
||||
}],
|
||||
});
|
||||
|
||||
const teams = config.data?.teams || [];
|
||||
const teams = config.teams || [];
|
||||
const windowMenu = {
|
||||
id: 'window',
|
||||
label: localizeMessage('main.menus.app.window', '&Window'),
|
||||
@@ -251,7 +251,7 @@ export function createTemplate(config: Config, updateManager: UpdateManager) {
|
||||
label: isMac ? localizeMessage('main.menus.app.window.closeWindow', 'Close Window') : localizeMessage('main.menus.app.window.close', 'Close'),
|
||||
accelerator: 'CmdOrCtrl+W',
|
||||
}, separatorItem,
|
||||
...(config.data?.teams.length ? [{
|
||||
...(config.teams.length ? [{
|
||||
label: localizeMessage('main.menus.app.window.showServers', 'Show Servers'),
|
||||
accelerator: `${process.platform === 'darwin' ? 'Cmd+Ctrl' : 'Ctrl+Shift'}+S`,
|
||||
click() {
|
||||
@@ -325,11 +325,11 @@ export function createTemplate(config: Config, updateManager: UpdateManager) {
|
||||
});
|
||||
}
|
||||
}
|
||||
if (config.data?.helpLink) {
|
||||
if (config.helpLink) {
|
||||
submenu.push({
|
||||
label: localizeMessage('main.menus.app.help.learnMore', 'Learn More...'),
|
||||
click() {
|
||||
shell.openExternal(config.data!.helpLink);
|
||||
shell.openExternal(config.helpLink!);
|
||||
},
|
||||
});
|
||||
submenu.push(separatorItem);
|
||||
|
Reference in New Issue
Block a user