1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 13:53:34 +00:00

PM-23674 The v3 notification is using erroneous notification sizing in some cases (#15562)

* PM-23674

* remove duplicate mock
This commit is contained in:
Daniel Riera
2025-07-11 17:04:50 -04:00
committed by GitHub
parent 5f53987873
commit c1818b32e7
2 changed files with 14 additions and 13 deletions

View File

@@ -4,6 +4,8 @@ import AutofillInit from "../../../content/autofill-init";
import { DomQueryService } from "../../../services/abstractions/dom-query.service"; import { DomQueryService } from "../../../services/abstractions/dom-query.service";
import DomElementVisibilityService from "../../../services/dom-element-visibility.service"; import DomElementVisibilityService from "../../../services/dom-element-visibility.service";
import { flushPromises, sendMockExtensionMessage } from "../../../spec/testing-utils"; import { flushPromises, sendMockExtensionMessage } from "../../../spec/testing-utils";
import * as utils from "../../../utils";
import { sendExtensionMessage } from "../../../utils";
import { NotificationTypeData } from "../abstractions/overlay-notifications-content.service"; import { NotificationTypeData } from "../abstractions/overlay-notifications-content.service";
import { OverlayNotificationsContentService } from "./overlay-notifications-content.service"; import { OverlayNotificationsContentService } from "./overlay-notifications-content.service";
@@ -17,6 +19,11 @@ describe("OverlayNotificationsContentService", () => {
beforeEach(() => { beforeEach(() => {
jest.useFakeTimers(); jest.useFakeTimers();
jest
.spyOn(utils, "sendExtensionMessage")
.mockImplementation((command: string) =>
Promise.resolve(command === "notificationRefreshFlagValue" ? false : true),
);
domQueryService = mock<DomQueryService>(); domQueryService = mock<DomQueryService>();
domElementVisibilityService = new DomElementVisibilityService(); domElementVisibilityService = new DomElementVisibilityService();
overlayNotificationsContentService = new OverlayNotificationsContentService(); overlayNotificationsContentService = new OverlayNotificationsContentService();
@@ -45,8 +52,7 @@ describe("OverlayNotificationsContentService", () => {
}); });
it("applies correct styles when notificationRefreshFlag is true", async () => { it("applies correct styles when notificationRefreshFlag is true", async () => {
overlayNotificationsContentService["notificationRefreshFlag"] = true; (sendExtensionMessage as jest.Mock).mockResolvedValue(true);
sendMockExtensionMessage({ sendMockExtensionMessage({
command: "openNotificationBar", command: "openNotificationBar",
data: { data: {
@@ -62,8 +68,6 @@ describe("OverlayNotificationsContentService", () => {
}); });
it("applies correct styles when notificationRefreshFlag is false", async () => { it("applies correct styles when notificationRefreshFlag is false", async () => {
overlayNotificationsContentService["notificationRefreshFlag"] = false;
sendMockExtensionMessage({ sendMockExtensionMessage({
command: "openNotificationBar", command: "openNotificationBar",
data: { data: {
@@ -208,10 +212,7 @@ describe("OverlayNotificationsContentService", () => {
jest.advanceTimersByTime(150); jest.advanceTimersByTime(150);
expect(chrome.runtime.sendMessage).toHaveBeenCalledWith( expect(sendExtensionMessage).toHaveBeenCalledWith("bgRemoveTabFromNotificationQueue");
{ command: "bgRemoveTabFromNotificationQueue" },
expect.any(Function),
);
}); });
it("closes the notification bar without a fadeout", () => { it("closes the notification bar without a fadeout", () => {

View File

@@ -67,9 +67,6 @@ export class OverlayNotificationsContentService
constructor() { constructor() {
void sendExtensionMessage("checkNotificationQueue"); void sendExtensionMessage("checkNotificationQueue");
void sendExtensionMessage("notificationRefreshFlagValue").then((notificationRefreshFlag) => {
this.notificationRefreshFlag = !!notificationRefreshFlag;
});
} }
/** /**
@@ -85,11 +82,10 @@ export class OverlayNotificationsContentService
* *
* @param message - The message containing the initialization data for the notification bar. * @param message - The message containing the initialization data for the notification bar.
*/ */
private handleOpenNotificationBarMessage(message: NotificationsExtensionMessage) { private async handleOpenNotificationBarMessage(message: NotificationsExtensionMessage) {
if (!message.data) { if (!message.data) {
return; return;
} }
const { type, typeData, params } = message.data; const { type, typeData, params } = message.data;
if (this.currentNotificationBarType && type !== this.currentNotificationBarType) { if (this.currentNotificationBarType && type !== this.currentNotificationBarType) {
@@ -105,6 +101,10 @@ export class OverlayNotificationsContentService
params, params,
}; };
await sendExtensionMessage("notificationRefreshFlagValue").then((notificationRefreshFlag) => {
this.notificationRefreshFlag = !!notificationRefreshFlag;
});
if (globalThis.document.readyState === "loading") { if (globalThis.document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", () => this.openNotificationBar(initData)); document.addEventListener("DOMContentLoaded", () => this.openNotificationBar(initData));
return; return;