1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-10 19:38:11 +01:00

[PM-5189] Adding jest tests for added methods in AutofillInit

This commit is contained in:
Cesar Gonzalez 2024-06-07 11:38:09 -05:00
parent 4b241fe47f
commit 873cfa51cd
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF
2 changed files with 23 additions and 0 deletions

View File

@ -155,6 +155,24 @@ describe("AutofillInit", () => {
autofillInit.init();
});
it("triggers extension message handlers from the AutofillOverlayContentService", () => {
autofillOverlayContentService.extensionMessageHandlers.messageHandler = jest.fn();
sendMockExtensionMessage({ command: "messageHandler" }, sender, sendResponse);
expect(
autofillOverlayContentService.extensionMessageHandlers.messageHandler,
).toHaveBeenCalled();
});
it("triggers extension message handlers from the AutofillInlineMenuContentService", () => {
inlineMenuElements.extensionMessageHandlers.messageHandler = jest.fn();
sendMockExtensionMessage({ command: "messageHandler" }, sender, sendResponse);
expect(inlineMenuElements.extensionMessageHandlers.messageHandler).toHaveBeenCalled();
});
describe("collectPageDetails", () => {
it("sends the collected page details for autofill using a background script message", async () => {
const pageDetails: AutofillPageDetails = {

View File

@ -190,6 +190,11 @@ class AutofillInit implements AutofillInitInterface {
return true;
};
/**
* Gets the extension message handler for the given command.
*
* @param command - The extension message command.
*/
private getExtensionMessageHandler(command: string): CallableFunction | undefined {
if (this.autofillOverlayContentService?.extensionMessageHandlers?.[command]) {
return this.autofillOverlayContentService.extensionMessageHandlers[command];