1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-13 06:54:07 +00:00

Merge branch 'main' into ps/extension-refresh

This commit is contained in:
Vicki League
2024-08-07 11:08:31 -04:00
163 changed files with 4236 additions and 1148 deletions

View File

@@ -42,7 +42,7 @@ export class ApiActionDirective implements OnChanges {
this.logService.error("Captcha required error response: " + e.getSingleMessage());
return;
}
this.logService?.error(`Received API exception: ${e}`);
this.logService?.error(`Received API exception:`, e);
this.validationService.showError(e);
},
);

View File

@@ -12,12 +12,14 @@ import { CopyClickDirective } from "./copy-click.directive";
<button appCopyClick="no toast shown" #noToast></button>
<button appCopyClick="info toast shown" showToast="info" #infoToast></button>
<button appCopyClick="success toast shown" showToast #successToast></button>
<button appCopyClick="toast with label" showToast valueLabel="Content" #toastWithLabel></button>
`,
})
class TestCopyClickComponent {
@ViewChild("noToast") noToastButton: ElementRef<HTMLButtonElement>;
@ViewChild("infoToast") infoToastButton: ElementRef<HTMLButtonElement>;
@ViewChild("successToast") successToastButton: ElementRef<HTMLButtonElement>;
@ViewChild("toastWithLabel") toastWithLabelButton: ElementRef<HTMLButtonElement>;
}
describe("CopyClickDirective", () => {
@@ -32,7 +34,17 @@ describe("CopyClickDirective", () => {
await TestBed.configureTestingModule({
declarations: [CopyClickDirective, TestCopyClickComponent],
providers: [
{ provide: I18nService, useValue: { t: (key: string) => key } },
{
provide: I18nService,
useValue: {
t: (key: string, ...rest: string[]) => {
if (rest?.length) {
return `${key} ${rest.join("")}`;
}
return key;
},
},
},
{ provide: PlatformUtilsService, useValue: { copyToClipboard } },
{ provide: ToastService, useValue: { showToast } },
],
@@ -87,4 +99,16 @@ describe("CopyClickDirective", () => {
variant: "info",
});
});
it('includes label in toast message when "copyLabel" is set', () => {
const toastWithLabelButton = fixture.componentInstance.toastWithLabelButton.nativeElement;
toastWithLabelButton.click();
expect(showToast).toHaveBeenCalledWith({
message: "valueCopied Content",
title: null,
variant: "success",
});
});
});

View File

@@ -20,6 +20,12 @@ export class CopyClickDirective {
@Input("appCopyClick") valueToCopy = "";
/**
* When set, the toast displayed will show `<valueLabel> copied`
* instead of the default messaging.
*/
@Input() valueLabel: string;
/**
* When set without a value, a success toast will be shown when the value is copied
* @example
@@ -47,10 +53,14 @@ export class CopyClickDirective {
this.platformUtilsService.copyToClipboard(this.valueToCopy);
if (this._showToast) {
const message = this.valueLabel
? this.i18nService.t("valueCopied", this.valueLabel)
: this.i18nService.t("copySuccessful");
this.toastService.showToast({
variant: this.toastVariant,
title: null,
message: this.i18nService.t("copySuccessful"),
message,
});
}
}

View File

@@ -685,6 +685,7 @@ const safeProviders: SafeProvider[] = [
BillingAccountProfileStateService,
TokenServiceAbstraction,
AuthServiceAbstraction,
StateProvider,
],
}),
safeProvider({