1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 01:33:33 +00:00

[PM-5189] Fixing jest tests within AutofillOverlayContentService

This commit is contained in:
Cesar Gonzalez
2024-04-08 13:25:55 -05:00
parent 35ebcc3fd7
commit 43181fd794
3 changed files with 1318 additions and 1696 deletions

View File

@@ -44,7 +44,8 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
blurMostRecentOverlayField: () => this.blurMostRecentOverlayField(), blurMostRecentOverlayField: () => this.blurMostRecentOverlayField(),
bgUnlockPopoutOpened: () => this.blurMostRecentOverlayField(true), bgUnlockPopoutOpened: () => this.blurMostRecentOverlayField(true),
bgVaultItemRepromptPopoutOpened: () => this.blurMostRecentOverlayField(true), bgVaultItemRepromptPopoutOpened: () => this.blurMostRecentOverlayField(true),
redirectOverlayFocusOut: ({ message }) => this.redirectOverlayFocusOut(message), redirectOverlayFocusOut: ({ message }) =>
this.redirectOverlayFocusOut(message?.data?.direction),
updateAutofillOverlayVisibility: ({ message }) => this.updateAutofillOverlayVisibility(message), updateAutofillOverlayVisibility: ({ message }) => this.updateAutofillOverlayVisibility(message),
getSubFrameOffsets: ({ message }) => this.getSubFrameOffsets(message), getSubFrameOffsets: ({ message }) => this.getSubFrameOffsets(message),
getSubFrameOffsetsFromWindowMessage: ({ message }) => getSubFrameOffsetsFromWindowMessage: ({ message }) =>
@@ -178,18 +179,13 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
* either previous or next in the tab order. If the direction is current, the most * either previous or next in the tab order. If the direction is current, the most
* recently focused field will be focused. * recently focused field will be focused.
* *
* @param data - Contains the direction to redirect the focus. * @param direction - The direction to redirect the focus out.
*/ */
async redirectOverlayFocusOut({ data }: AutofillExtensionMessage) { async redirectOverlayFocusOut(direction?: string) {
if ( if (!direction || !this.mostRecentlyFocusedField || !(await this.isInlineMenuListVisible())) {
!data?.direction ||
!this.mostRecentlyFocusedField ||
!(await this.isInlineMenuListVisible())
) {
return; return;
} }
const { direction } = data;
if (direction === RedirectFocusDirection.Current) { if (direction === RedirectFocusDirection.Current) {
this.focusMostRecentOverlayField(); this.focusMostRecentOverlayField();
setTimeout(() => void this.sendExtensionMessage("closeAutofillOverlay"), 100); setTimeout(() => void this.sendExtensionMessage("closeAutofillOverlay"), 100);
@@ -764,7 +760,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
}, 50); }, 50);
this.clearUserInteractionEventTimeout(); this.clearUserInteractionEventTimeout();
if (this.isRepositionedFocusedFieldOutOfBounds()) { if (this.isFocusedFieldWithinViewportBounds()) {
return; return;
} }
@@ -789,7 +785,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
} }
} }
private isRepositionedFocusedFieldOutOfBounds() { private isFocusedFieldWithinViewportBounds() {
const focusedFieldRectsTop = this.focusedFieldData?.focusedFieldRects?.top; const focusedFieldRectsTop = this.focusedFieldData?.focusedFieldRects?.top;
return ( return (
focusedFieldRectsTop && focusedFieldRectsTop &&

View File

@@ -275,6 +275,21 @@ function createPortSpyMock(name: string) {
}); });
} }
function createMutationRecordMock(customFields = {}): MutationRecord {
return {
addedNodes: mock<NodeList>(),
attributeName: "default-attributeName",
attributeNamespace: "default-attributeNamespace",
nextSibling: null,
oldValue: "default-oldValue",
previousSibling: null,
removedNodes: mock<NodeList>(),
target: null,
type: "attributes",
...customFields,
};
}
export { export {
createAutofillFormMock, createAutofillFormMock,
createAutofillFieldMock, createAutofillFieldMock,
@@ -287,4 +302,5 @@ export {
createInitAutofillOverlayListMessageMock, createInitAutofillOverlayListMessageMock,
createFocusedFieldDataMock, createFocusedFieldDataMock,
createPortSpyMock, createPortSpyMock,
createMutationRecordMock,
}; };