-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fire an event upon the completion of the refreshSObjects comma…
…nd to notify E4D (#5584) * chore: add event emitter for refresh sobject command * fix: fix lint * chore: rename * chore: remove static * test: add tests * test: update test description * chore: delete commandEventdispather * chore: add commandEventDispacther back * chore: update imports reference * test: update nits --------- Co-authored-by: Mingxuan Zhang <132491513+mingxuanzhangsfdx@users.noreply.github.com> Co-authored-by: gbockus-sf <76090802+gbockus-sf@users.noreply.github.com>
- Loading branch information
1 parent
96a1954
commit 91eac1a
Showing
5 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/salesforcedx-vscode-core/src/commands/util/commandEventDispatcher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2024, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import * as vscode from 'vscode'; | ||
import { RefreshSObjectsExecutor } from '..'; | ||
|
||
export class CommandEventDispatcher implements vscode.Disposable { | ||
protected static instance: CommandEventDispatcher; | ||
|
||
public static getInstance(): CommandEventDispatcher { | ||
if (!CommandEventDispatcher.instance) { | ||
CommandEventDispatcher.instance = new CommandEventDispatcher(); | ||
} | ||
return CommandEventDispatcher.instance; | ||
} | ||
|
||
public onRefreshSObjectsCommandCompletion( | ||
listener: (event: unknown) => unknown | ||
): vscode.Disposable { | ||
return RefreshSObjectsExecutor.onRefreshSObjectsCommandCompletion(listener); | ||
} | ||
|
||
public dispose() { | ||
RefreshSObjectsExecutor.refreshSObjectsCommandCompletionEventEmitter.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/salesforcedx-vscode-core/test/jest/commands/util/commandEventDispatcher.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (c) 2024, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import * as vscode from 'vscode'; | ||
import { RefreshSObjectsExecutor } from '../../../../src/commands'; | ||
import { CommandEventDispatcher } from '../../../../src/commands/util/commandEventDispatcher'; | ||
|
||
describe('CommandEventDispatcher', () => { | ||
describe('getInstance', () => { | ||
it('should return the instance of CommandEventDispatcher', () => { | ||
const instance = CommandEventDispatcher.getInstance(); | ||
|
||
expect(instance).toBeDefined(); | ||
}); | ||
|
||
it('should return the same instance of CommandEventDispatcher', () => { | ||
const instance1 = CommandEventDispatcher.getInstance(); | ||
const instance2 = CommandEventDispatcher.getInstance(); | ||
|
||
expect(instance1).toBe(instance2); | ||
}); | ||
}); | ||
|
||
describe('onRefreshSObjectsCommandCompletion', () => { | ||
const mockDisposable = new vscode.Disposable(() => {}); | ||
|
||
beforeEach(() => { | ||
(RefreshSObjectsExecutor as any).onRefreshSObjectsCommandCompletion = jest | ||
.fn() | ||
.mockReturnValue(mockDisposable); | ||
}); | ||
|
||
it('should call refreshSObjectExecutor event and return the disposable', () => { | ||
const dispatcher = CommandEventDispatcher.getInstance(); | ||
const listener = () => {}; | ||
const disposable = | ||
dispatcher.onRefreshSObjectsCommandCompletion(listener); | ||
|
||
expect(disposable).toBe(mockDisposable); | ||
expect( | ||
(RefreshSObjectsExecutor as any).onRefreshSObjectsCommandCompletion | ||
).toHaveBeenCalledWith(listener); | ||
}); | ||
}); | ||
|
||
describe('dispose', () => { | ||
beforeEach(() => { | ||
( | ||
RefreshSObjectsExecutor as any | ||
).refreshSObjectsCommandCompletionEventEmitter = { dispose: jest.fn() }; | ||
}); | ||
|
||
it('should dispose the refreshSObjectsCommandCompletionEventEmitter', () => { | ||
const dispatcher = CommandEventDispatcher.getInstance(); | ||
dispatcher.dispose(); | ||
|
||
expect( | ||
(RefreshSObjectsExecutor as any) | ||
.refreshSObjectsCommandCompletionEventEmitter.dispose | ||
).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |