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:
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user