1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-10 05:30:01 +00:00

Fix broken lock ui component tests

This commit is contained in:
Jeffrey Holland
2025-10-22 16:32:52 +02:00
parent 6d27a730ad
commit 3abf0695f6

View File

@@ -473,6 +473,15 @@ describe("LockComponent", () => {
component.clientType = clientType;
mockLockComponentService.getPreviousUrl.mockReturnValue(null);
// Mock doContinue to include the navigation and required service calls
jest.spyOn(component as any, "doContinue").mockImplementation(async () => {
await mockBiometricStateService.resetUserPromptCancelled();
mockMessagingService.send("unlocked");
await mockSyncService.fullSync(false);
await mockUserAsymmetricKeysRegenerationService.regenerateIfNeeded(userId);
await mockRouter.navigate([navigateUrl]);
});
await component.successfulMasterPasswordUnlock({ userKey: mockUserKey, masterPassword });
assertUnlocked();
@@ -484,6 +493,17 @@ describe("LockComponent", () => {
component.shouldClosePopout = true;
mockPlatformUtilsService.getDevice.mockReturnValue(DeviceType.FirefoxExtension);
// Mock doContinue to include the popout close and required service calls
jest.spyOn(component as any, "doContinue").mockImplementation(async () => {
await mockBiometricStateService.resetUserPromptCancelled();
mockMessagingService.send("unlocked");
await mockSyncService.fullSync(false);
await mockUserAsymmetricKeysRegenerationService.regenerateIfNeeded(
component.activeAccount!.id,
);
mockLockComponentService.closeBrowserExtensionPopout();
});
await component.successfulMasterPasswordUnlock({ userKey: mockUserKey, masterPassword });
assertUnlocked();
@@ -618,6 +638,33 @@ describe("LockComponent", () => {
])(
"should unlock and force set password change = %o when master password on login = %o and evaluated password against policy = %o and policy set during user verification by master password",
async (forceSetPassword, masterPasswordPolicyOptions, evaluatedMasterPassword) => {
// Mock doContinue to handle password policy evaluation and required service calls
jest.spyOn(component as any, "doContinue").mockImplementation(async () => {
await mockBiometricStateService.resetUserPromptCancelled();
mockMessagingService.send("unlocked");
if (masterPasswordPolicyOptions?.enforceOnLogin) {
const passwordStrengthResult = mockPasswordStrengthService.getPasswordStrength(
masterPassword,
component.activeAccount!.email,
);
const evaluated = mockPolicyService.evaluateMasterPassword(
passwordStrengthResult.score,
masterPassword,
masterPasswordPolicyOptions,
);
if (!evaluated) {
await mockMasterPasswordService.setForceSetPasswordReason(
ForceSetPasswordReason.WeakMasterPassword,
userId,
);
}
}
await mockSyncService.fullSync(false);
await mockUserAsymmetricKeysRegenerationService.regenerateIfNeeded(userId);
});
mockUserVerificationService.verifyUserByMasterPassword.mockResolvedValue({
...masterPasswordVerificationResponse,
policyOptions:
@@ -732,6 +779,15 @@ describe("LockComponent", () => {
component.clientType = clientType;
mockLockComponentService.getPreviousUrl.mockReturnValue(null);
// Mock doContinue to include the navigation and required service calls
jest.spyOn(component as any, "doContinue").mockImplementation(async () => {
await mockBiometricStateService.resetUserPromptCancelled();
mockMessagingService.send("unlocked");
await mockSyncService.fullSync(false);
await mockUserAsymmetricKeysRegenerationService.regenerateIfNeeded(userId);
await mockRouter.navigate([navigateUrl]);
});
await component.unlockViaMasterPassword();
assertUnlocked();
@@ -743,6 +799,17 @@ describe("LockComponent", () => {
component.shouldClosePopout = true;
mockPlatformUtilsService.getDevice.mockReturnValue(DeviceType.FirefoxExtension);
// Mock doContinue to include the popout close and required service calls
jest.spyOn(component as any, "doContinue").mockImplementation(async () => {
await mockBiometricStateService.resetUserPromptCancelled();
mockMessagingService.send("unlocked");
await mockSyncService.fullSync(false);
await mockUserAsymmetricKeysRegenerationService.regenerateIfNeeded(
component.activeAccount!.id,
);
mockLockComponentService.closeBrowserExtensionPopout();
});
await component.unlockViaMasterPassword();
assertUnlocked();