Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-62001] Calls: switch tab on actions requiring focus #3235

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions src/main/windows/callsWidgetWindow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jest.mock('main/performanceMonitor', () => ({
jest.mock('main/views/viewManager', () => ({
getView: jest.fn(),
getViewByWebContentsId: jest.fn(),
showById: jest.fn(),
}));
jest.mock('../utils', () => ({
openScreensharePermissionsSettingsMacOS: jest.fn(),
Expand Down Expand Up @@ -786,6 +787,7 @@ describe('main/windows/callsWidgetWindow', () => {

describe('forwardToMainApp', () => {
const view = {
id: 'main-view',
view: {
server: {
id: 'server-1',
Expand All @@ -812,13 +814,15 @@ describe('main/windows/callsWidgetWindow', () => {
const func = callsWidgetWindow.forwardToMainApp('some-channel');
func({sender: {id: 1}}, 'thecallchannelid');
expect(ServerViewState.switchServer).toHaveBeenCalledWith('server-1');
expect(ViewManager.showById).toHaveBeenCalledWith('main-view');
expect(focus).toHaveBeenCalled();
expect(view.sendToRenderer).toBeCalledWith('some-channel', 'thecallchannelid');
});
});

describe('handleCallsLinkClick', () => {
const view = {
id: 'main-view',
view: {
server: {
id: 'server-1',
Expand All @@ -845,10 +849,11 @@ describe('main/windows/callsWidgetWindow', () => {
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';
callsWidgetWindow.handleCallsLinkClick({sender: {id: 1}}, url);
expect(ServerViewState.switchServer).toHaveBeenCalledWith('server-1');
expect(ViewManager.showById).toHaveBeenCalledWith('main-view');
expect(focus).toHaveBeenCalled();
expect(view.sendToRenderer).toBeCalledWith(BROWSER_HISTORY_PUSH, url);
});
Expand Down Expand Up @@ -884,6 +889,7 @@ describe('main/windows/callsWidgetWindow', () => {

describe('handleCallsOpenThread', () => {
const view = {
id: 'main-view',
view: {
server: {
id: 'server-1',
Expand All @@ -903,17 +909,19 @@ describe('main/windows/callsWidgetWindow', () => {
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';
callsWidgetWindow.handleCallsOpenThread({sender: {id: 1}}, threadID);
expect(ServerViewState.switchServer).toHaveBeenCalledWith('server-1');
expect(ViewManager.showById).toHaveBeenCalledWith('main-view');
expect(focus).toHaveBeenCalled();
expect(view.sendToRenderer).toBeCalledWith(CALLS_WIDGET_OPEN_THREAD, threadID);
});
});

describe('handleCallsOpenStopRecordingModal', () => {
const view = {
id: 'main-view',
view: {
server: {
id: 'server-1',
Expand All @@ -932,12 +940,49 @@ describe('main/windows/callsWidgetWindow', () => {
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';
callsWidgetWindow.handleCallsOpenStopRecordingModal({sender: {id: 1}}, channelID);
expect(ServerViewState.switchServer).toHaveBeenCalledWith('server-1');
expect(ViewManager.showById).toHaveBeenCalledWith('main-view');
expect(focus).toHaveBeenCalled();
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();
});
});
});
16 changes: 12 additions & 4 deletions src/main/windows/callsWidgetWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,16 @@ export class CallsWidgetWindow {
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) => {
return (event: IpcMainEvent, ...args: any) => {
log.debug('forwardToMainApp', channel, ...args);
Expand All @@ -513,8 +523,7 @@ export class CallsWidgetWindow {
return;
}

ServerViewState.switchServer(this.serverID);
MainWindow.get()?.focus();
this.focusChannelView();
this.mainView?.sendToRenderer(channel, ...args);
};
};
Expand Down Expand Up @@ -547,8 +556,7 @@ export class CallsWidgetWindow {
// If parsing above fails it means it's a relative path (e.g.
// pointing to a channel).

ServerViewState.switchServer(this.serverID);
MainWindow.get()?.focus();
this.focusChannelView();
this.mainView?.sendToRenderer(BROWSER_HISTORY_PUSH, url);
};
}
Expand Down
Loading