Skip to content
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
7 changes: 3 additions & 4 deletions e2e/specs/calls/calls_functionality.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {ElectronApplication} from 'playwright';
import {test, expect} from '../../fixtures/index';
import {findCallsWidgetWindow, waitForCallsWidgetWindow} from '../../helpers/callsWidget';
import {demoMattermostConfig} from '../../helpers/config';
import {CALLS_LEAVE_CALL} from '../../helpers/ipcChannels';
import {loginToMattermost} from '../../helpers/login';
import type {ServerView} from '../../helpers/serverView';

Expand Down Expand Up @@ -205,9 +204,9 @@ async function closeCallsWidget(
});

if (!leaveClicked) {
await electronApp.evaluate(({ipcMain}, channel) => {
ipcMain.emit(channel);
}, CALLS_LEAVE_CALL);
await widgetWindow.evaluate(() => {
(window as unknown as {desktopAPI?: {leaveCall: () => void}}).desktopAPI?.leaveCall();
});
}

await expect.poll(
Expand Down
32 changes: 32 additions & 0 deletions src/app/callsWidgetWindow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,38 @@ describe('main/windows/callsWidgetWindow', () => {
expect(callsWidgetWindow.win.webContents.send).toHaveBeenCalledWith(CALLS_WIDGET_SHARE_SCREEN, 'sourceId', true);
});

describe('handleCallsLeave', () => {
const callsWidgetWindow = new CallsWidgetWindow();

beforeEach(() => {
callsWidgetWindow.close = jest.fn();
callsWidgetWindow.mainView = {webContentsId: 'mainViewID'};
callsWidgetWindow.win = {webContents: {id: 'widgetID'}, isDestroyed: () => false};
callsWidgetWindow.popOut = undefined;
});

afterEach(() => {
jest.clearAllMocks();
delete callsWidgetWindow.mainView;
delete callsWidgetWindow.win;
});

it('should not close when the sender is a different server', () => {
callsWidgetWindow.handleCallsLeave({sender: {id: 'otherServerID'}});
expect(callsWidgetWindow.close).not.toHaveBeenCalled();
});

it('should close when the sender is the calls widget', () => {
callsWidgetWindow.handleCallsLeave({sender: {id: 'widgetID'}});
expect(callsWidgetWindow.close).toHaveBeenCalled();
});

it('should close when the sender is the main view of the call', () => {
callsWidgetWindow.handleCallsLeave({sender: {id: 'mainViewID'}});
expect(callsWidgetWindow.close).toHaveBeenCalled();
});
});

describe('onPopOutOpen', () => {
const callsWidgetWindow = new CallsWidgetWindow();

Expand Down
7 changes: 6 additions & 1 deletion src/app/callsWidgetWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,14 @@ export class CallsWidgetWindow {
return promise;
};

private handleCallsLeave = () => {
private handleCallsLeave = (event: IpcMainEvent) => {
log.debug('handleCallsLeave');

if (!this.isCallsWidget(event.sender.id) && this.mainView?.webContentsId !== event.sender.id) {
log.debug('handleCallsLeave', 'blocked on wrong webContentsId');
return;
}

this.close();
};

Expand Down
Loading