1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 05:13:29 +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 DomElementVisibilityService from "../../../services/dom-element-visibility.service";
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 { OverlayNotificationsContentService } from "./overlay-notifications-content.service";
@@ -17,6 +19,11 @@ describe("OverlayNotificationsContentService", () => {
beforeEach(() => {
jest.useFakeTimers();
jest
.spyOn(utils, "sendExtensionMessage")
.mockImplementation((command: string) =>
Promise.resolve(command === "notificationRefreshFlagValue" ? false : true),
);
domQueryService = mock<DomQueryService>();
domElementVisibilityService = new DomElementVisibilityService();
overlayNotificationsContentService = new OverlayNotificationsContentService();
@@ -45,8 +52,7 @@ describe("OverlayNotificationsContentService", () => {
});
it("applies correct styles when notificationRefreshFlag is true", async () => {
overlayNotificationsContentService["notificationRefreshFlag"] = true;
(sendExtensionMessage as jest.Mock).mockResolvedValue(true);
sendMockExtensionMessage({
command: "openNotificationBar",
data: {
@@ -62,8 +68,6 @@ describe("OverlayNotificationsContentService", () => {
});
it("applies correct styles when notificationRefreshFlag is false", async () => {
overlayNotificationsContentService["notificationRefreshFlag"] = false;
sendMockExtensionMessage({
command: "openNotificationBar",
data: {
@@ -208,10 +212,7 @@ describe("OverlayNotificationsContentService", () => {
jest.advanceTimersByTime(150);
expect(chrome.runtime.sendMessage).toHaveBeenCalledWith(
{ command: "bgRemoveTabFromNotificationQueue" },
expect.any(Function),
);
expect(sendExtensionMessage).toHaveBeenCalledWith("bgRemoveTabFromNotificationQueue");
});
it("closes the notification bar without a fadeout", () => {

View File

@@ -67,9 +67,6 @@ export class OverlayNotificationsContentService
constructor() {
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.
*/
private handleOpenNotificationBarMessage(message: NotificationsExtensionMessage) {
private async handleOpenNotificationBarMessage(message: NotificationsExtensionMessage) {
if (!message.data) {
return;
}
const { type, typeData, params } = message.data;
if (this.currentNotificationBarType && type !== this.currentNotificationBarType) {
@@ -105,6 +101,10 @@ export class OverlayNotificationsContentService
params,
};
await sendExtensionMessage("notificationRefreshFlagValue").then((notificationRefreshFlag) => {
this.notificationRefreshFlag = !!notificationRefreshFlag;
});
if (globalThis.document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", () => this.openNotificationBar(initData));
return;