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

[PM- 9666] Implement edit item view individual vault (#10553)

* Add initial vault cipher form for cipher edit.

* Add ability to add new cipher by type

* Add ability to save and clone cipher,

* Update canEditAllCiphers to take 1 argument.

* Add attachments button to add/edit dialog.

* Add semi-working attachment dialog.

* Add working attachment functionality.

* Remove debugging code.

* Add tests for new attachments dialog component.

* Add AddEditComponentV2 tests.

* Remove AddEditComponentV2 delete functionality.

* Remove unnecessary else statement.

* Launch password generation in new dialog when extension refresh enabled.

* Add tests for PasswordGeneratorComponent.

* Adjust password and attachments dialog sizes.

* run lint:fix

* Remove unnecessary form from button.

* Add missing provider in test.

* Remove password generation events.

* Add WebVaultGeneratorDialogComponent and WebCipherFormGenerationService

* Move and rename CipherFormQueryParams

* Use WebCipherFormGenerationService to launch password / user generation modals.

* Add WebVaultGeneratorDialogComponent tests.

* Remove unnecessary functionality and corresponding tests.

* Fix failing tests.

* Remove unused properties from AddEditComponentV2

* Pass CipherFormConfig to dialog.

* Clean up unused attachment dialog functionality.

* Update AddEdit cancel functionality to prevent navigating user.

* Make attachment dialog open a static method.

* Add addCipherV2 method and clean up tests.

* Remove changes to QueryParams.

* Add tests for WebCipherFormGenerationService

* Remove unused onCipherSaved method.

* Remove cipherSaved event.

* Remove unused password generator component

* Refactor to simplify editCipherId for extensionRefresh flag.

* Add additional comments to AddEditComponentV2.

* Simplify open vault generator dialog comment.

* Remove unused organizationService

* Remove unnecessary typecasting.

* Remove extensionRefreshEnabled and related.

* Remove slideIn animation

* Remove unused AddEditComponentV2 properties.

* Add back generic typing.

* Condesnse properties into single form config.

* Remove onDestroy and related code.

* Run prettier

* fix injection warning

* Handle cipher save.

* Redirect to vault on delete and make actions consistent.

* Update comment.
This commit is contained in:
Alec Rippberger
2024-09-18 12:48:47 -05:00
committed by GitHub
parent a674f698a2
commit 931f86c948
18 changed files with 1065 additions and 18 deletions

View File

@@ -0,0 +1,88 @@
import { DialogRef } from "@angular/cdk/dialog";
import { TestBed } from "@angular/core/testing";
import { mock } from "jest-mock-extended";
import { of } from "rxjs";
import { DialogService } from "@bitwarden/components";
import { WebVaultGeneratorDialogComponent } from "../components/web-generator-dialog/web-generator-dialog.component";
import { WebCipherFormGenerationService } from "./web-cipher-form-generation.service";
describe("WebCipherFormGenerationService", () => {
let service: WebCipherFormGenerationService;
let dialogService: jest.Mocked<DialogService>;
let closed = of({});
const close = jest.fn();
const dialogRef = {
close,
get closed() {
return closed;
},
} as unknown as DialogRef<unknown, unknown>;
beforeEach(() => {
dialogService = mock<DialogService>();
TestBed.configureTestingModule({
providers: [
WebCipherFormGenerationService,
{ provide: DialogService, useValue: dialogService },
],
});
service = TestBed.inject(WebCipherFormGenerationService);
});
it("creates without error", () => {
expect(service).toBeTruthy();
});
describe("generatePassword", () => {
it("opens the password generator dialog and returns the generated value", async () => {
const generatedValue = "generated-password";
closed = of({ action: "generated", generatedValue });
dialogService.open.mockReturnValue(dialogRef);
const result = await service.generatePassword();
expect(dialogService.open).toHaveBeenCalledWith(WebVaultGeneratorDialogComponent, {
data: { type: "password" },
});
expect(result).toBe(generatedValue);
});
it("returns null if the dialog is canceled", async () => {
closed = of({ action: "canceled" });
dialogService.open.mockReturnValue(dialogRef);
const result = await service.generatePassword();
expect(result).toBeNull();
});
});
describe("generateUsername", () => {
it("opens the username generator dialog and returns the generated value", async () => {
const generatedValue = "generated-username";
closed = of({ action: "generated", generatedValue });
dialogService.open.mockReturnValue(dialogRef);
const result = await service.generateUsername();
expect(dialogService.open).toHaveBeenCalledWith(WebVaultGeneratorDialogComponent, {
data: { type: "username" },
});
expect(result).toBe(generatedValue);
});
it("returns null if the dialog is canceled", async () => {
closed = of({ action: "canceled" });
dialogService.open.mockReturnValue(dialogRef);
const result = await service.generateUsername();
expect(result).toBeNull();
});
});
});

View File

@@ -0,0 +1,40 @@
import { inject, Injectable } from "@angular/core";
import { firstValueFrom } from "rxjs";
import { DialogService } from "@bitwarden/components";
import { CipherFormGenerationService } from "@bitwarden/vault";
import { WebVaultGeneratorDialogComponent } from "../components/web-generator-dialog/web-generator-dialog.component";
@Injectable()
export class WebCipherFormGenerationService implements CipherFormGenerationService {
private dialogService = inject(DialogService);
async generatePassword(): Promise<string> {
const dialogRef = WebVaultGeneratorDialogComponent.open(this.dialogService, {
data: { type: "password" },
});
const result = await firstValueFrom(dialogRef.closed);
if (result == null || result.action === "canceled") {
return null;
}
return result.generatedValue;
}
async generateUsername(): Promise<string> {
const dialogRef = WebVaultGeneratorDialogComponent.open(this.dialogService, {
data: { type: "username" },
});
const result = await firstValueFrom(dialogRef.closed);
if (result == null || result.action === "canceled") {
return null;
}
return result.generatedValue;
}
}