1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-10 21:50:15 +00:00

[PM-22756] Send minimizeOnCopy message during copy on Desktop platform

This commit is contained in:
Shane
2025-06-17 12:37:38 -07:00
parent e8e61d2796
commit 37c9cffd06
2 changed files with 21 additions and 1 deletions

View File

@@ -1,7 +1,9 @@
import { Component, ElementRef, ViewChild } from "@angular/core";
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { ClientType } from "@bitwarden/common/enums";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ToastService } from "../";
@@ -34,6 +36,8 @@ describe("CopyClickDirective", () => {
let fixture: ComponentFixture<TestCopyClickComponent>;
const copyToClipboard = jest.fn();
const showToast = jest.fn();
const sendMessage = jest.fn();
const getClientType = jest.fn().mockReturnValue(ClientType.Web);
beforeEach(async () => {
copyToClipboard.mockClear();
@@ -53,8 +57,9 @@ describe("CopyClickDirective", () => {
},
},
},
{ provide: PlatformUtilsService, useValue: { copyToClipboard } },
{ provide: PlatformUtilsService, useValue: { copyToClipboard, getClientType } },
{ provide: ToastService, useValue: { showToast } },
{ provide: MessagingService, useValue: { send: sendMessage } },
],
}).compileComponents();
@@ -119,4 +124,12 @@ describe("CopyClickDirective", () => {
variant: "success",
});
});
it("sends minimize message when client is desktop", () => {
getClientType.mockReturnValue(ClientType.Desktop);
const successToastButton = fixture.componentInstance.successToastButton.nativeElement;
successToastButton.click();
expect(sendMessage).toHaveBeenCalledWith("minimizeOnCopy");
});
});

View File

@@ -2,7 +2,9 @@
// @ts-strict-ignore
import { Directive, HostListener, Input } from "@angular/core";
import { ClientType } from "@bitwarden/common/enums";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ToastService, ToastVariant } from "../";
@@ -18,6 +20,7 @@ export class CopyClickDirective {
private platformUtilsService: PlatformUtilsService,
private toastService: ToastService,
private i18nService: I18nService,
private messagingService: MessagingService,
) {}
@Input("appCopyClick") valueToCopy = "";
@@ -54,6 +57,10 @@ export class CopyClickDirective {
@HostListener("click") onClick() {
this.platformUtilsService.copyToClipboard(this.valueToCopy);
if (this.platformUtilsService.getClientType() === ClientType.Desktop) {
this.messagingService.send("minimizeOnCopy");
}
if (this._showToast) {
const message = this.valueLabel
? this.i18nService.t("valueCopied", this.valueLabel)