mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
* 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.
118 lines
4.9 KiB
TypeScript
118 lines
4.9 KiB
TypeScript
import { DIALOG_DATA, DialogRef } from "@angular/cdk/dialog";
|
|
import { ComponentFixture, TestBed } from "@angular/core/testing";
|
|
import { Router } from "@angular/router";
|
|
import { mock } from "jest-mock-extended";
|
|
|
|
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
|
|
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
|
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
|
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
|
import { CollectionService } from "@bitwarden/common/vault/abstractions/collection.service";
|
|
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
|
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
|
import { DialogService, ToastService } from "@bitwarden/components";
|
|
|
|
import { ViewComponent, ViewCipherDialogParams, ViewCipherDialogResult } from "./view.component";
|
|
|
|
describe("ViewComponent", () => {
|
|
let component: ViewComponent;
|
|
let fixture: ComponentFixture<ViewComponent>;
|
|
let router: Router;
|
|
|
|
const mockCipher: CipherView = {
|
|
id: "cipher-id",
|
|
type: 1,
|
|
organizationId: "org-id",
|
|
isDeleted: false,
|
|
} as CipherView;
|
|
|
|
const mockOrganization: Organization = {
|
|
id: "org-id",
|
|
name: "Test Organization",
|
|
} as Organization;
|
|
|
|
const mockParams: ViewCipherDialogParams = {
|
|
cipher: mockCipher,
|
|
};
|
|
|
|
beforeEach(async () => {
|
|
await TestBed.configureTestingModule({
|
|
imports: [ViewComponent],
|
|
providers: [
|
|
{ provide: DIALOG_DATA, useValue: mockParams },
|
|
{ provide: DialogRef, useValue: mock<DialogRef>() },
|
|
{ provide: I18nService, useValue: { t: jest.fn().mockReturnValue("login") } },
|
|
{ provide: DialogService, useValue: mock<DialogService>() },
|
|
{ provide: CipherService, useValue: mock<CipherService>() },
|
|
{ provide: ToastService, useValue: mock<ToastService>() },
|
|
{ provide: MessagingService, useValue: mock<MessagingService>() },
|
|
{ provide: LogService, useValue: mock<LogService>() },
|
|
{
|
|
provide: OrganizationService,
|
|
useValue: { get: jest.fn().mockResolvedValue(mockOrganization) },
|
|
},
|
|
{ provide: Router, useValue: mock<Router>() },
|
|
{ provide: CollectionService, useValue: mock<CollectionService>() },
|
|
{ provide: FolderService, useValue: mock<FolderService>() },
|
|
{ provide: CryptoService, useValue: mock<CryptoService>() },
|
|
{
|
|
provide: BillingAccountProfileStateService,
|
|
useValue: mock<BillingAccountProfileStateService>(),
|
|
},
|
|
{ provide: ConfigService, useValue: mock<ConfigService>() },
|
|
],
|
|
}).compileComponents();
|
|
|
|
fixture = TestBed.createComponent(ViewComponent);
|
|
component = fixture.componentInstance;
|
|
router = TestBed.inject(Router);
|
|
component.params = mockParams;
|
|
component.cipher = mockCipher;
|
|
});
|
|
|
|
describe("ngOnInit", () => {
|
|
it("initializes the component with cipher and organization", async () => {
|
|
await component.ngOnInit();
|
|
|
|
expect(component.cipher).toEqual(mockCipher);
|
|
expect(component.organization).toEqual(mockOrganization);
|
|
});
|
|
});
|
|
|
|
describe("edit", () => {
|
|
it("navigates to the edit route and closes the dialog with the proper arguments", async () => {
|
|
jest.spyOn(router, "navigate").mockResolvedValue(true);
|
|
const dialogRefCloseSpy = jest.spyOn(component["dialogRef"], "close");
|
|
|
|
await component.edit();
|
|
|
|
expect(router.navigate).toHaveBeenCalledWith([], {
|
|
queryParams: {
|
|
itemId: mockCipher.id,
|
|
action: "edit",
|
|
organizationId: mockCipher.organizationId,
|
|
},
|
|
});
|
|
expect(dialogRefCloseSpy).toHaveBeenCalledWith({ action: ViewCipherDialogResult.Edited });
|
|
});
|
|
});
|
|
|
|
describe("delete", () => {
|
|
it("calls the delete method on delete and closes the dialog with the proper arguments", async () => {
|
|
const deleteSpy = jest.spyOn(component, "delete");
|
|
const dialogRefCloseSpy = jest.spyOn(component["dialogRef"], "close");
|
|
jest.spyOn(component["dialogService"], "openSimpleDialog").mockResolvedValue(true);
|
|
|
|
await component.delete();
|
|
|
|
expect(deleteSpy).toHaveBeenCalled();
|
|
expect(dialogRefCloseSpy).toHaveBeenCalledWith({ action: ViewCipherDialogResult.Deleted });
|
|
});
|
|
});
|
|
});
|