Fix race condition on switching calls (#2591)

This commit is contained in:
Claudio Costa
2023-03-07 18:23:21 -06:00
committed by GitHub
parent 893f13e59d
commit 49ed221659
4 changed files with 73 additions and 26 deletions

View File

@@ -1032,6 +1032,23 @@ describe('main/windows/windowManager', () => {
},
},
};
beforeEach(() => {
CallsWidgetWindow.mockImplementation(() => {
return {
win: {
isDestroyed: jest.fn(() => true),
},
on: jest.fn(),
close: jest.fn(),
};
});
});
afterEach(() => {
jest.resetAllMocks();
});
const windowManager = new WindowManager();
windowManager.viewManager = {
views: new Map([
@@ -1039,25 +1056,25 @@ describe('main/windows/windowManager', () => {
]),
};
it('should create calls widget window', () => {
it('should create calls widget window', async () => {
expect(windowManager.callsWidgetWindow).toBeUndefined();
windowManager.createCallsWidgetWindow('server-1_tab-messaging', {callID: 'test'});
await windowManager.createCallsWidgetWindow('server-1_tab-messaging', {callID: 'test'});
expect(windowManager.callsWidgetWindow).toBeDefined();
});
it('should not create a new window if call is the same', () => {
it('should not create a new window if call is the same', async () => {
const widgetWindow = windowManager.callsWidgetWindow;
expect(widgetWindow).toBeDefined();
widgetWindow.getCallID = jest.fn(() => 'test');
windowManager.createCallsWidgetWindow('server-1_tab-messaging', {callID: 'test'});
await windowManager.createCallsWidgetWindow('server-1_tab-messaging', {callID: 'test'});
expect(windowManager.callsWidgetWindow).toEqual(widgetWindow);
});
it('should create a new window if switching calls', () => {
it('should create a new window if switching calls', async () => {
const widgetWindow = windowManager.callsWidgetWindow;
expect(widgetWindow).toBeDefined();
widgetWindow.getCallID = jest.fn(() => 'test');
windowManager.createCallsWidgetWindow('server-1_tab-messaging', {callID: 'test2'});
await windowManager.createCallsWidgetWindow('server-1_tab-messaging', {callID: 'test2'});
expect(windowManager.callsWidgetWindow).not.toEqual(widgetWindow);
});
});