1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 09:43:23 +00:00

[PM-21663] nudge service name refactor (#14789)

* update names of vault nudge service and their corresponding files, convert components using showNudge$ to instead target spotlight and badges directly with new observables. Core logic for dismiss remains the same
This commit is contained in:
Jason Ng
2025-05-15 15:10:38 -04:00
committed by GitHub
parent 82d0925f4e
commit ee4c3cfd94
20 changed files with 199 additions and 152 deletions

View File

@@ -36,7 +36,7 @@ import {
CipherFormGenerationService,
NudgeStatus,
PasswordRepromptService,
VaultNudgesService,
NudgesService,
} from "@bitwarden/vault";
// FIXME: remove `/apps` import from `/libs`
// FIXME: remove `src` and fix import
@@ -144,7 +144,7 @@ export default {
],
providers: [
{
provide: VaultNudgesService,
provide: NudgesService,
useValue: {
showNudge$: new BehaviorSubject({
hasBadgeDismissed: true,

View File

@@ -8,7 +8,7 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
import { UserId } from "@bitwarden/common/types/guid";
import { CipherType } from "@bitwarden/sdk-internal";
import { VaultNudgesService, VaultNudgeType } from "../../../services/vault-nudges.service";
import { NudgesService, NudgeType } from "../../../services/nudges.service";
import { NewItemNudgeComponent } from "./new-item-nudge.component";
@@ -18,19 +18,19 @@ describe("NewItemNudgeComponent", () => {
let i18nService: MockProxy<I18nService>;
let accountService: MockProxy<AccountService>;
let vaultNudgesService: MockProxy<VaultNudgesService>;
let nudgesService: MockProxy<NudgesService>;
beforeEach(async () => {
i18nService = mock<I18nService>({ t: (key: string) => key });
accountService = mock<AccountService>();
vaultNudgesService = mock<VaultNudgesService>();
nudgesService = mock<NudgesService>();
await TestBed.configureTestingModule({
imports: [NewItemNudgeComponent, CommonModule],
providers: [
{ provide: I18nService, useValue: i18nService },
{ provide: AccountService, useValue: accountService },
{ provide: VaultNudgesService, useValue: vaultNudgesService },
{ provide: NudgesService, useValue: nudgesService },
],
}).compileComponents();
});
@@ -58,7 +58,7 @@ describe("NewItemNudgeComponent", () => {
expect(component.nudgeBody).toBe(
"newLoginNudgeBodyOne <strong>newLoginNudgeBodyBold</strong> newLoginNudgeBodyTwo",
);
expect(component.dismissalNudgeType).toBe(VaultNudgeType.newLoginItemStatus);
expect(component.dismissalNudgeType).toBe(NudgeType.NewLoginItemStatus);
});
it("should set nudge title and body for CipherType.Card type", async () => {
@@ -71,7 +71,7 @@ describe("NewItemNudgeComponent", () => {
expect(component.showNewItemSpotlight).toBe(true);
expect(component.nudgeTitle).toBe("newCardNudgeTitle");
expect(component.nudgeBody).toBe("newCardNudgeBody");
expect(component.dismissalNudgeType).toBe(VaultNudgeType.newCardItemStatus);
expect(component.dismissalNudgeType).toBe(NudgeType.NewCardItemStatus);
});
it("should not show anything if spotlight has been dismissed", async () => {
@@ -82,22 +82,19 @@ describe("NewItemNudgeComponent", () => {
await component.ngOnInit();
expect(component.showNewItemSpotlight).toBe(false);
expect(component.dismissalNudgeType).toBe(VaultNudgeType.newIdentityItemStatus);
expect(component.dismissalNudgeType).toBe(NudgeType.NewIdentityItemStatus);
});
it("should set showNewItemSpotlight to false when user dismisses spotlight", async () => {
component.showNewItemSpotlight = true;
component.dismissalNudgeType = VaultNudgeType.newLoginItemStatus;
component.dismissalNudgeType = NudgeType.NewLoginItemStatus;
component.activeUserId = "test-user-id" as UserId;
const dismissSpy = jest.spyOn(vaultNudgesService, "dismissNudge").mockResolvedValue();
const dismissSpy = jest.spyOn(nudgesService, "dismissNudge").mockResolvedValue();
await component.dismissNewItemSpotlight();
expect(component.showNewItemSpotlight).toBe(false);
expect(dismissSpy).toHaveBeenCalledWith(
VaultNudgeType.newLoginItemStatus,
component.activeUserId,
);
expect(dismissSpy).toHaveBeenCalledWith(NudgeType.NewLoginItemStatus, component.activeUserId);
});
});

View File

@@ -9,7 +9,7 @@ import { UserId } from "@bitwarden/common/types/guid";
import { CipherType } from "@bitwarden/sdk-internal";
import { SpotlightComponent } from "../../../components/spotlight/spotlight.component";
import { VaultNudgesService, VaultNudgeType } from "../../../services/vault-nudges.service";
import { NudgesService, NudgeType } from "../../../services/nudges.service";
@Component({
selector: "vault-new-item-nudge",
@@ -23,12 +23,12 @@ export class NewItemNudgeComponent implements OnInit {
showNewItemSpotlight: boolean = false;
nudgeTitle: string = "";
nudgeBody: string = "";
dismissalNudgeType: VaultNudgeType | null = null;
dismissalNudgeType: NudgeType | null = null;
constructor(
private i18nService: I18nService,
private accountService: AccountService,
private vaultNudgesService: VaultNudgesService,
private nudgesService: NudgesService,
) {}
async ngOnInit() {
@@ -39,25 +39,25 @@ export class NewItemNudgeComponent implements OnInit {
const nudgeBodyOne = this.i18nService.t("newLoginNudgeBodyOne");
const nudgeBodyBold = this.i18nService.t("newLoginNudgeBodyBold");
const nudgeBodyTwo = this.i18nService.t("newLoginNudgeBodyTwo");
this.dismissalNudgeType = VaultNudgeType.newLoginItemStatus;
this.dismissalNudgeType = NudgeType.NewLoginItemStatus;
this.nudgeTitle = this.i18nService.t("newLoginNudgeTitle");
this.nudgeBody = `${nudgeBodyOne} <strong>${nudgeBodyBold}</strong> ${nudgeBodyTwo}`;
break;
}
case CipherType.Card:
this.dismissalNudgeType = VaultNudgeType.newCardItemStatus;
this.dismissalNudgeType = NudgeType.NewCardItemStatus;
this.nudgeTitle = this.i18nService.t("newCardNudgeTitle");
this.nudgeBody = this.i18nService.t("newCardNudgeBody");
break;
case CipherType.Identity:
this.dismissalNudgeType = VaultNudgeType.newIdentityItemStatus;
this.dismissalNudgeType = NudgeType.NewIdentityItemStatus;
this.nudgeTitle = this.i18nService.t("newIdentityNudgeTitle");
this.nudgeBody = this.i18nService.t("newIdentityNudgeBody");
break;
case CipherType.SecureNote:
this.dismissalNudgeType = VaultNudgeType.newNoteItemStatus;
this.dismissalNudgeType = NudgeType.NewNoteItemStatus;
this.nudgeTitle = this.i18nService.t("newNoteNudgeTitle");
this.nudgeBody = this.i18nService.t("newNoteNudgeBody");
break;
@@ -66,7 +66,7 @@ export class NewItemNudgeComponent implements OnInit {
const sshPartOne = this.i18nService.t("newSshNudgeBodyOne");
const sshPartTwo = this.i18nService.t("newSshNudgeBodyTwo");
this.dismissalNudgeType = VaultNudgeType.newSshItemStatus;
this.dismissalNudgeType = NudgeType.NewSshItemStatus;
this.nudgeTitle = this.i18nService.t("newSshNudgeTitle");
this.nudgeBody = `${sshPartOne} <a href="https://bitwarden.com/help/ssh-agent" class="tw-text-primary-600 tw-font-bold" target="_blank">${sshPartTwo}</a>`;
break;
@@ -75,23 +75,19 @@ export class NewItemNudgeComponent implements OnInit {
throw new Error("Unsupported cipher type");
}
this.showNewItemSpotlight = await this.checkHasSpotlightDismissed(
this.dismissalNudgeType as VaultNudgeType,
this.dismissalNudgeType as NudgeType,
this.activeUserId,
);
}
async dismissNewItemSpotlight() {
if (this.dismissalNudgeType && this.activeUserId) {
await this.vaultNudgesService.dismissNudge(
this.dismissalNudgeType,
this.activeUserId as UserId,
);
await this.nudgesService.dismissNudge(this.dismissalNudgeType, this.activeUserId as UserId);
this.showNewItemSpotlight = false;
}
}
async checkHasSpotlightDismissed(nudgeType: VaultNudgeType, userId: UserId): Promise<boolean> {
return !(await firstValueFrom(this.vaultNudgesService.showNudge$(nudgeType, userId)))
.hasSpotlightDismissed;
async checkHasSpotlightDismissed(nudgeType: NudgeType, userId: UserId): Promise<boolean> {
return await firstValueFrom(this.nudgesService.showNudgeSpotlight$(nudgeType, userId));
}
}