mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 08:43:33 +00:00
[PM-22756] Send minimizeOnCopy message during copy on Desktop platform (#15232)
* [PM-22756] Send minimizeOnCopy message during copy on Desktop platform * [PM-22756] Introduce optional CopyClickListener pattern * [PM-22756] Introduce CopyService that wraps PlatformUtilsService.copyToClipboard to allow scoped implementations * [PM-22756] Introduce DesktopVaultCopyService that sends the minimizeOnCopy message * [PM-22756] Remove leftover onCopy method * [PM-22756] Fix failing tests * [PM-22756] Revert CopyService solution * [PM-22756] Cleanup * [PM-22756] Update test * [PM-22756] Cleanup leftover test changes
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { Component, ElementRef, ViewChild } from "@angular/core";
|
||||
import { ComponentFixture, TestBed } from "@angular/core/testing";
|
||||
import { mock } from "jest-mock-extended";
|
||||
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
|
||||
import { ToastService } from "../";
|
||||
import { ToastService, CopyClickListener, COPY_CLICK_LISTENER } from "../";
|
||||
|
||||
import { CopyClickDirective } from "./copy-click.directive";
|
||||
|
||||
@@ -34,10 +35,12 @@ describe("CopyClickDirective", () => {
|
||||
let fixture: ComponentFixture<TestCopyClickComponent>;
|
||||
const copyToClipboard = jest.fn();
|
||||
const showToast = jest.fn();
|
||||
const copyClickListener = mock<CopyClickListener>();
|
||||
|
||||
beforeEach(async () => {
|
||||
copyToClipboard.mockClear();
|
||||
showToast.mockClear();
|
||||
copyClickListener.onCopy.mockClear();
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [TestCopyClickComponent],
|
||||
@@ -55,6 +58,7 @@ describe("CopyClickDirective", () => {
|
||||
},
|
||||
{ provide: PlatformUtilsService, useValue: { copyToClipboard } },
|
||||
{ provide: ToastService, useValue: { showToast } },
|
||||
{ provide: COPY_CLICK_LISTENER, useValue: copyClickListener },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
@@ -92,7 +96,6 @@ describe("CopyClickDirective", () => {
|
||||
successToastButton.click();
|
||||
expect(showToast).toHaveBeenCalledWith({
|
||||
message: "copySuccessful",
|
||||
title: null,
|
||||
variant: "success",
|
||||
});
|
||||
});
|
||||
@@ -103,7 +106,6 @@ describe("CopyClickDirective", () => {
|
||||
infoToastButton.click();
|
||||
expect(showToast).toHaveBeenCalledWith({
|
||||
message: "copySuccessful",
|
||||
title: null,
|
||||
variant: "info",
|
||||
});
|
||||
});
|
||||
@@ -115,8 +117,15 @@ describe("CopyClickDirective", () => {
|
||||
|
||||
expect(showToast).toHaveBeenCalledWith({
|
||||
message: "valueCopied Content",
|
||||
title: null,
|
||||
variant: "success",
|
||||
});
|
||||
});
|
||||
|
||||
it("should call copyClickListener.onCopy when value is copied", () => {
|
||||
const successToastButton = fixture.componentInstance.successToastButton.nativeElement;
|
||||
|
||||
successToastButton.click();
|
||||
|
||||
expect(copyClickListener.onCopy).toHaveBeenCalledWith("success toast shown");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user