1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 06:13:38 +00:00

migrate platform toasts to CL toastService (#10666)

This commit is contained in:
Jordan Aasen
2024-08-22 10:12:27 -07:00
committed by GitHub
parent d2d49b254d
commit 898338ff9d
2 changed files with 17 additions and 14 deletions

View File

@@ -8,8 +8,7 @@ import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { I18nMockService, ToastService } from "@bitwarden/components/src";
import { I18nMockService } from "@bitwarden/components/src";
import { canAccessFeature } from "./feature-flag.guard"; import { canAccessFeature } from "./feature-flag.guard";
@@ -22,11 +21,11 @@ describe("canAccessFeature", () => {
const redirectRoute = "redirect"; const redirectRoute = "redirect";
let mockConfigService: MockProxy<ConfigService>; let mockConfigService: MockProxy<ConfigService>;
let mockPlatformUtilsService: MockProxy<PlatformUtilsService>; let mockToastService: MockProxy<ToastService>;
const setup = (featureGuard: CanActivateFn, flagValue: any) => { const setup = (featureGuard: CanActivateFn, flagValue: any) => {
mockConfigService = mock<ConfigService>(); mockConfigService = mock<ConfigService>();
mockPlatformUtilsService = mock<PlatformUtilsService>(); mockToastService = mock<ToastService>();
// Mock the correct getter based on the type of flagValue; also mock default values if one is not provided // Mock the correct getter based on the type of flagValue; also mock default values if one is not provided
if (typeof flagValue === "boolean") { if (typeof flagValue === "boolean") {
@@ -57,7 +56,7 @@ describe("canAccessFeature", () => {
], ],
providers: [ providers: [
{ provide: ConfigService, useValue: mockConfigService }, { provide: ConfigService, useValue: mockConfigService },
{ provide: PlatformUtilsService, useValue: mockPlatformUtilsService }, { provide: ToastService, useValue: mockToastService },
{ provide: LogService, useValue: mock<LogService>() }, { provide: LogService, useValue: mock<LogService>() },
{ {
provide: I18nService, provide: I18nService,
@@ -117,11 +116,11 @@ describe("canAccessFeature", () => {
await router.navigate([featureRoute]); await router.navigate([featureRoute]);
expect(mockPlatformUtilsService.showToast).toHaveBeenCalledWith( expect(mockToastService.showToast).toHaveBeenCalledWith({
"error", variant: "error",
null, title: null,
"Access Denied!", message: "Access Denied!",
); });
}); });
it("does not show an error toast when the feature flag is enabled", async () => { it("does not show an error toast when the feature flag is enabled", async () => {
@@ -129,7 +128,7 @@ describe("canAccessFeature", () => {
await router.navigate([featureRoute]); await router.navigate([featureRoute]);
expect(mockPlatformUtilsService.showToast).not.toHaveBeenCalled(); expect(mockToastService.showToast).not.toHaveBeenCalled();
}); });
it("redirects to the specified redirect url when the feature flag is disabled", async () => { it("redirects to the specified redirect url when the feature flag is disabled", async () => {

View File

@@ -5,7 +5,7 @@ import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { ToastService } from "@bitwarden/components";
// Replace this with a type safe lookup of the feature flag values in PM-2282 // Replace this with a type safe lookup of the feature flag values in PM-2282
type FlagValue = boolean | number | string; type FlagValue = boolean | number | string;
@@ -24,7 +24,7 @@ export const canAccessFeature = (
): CanActivateFn => { ): CanActivateFn => {
return async () => { return async () => {
const configService = inject(ConfigService); const configService = inject(ConfigService);
const platformUtilsService = inject(PlatformUtilsService); const toastService = inject(ToastService);
const router = inject(Router); const router = inject(Router);
const i18nService = inject(I18nService); const i18nService = inject(I18nService);
const logService = inject(LogService); const logService = inject(LogService);
@@ -36,7 +36,11 @@ export const canAccessFeature = (
return true; return true;
} }
platformUtilsService.showToast("error", null, i18nService.t("accessDenied")); toastService.showToast({
variant: "error",
title: null,
message: i18nService.t("accessDenied"),
});
if (redirectUrlOnDisabled != null) { if (redirectUrlOnDisabled != null) {
return router.createUrlTree([redirectUrlOnDisabled]); return router.createUrlTree([redirectUrlOnDisabled]);