-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): [PM-9693] Refresh LoginDecryptionOptionsComponent (#11782)
Creates a refreshed and consolidated `LoginDecryptionOptionsComponent` for use on all visual clients, which will be used when the `UnauthenticatedExtensionUIRefresh` feature flag is on.
- Loading branch information
Showing
31 changed files
with
742 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...rc/auth/popup/login-decryption-options/extension-login-decryption-options.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Router } from "@angular/router"; | ||
import { MockProxy, mock } from "jest-mock-extended"; | ||
import { BehaviorSubject } from "rxjs"; | ||
|
||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; | ||
|
||
import { postLogoutMessageListener$ } from "../utils/post-logout-message-listener"; | ||
|
||
import { ExtensionLoginDecryptionOptionsService } from "./extension-login-decryption-options.service"; | ||
|
||
// Mock the module providing postLogoutMessageListener$ | ||
jest.mock("../utils/post-logout-message-listener", () => { | ||
return { | ||
postLogoutMessageListener$: new BehaviorSubject<string>(""), // Replace with mock subject | ||
}; | ||
}); | ||
|
||
describe("ExtensionLoginDecryptionOptionsService", () => { | ||
let service: ExtensionLoginDecryptionOptionsService; | ||
|
||
let messagingService: MockProxy<MessagingService>; | ||
let router: MockProxy<Router>; | ||
let postLogoutMessageSubject: BehaviorSubject<string>; | ||
|
||
beforeEach(() => { | ||
messagingService = mock<MessagingService>(); | ||
router = mock<Router>(); | ||
|
||
// Cast postLogoutMessageListener$ to BehaviorSubject for dynamic control | ||
postLogoutMessageSubject = postLogoutMessageListener$ as BehaviorSubject<string>; | ||
|
||
service = new ExtensionLoginDecryptionOptionsService(messagingService, router); | ||
}); | ||
|
||
it("should instantiate the service", () => { | ||
expect(service).not.toBeFalsy(); | ||
}); | ||
|
||
describe("logOut()", () => { | ||
it("should send a logout message", async () => { | ||
postLogoutMessageSubject.next("switchAccountFinish"); | ||
|
||
await service.logOut(); | ||
|
||
expect(messagingService.send).toHaveBeenCalledWith("logout"); | ||
}); | ||
|
||
it("should navigate to root on 'switchAccountFinish'", async () => { | ||
postLogoutMessageSubject.next("switchAccountFinish"); | ||
|
||
await service.logOut(); | ||
|
||
expect(router.navigate).toHaveBeenCalledWith(["/"]); | ||
}); | ||
|
||
it("should not navigate for 'doneLoggingOut'", async () => { | ||
postLogoutMessageSubject.next("doneLoggingOut"); | ||
|
||
await service.logOut(); | ||
|
||
expect(router.navigate).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
...ser/src/auth/popup/login-decryption-options/extension-login-decryption-options.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Router } from "@angular/router"; | ||
import { firstValueFrom } from "rxjs"; | ||
|
||
import { | ||
DefaultLoginDecryptionOptionsService, | ||
LoginDecryptionOptionsService, | ||
} from "@bitwarden/auth/angular"; | ||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; | ||
|
||
import { postLogoutMessageListener$ } from "../utils/post-logout-message-listener"; | ||
|
||
export class ExtensionLoginDecryptionOptionsService | ||
extends DefaultLoginDecryptionOptionsService | ||
implements LoginDecryptionOptionsService | ||
{ | ||
constructor( | ||
protected messagingService: MessagingService, | ||
private router: Router, | ||
) { | ||
super(messagingService); | ||
} | ||
|
||
override async logOut(): Promise<void> { | ||
// start listening for "switchAccountFinish" or "doneLoggingOut" | ||
const messagePromise = firstValueFrom(postLogoutMessageListener$); | ||
|
||
super.logOut(); | ||
|
||
// wait for messages | ||
const command = await messagePromise; | ||
|
||
// doneLoggingOut already has a message handler that will navigate us | ||
if (command === "switchAccountFinish") { | ||
await this.router.navigate(["/"]); | ||
} | ||
} | ||
} |
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
...ons/login-decryption-options.component.ts → .../login-decryption-options-v1.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
...ons/login-decryption-options.component.ts → .../login-decryption-options-v1.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.