Calls: switch tab on actions requiring focus (#3235)
This commit is contained in:
@@ -74,6 +74,7 @@ jest.mock('main/performanceMonitor', () => ({
|
|||||||
jest.mock('main/views/viewManager', () => ({
|
jest.mock('main/views/viewManager', () => ({
|
||||||
getView: jest.fn(),
|
getView: jest.fn(),
|
||||||
getViewByWebContentsId: jest.fn(),
|
getViewByWebContentsId: jest.fn(),
|
||||||
|
showById: jest.fn(),
|
||||||
}));
|
}));
|
||||||
jest.mock('../utils', () => ({
|
jest.mock('../utils', () => ({
|
||||||
openScreensharePermissionsSettingsMacOS: jest.fn(),
|
openScreensharePermissionsSettingsMacOS: jest.fn(),
|
||||||
@@ -786,6 +787,7 @@ describe('main/windows/callsWidgetWindow', () => {
|
|||||||
|
|
||||||
describe('forwardToMainApp', () => {
|
describe('forwardToMainApp', () => {
|
||||||
const view = {
|
const view = {
|
||||||
|
id: 'main-view',
|
||||||
view: {
|
view: {
|
||||||
server: {
|
server: {
|
||||||
id: 'server-1',
|
id: 'server-1',
|
||||||
@@ -812,6 +814,7 @@ describe('main/windows/callsWidgetWindow', () => {
|
|||||||
const func = callsWidgetWindow.forwardToMainApp('some-channel');
|
const func = callsWidgetWindow.forwardToMainApp('some-channel');
|
||||||
func({sender: {id: 1}}, 'thecallchannelid');
|
func({sender: {id: 1}}, 'thecallchannelid');
|
||||||
expect(ServerViewState.switchServer).toHaveBeenCalledWith('server-1');
|
expect(ServerViewState.switchServer).toHaveBeenCalledWith('server-1');
|
||||||
|
expect(ViewManager.showById).toHaveBeenCalledWith('main-view');
|
||||||
expect(focus).toHaveBeenCalled();
|
expect(focus).toHaveBeenCalled();
|
||||||
expect(view.sendToRenderer).toBeCalledWith('some-channel', 'thecallchannelid');
|
expect(view.sendToRenderer).toBeCalledWith('some-channel', 'thecallchannelid');
|
||||||
});
|
});
|
||||||
@@ -819,6 +822,7 @@ describe('main/windows/callsWidgetWindow', () => {
|
|||||||
|
|
||||||
describe('handleCallsLinkClick', () => {
|
describe('handleCallsLinkClick', () => {
|
||||||
const view = {
|
const view = {
|
||||||
|
id: 'main-view',
|
||||||
view: {
|
view: {
|
||||||
server: {
|
server: {
|
||||||
id: 'server-1',
|
id: 'server-1',
|
||||||
@@ -845,10 +849,11 @@ describe('main/windows/callsWidgetWindow', () => {
|
|||||||
ViewManager.handleDeepLink = jest.fn();
|
ViewManager.handleDeepLink = jest.fn();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should switch server, focus and send history push event', () => {
|
it('should switch server, tab and focus and send history push event', () => {
|
||||||
const url = '/team/channel';
|
const url = '/team/channel';
|
||||||
callsWidgetWindow.handleCallsLinkClick({sender: {id: 1}}, url);
|
callsWidgetWindow.handleCallsLinkClick({sender: {id: 1}}, url);
|
||||||
expect(ServerViewState.switchServer).toHaveBeenCalledWith('server-1');
|
expect(ServerViewState.switchServer).toHaveBeenCalledWith('server-1');
|
||||||
|
expect(ViewManager.showById).toHaveBeenCalledWith('main-view');
|
||||||
expect(focus).toHaveBeenCalled();
|
expect(focus).toHaveBeenCalled();
|
||||||
expect(view.sendToRenderer).toBeCalledWith(BROWSER_HISTORY_PUSH, url);
|
expect(view.sendToRenderer).toBeCalledWith(BROWSER_HISTORY_PUSH, url);
|
||||||
});
|
});
|
||||||
@@ -884,6 +889,7 @@ describe('main/windows/callsWidgetWindow', () => {
|
|||||||
|
|
||||||
describe('handleCallsOpenThread', () => {
|
describe('handleCallsOpenThread', () => {
|
||||||
const view = {
|
const view = {
|
||||||
|
id: 'main-view',
|
||||||
view: {
|
view: {
|
||||||
server: {
|
server: {
|
||||||
id: 'server-1',
|
id: 'server-1',
|
||||||
@@ -903,10 +909,11 @@ describe('main/windows/callsWidgetWindow', () => {
|
|||||||
ViewManager.handleDeepLink = jest.fn();
|
ViewManager.handleDeepLink = jest.fn();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should switch server, focus and send open thread event', () => {
|
it('should switch server, tab and focus and send open thread event', () => {
|
||||||
const threadID = 'call-thread-id';
|
const threadID = 'call-thread-id';
|
||||||
callsWidgetWindow.handleCallsOpenThread({sender: {id: 1}}, threadID);
|
callsWidgetWindow.handleCallsOpenThread({sender: {id: 1}}, threadID);
|
||||||
expect(ServerViewState.switchServer).toHaveBeenCalledWith('server-1');
|
expect(ServerViewState.switchServer).toHaveBeenCalledWith('server-1');
|
||||||
|
expect(ViewManager.showById).toHaveBeenCalledWith('main-view');
|
||||||
expect(focus).toHaveBeenCalled();
|
expect(focus).toHaveBeenCalled();
|
||||||
expect(view.sendToRenderer).toBeCalledWith(CALLS_WIDGET_OPEN_THREAD, threadID);
|
expect(view.sendToRenderer).toBeCalledWith(CALLS_WIDGET_OPEN_THREAD, threadID);
|
||||||
});
|
});
|
||||||
@@ -914,6 +921,7 @@ describe('main/windows/callsWidgetWindow', () => {
|
|||||||
|
|
||||||
describe('handleCallsOpenStopRecordingModal', () => {
|
describe('handleCallsOpenStopRecordingModal', () => {
|
||||||
const view = {
|
const view = {
|
||||||
|
id: 'main-view',
|
||||||
view: {
|
view: {
|
||||||
server: {
|
server: {
|
||||||
id: 'server-1',
|
id: 'server-1',
|
||||||
@@ -932,12 +940,49 @@ describe('main/windows/callsWidgetWindow', () => {
|
|||||||
ViewManager.getView.mockReturnValue(view);
|
ViewManager.getView.mockReturnValue(view);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should switch server, focus and send open modal event', () => {
|
it('should switch server, tab and focus and send open modal event', () => {
|
||||||
const channelID = 'call-channel-id';
|
const channelID = 'call-channel-id';
|
||||||
callsWidgetWindow.handleCallsOpenStopRecordingModal({sender: {id: 1}}, channelID);
|
callsWidgetWindow.handleCallsOpenStopRecordingModal({sender: {id: 1}}, channelID);
|
||||||
expect(ServerViewState.switchServer).toHaveBeenCalledWith('server-1');
|
expect(ServerViewState.switchServer).toHaveBeenCalledWith('server-1');
|
||||||
|
expect(ViewManager.showById).toHaveBeenCalledWith('main-view');
|
||||||
expect(focus).toHaveBeenCalled();
|
expect(focus).toHaveBeenCalled();
|
||||||
expect(view.sendToRenderer).toBeCalledWith(CALLS_WIDGET_OPEN_STOP_RECORDING_MODAL, channelID);
|
expect(view.sendToRenderer).toBeCalledWith(CALLS_WIDGET_OPEN_STOP_RECORDING_MODAL, channelID);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('focusChannelView', () => {
|
||||||
|
const view = {
|
||||||
|
id: 'main-view',
|
||||||
|
view: {
|
||||||
|
server: {
|
||||||
|
id: 'server-1',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
sendToRenderer: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const callsWidgetWindow = new CallsWidgetWindow();
|
||||||
|
|
||||||
|
const focus = jest.fn();
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
MainWindow.get.mockReturnValue({focus});
|
||||||
|
ViewManager.getView.mockReturnValue(view);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('noop if not initialized', () => {
|
||||||
|
callsWidgetWindow.focusChannelView();
|
||||||
|
expect(ServerViewState.switchServer).not.toHaveBeenCalled();
|
||||||
|
expect(ViewManager.showById).not.toHaveBeenCalled();
|
||||||
|
expect(focus).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should switch server, tab and focus', () => {
|
||||||
|
callsWidgetWindow.mainView = view;
|
||||||
|
callsWidgetWindow.focusChannelView();
|
||||||
|
expect(ServerViewState.switchServer).toHaveBeenCalledWith('server-1');
|
||||||
|
expect(ViewManager.showById).toHaveBeenCalledWith('main-view');
|
||||||
|
expect(focus).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -501,6 +501,16 @@ export class CallsWidgetWindow {
|
|||||||
this.close();
|
this.close();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private focusChannelView() {
|
||||||
|
if (!this.serverID || !this.mainView) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerViewState.switchServer(this.serverID);
|
||||||
|
MainWindow.get()?.focus();
|
||||||
|
ViewManager.showById(this.mainView.id);
|
||||||
|
}
|
||||||
|
|
||||||
private forwardToMainApp = (channel: string) => {
|
private forwardToMainApp = (channel: string) => {
|
||||||
return (event: IpcMainEvent, ...args: any) => {
|
return (event: IpcMainEvent, ...args: any) => {
|
||||||
log.debug('forwardToMainApp', channel, ...args);
|
log.debug('forwardToMainApp', channel, ...args);
|
||||||
@@ -513,8 +523,7 @@ export class CallsWidgetWindow {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerViewState.switchServer(this.serverID);
|
this.focusChannelView();
|
||||||
MainWindow.get()?.focus();
|
|
||||||
this.mainView?.sendToRenderer(channel, ...args);
|
this.mainView?.sendToRenderer(channel, ...args);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -547,8 +556,7 @@ export class CallsWidgetWindow {
|
|||||||
// If parsing above fails it means it's a relative path (e.g.
|
// If parsing above fails it means it's a relative path (e.g.
|
||||||
// pointing to a channel).
|
// pointing to a channel).
|
||||||
|
|
||||||
ServerViewState.switchServer(this.serverID);
|
this.focusChannelView();
|
||||||
MainWindow.get()?.focus();
|
|
||||||
this.mainView?.sendToRenderer(BROWSER_HISTORY_PUSH, url);
|
this.mainView?.sendToRenderer(BROWSER_HISTORY_PUSH, url);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user