Skip to content

Commit 03718a8

Browse files
committed
simpler I18nService mock
1 parent 06985a4 commit 03718a8

File tree

2 files changed

+7
-53
lines changed

2 files changed

+7
-53
lines changed

apps/web/src/app/key-management/change-kdf/change-kdf-confirmation.component.spec.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,7 @@ describe("ChangeKdfConfirmationComponent", () => {
4545
accountService = mockAccountServiceWith(mockUserId, { email: mockEmail });
4646
mockChangeKdfService = mock<ChangeKdfService>();
4747

48-
// Mock i18n service
49-
mockI18nService.t.mockImplementation((key: string) => {
50-
switch (key) {
51-
case "encKeySettingsChanged":
52-
return "Encryption key settings changed";
53-
case "logBackIn":
54-
return "Please log back in";
55-
default:
56-
return key;
57-
}
58-
});
48+
mockI18nService.t.mockImplementation((key) => `${key}-used-i18n`);
5949

6050
// Mock config service feature flag
6151
mockConfigService.getFeatureFlag$.mockReturnValue(of(false));
@@ -218,7 +208,7 @@ describe("ChangeKdfConfirmationComponent", () => {
218208
);
219209
expect(mockToastService.showToast).toHaveBeenCalledWith({
220210
variant: "success",
221-
message: "Encryption key settings changed",
211+
message: "encKeySettingsChanged-used-i18n",
222212
});
223213
expect(mockDialogRef.close).toHaveBeenCalled();
224214
expect(mockMessagingService.send).not.toHaveBeenCalled();
@@ -242,8 +232,8 @@ describe("ChangeKdfConfirmationComponent", () => {
242232
);
243233
expect(mockToastService.showToast).toHaveBeenCalledWith({
244234
variant: "success",
245-
title: "Encryption key settings changed",
246-
message: "Please log back in",
235+
title: "encKeySettingsChanged-used-i18n",
236+
message: "logBackIn-used-i18n",
247237
});
248238
expect(mockMessagingService.send).toHaveBeenCalledWith("logout");
249239
expect(mockDialogRef.close).not.toHaveBeenCalled();

apps/web/src/app/key-management/change-kdf/change-kdf.component.spec.ts

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -96,43 +96,7 @@ describe("ChangeKdfComponent", () => {
9696

9797
mockConfigService.getFeatureFlag$.mockReturnValue(of(false));
9898

99-
// Mock i18n service with switch statement for all keys
100-
mockI18nService.t.mockImplementation((key: string) => {
101-
switch (key) {
102-
case "encKeySettings":
103-
return "Encryption Key Settings";
104-
case "kdfSettingsChangeLogoutWarning":
105-
return "Proceeding will log you out of all active sessions. You will need to log back in and complete two-step login, if any. We recommend exporting your vault before changing your encryption settings to prevent data loss.";
106-
case "encryptionKeySettingsHowShouldWeEncryptYourData":
107-
return "How should we encrypt your data?";
108-
case "encryptionKeySettingsIncreaseImproveSecurity":
109-
return "Increase the number of iterations to improve security at the cost of slower login times.";
110-
case "algorithm":
111-
return "Algorithm";
112-
case "kdfIterations":
113-
return "KDF Iterations";
114-
case "kdfIterationRecommends":
115-
return "Minimum 100,000 iterations recommended.";
116-
case "kdfMemory":
117-
return "Memory (MB)";
118-
case "kdfParallelism":
119-
return "Parallelism";
120-
case "updateEncryptionSettings":
121-
return "Update Encryption Settings";
122-
case "encryptionKeySettingsAlgorithmPopoverTitle":
123-
return "Encryption Key Settings";
124-
case "encryptionKeySettingsAlgorithmPopoverPBKDF2":
125-
return "PBKDF2 SHA-256 is the default algorithm and is supported by all Bitwarden applications.";
126-
case "encryptionKeySettingsAlgorithmPopoverArgon2Id":
127-
return "Argon2id is a newer algorithm that is more secure but may not be supported by older Bitwarden applications.";
128-
case "learnMoreAboutEncryptionAlgorithms":
129-
return "Learn more about encryption algorithms";
130-
case "learnMore":
131-
return "Learn more";
132-
default:
133-
return key;
134-
}
135-
});
99+
mockI18nService.t.mockImplementation((key) => `${key}-used-i18n`);
136100

137101
TestBed.configureTestingModule({
138102
declarations: [ChangeKdfComponent],
@@ -230,13 +194,13 @@ describe("ChangeKdfComponent", () => {
230194

231195
// Assert
232196
const calloutElement = fixture.debugElement.query((el) =>
233-
el.nativeElement.textContent?.includes("Proceeding will log you out"),
197+
el.nativeElement.textContent?.includes("kdfSettingsChangeLogoutWarning"),
234198
);
235199

236200
if (showLogOutBanner) {
237201
expect(calloutElement).not.toBeNull();
238202
expect(calloutElement.nativeElement.textContent).toContain(
239-
"Proceeding will log you out of all active sessions",
203+
"kdfSettingsChangeLogoutWarning-used-i18n",
240204
);
241205
} else {
242206
expect(calloutElement).toBeNull();

0 commit comments

Comments
 (0)