mirror of
https://github.com/bitwarden/browser
synced 2025-12-06 00:13:28 +00:00
* Cipher service web changes * Updated browser client to pass user id to cipher service observable changes * Cli changes * desktop changes * Fixed test * Libs changes * Fixed merge conflicts * Fixed merge conflicts * removed duplicate reference fixed conflict * Fixed test * Fixed test * Fixed test * Fixed desturcturing issue on failed to decrypt ciphers cipher service * Updated abstraction to use method syntax * Fixed conflicts * Fixed test on add edit v2 Passed active userId to delete function * Used getUserId utility function * made vault changes * made suggestion changes * made suggestion changes * made suggestion changes * Replace getUserId function calls with pipe operator syntax for better consistency * fixed merge conflicts * revert mistake made of usinf account activity during merge conflict fix * fixed conflicts * fixed tests
115 lines
3.6 KiB
TypeScript
115 lines
3.6 KiB
TypeScript
import { ComponentFixture, TestBed } from "@angular/core/testing";
|
|
import { By } from "@angular/platform-browser";
|
|
import { mock } from "jest-mock-extended";
|
|
|
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
|
import { UserId } from "@bitwarden/common/types/guid";
|
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
|
import { AttachmentView } from "@bitwarden/common/vault/models/view/attachment.view";
|
|
import { DialogService, ToastService } from "@bitwarden/components";
|
|
|
|
import { mockAccountServiceWith } from "../../../../../../common/spec";
|
|
|
|
import { DeleteAttachmentComponent } from "./delete-attachment.component";
|
|
|
|
describe("DeleteAttachmentComponent", () => {
|
|
let component: DeleteAttachmentComponent;
|
|
let fixture: ComponentFixture<DeleteAttachmentComponent>;
|
|
const showToast = jest.fn();
|
|
const attachment = {
|
|
id: "222-3333-4444",
|
|
url: "attachment-url",
|
|
fileName: "attachment-filename",
|
|
size: "1234",
|
|
} as AttachmentView;
|
|
|
|
const deleteAttachmentWithServer = jest.fn().mockResolvedValue(null);
|
|
const openSimpleDialog = jest.fn().mockResolvedValue(true);
|
|
|
|
beforeEach(async () => {
|
|
deleteAttachmentWithServer.mockClear();
|
|
showToast.mockClear();
|
|
openSimpleDialog.mockClear().mockResolvedValue(true);
|
|
|
|
await TestBed.configureTestingModule({
|
|
imports: [DeleteAttachmentComponent],
|
|
providers: [
|
|
{
|
|
provide: CipherService,
|
|
useValue: { deleteAttachmentWithServer },
|
|
},
|
|
{
|
|
provide: ToastService,
|
|
useValue: { showToast },
|
|
},
|
|
{ provide: I18nService, useValue: { t: (key: string) => key } },
|
|
{ provide: LogService, useValue: mock<LogService>() },
|
|
{ provide: AccountService, useValue: mockAccountServiceWith("UserId" as UserId) },
|
|
],
|
|
})
|
|
.overrideProvider(DialogService, {
|
|
useValue: {
|
|
openSimpleDialog,
|
|
},
|
|
})
|
|
.compileComponents();
|
|
});
|
|
|
|
beforeEach(() => {
|
|
fixture = TestBed.createComponent(DeleteAttachmentComponent);
|
|
component = fixture.componentInstance;
|
|
component.cipherId = "5555-444-3333";
|
|
component.attachment = attachment;
|
|
fixture.detectChanges();
|
|
});
|
|
|
|
it("renders delete button", () => {
|
|
const deleteButton = fixture.debugElement.query(By.css("button"));
|
|
|
|
expect(deleteButton.attributes["title"]).toBe("deleteAttachmentName");
|
|
});
|
|
|
|
it("does not delete when the user cancels the dialog", async () => {
|
|
openSimpleDialog.mockResolvedValue(false);
|
|
|
|
await component.delete();
|
|
|
|
expect(openSimpleDialog).toHaveBeenCalledWith({
|
|
title: { key: "deleteAttachment" },
|
|
content: { key: "permanentlyDeleteAttachmentConfirmation" },
|
|
type: "warning",
|
|
});
|
|
|
|
expect(deleteAttachmentWithServer).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("deletes the attachment", async () => {
|
|
await component.delete();
|
|
|
|
expect(openSimpleDialog).toHaveBeenCalledWith({
|
|
title: { key: "deleteAttachment" },
|
|
content: { key: "permanentlyDeleteAttachmentConfirmation" },
|
|
type: "warning",
|
|
});
|
|
|
|
// Called with cipher id and attachment id
|
|
expect(deleteAttachmentWithServer).toHaveBeenCalledWith(
|
|
"5555-444-3333",
|
|
"222-3333-4444",
|
|
"UserId",
|
|
);
|
|
});
|
|
|
|
it("shows toast message on successful deletion", async () => {
|
|
await component.delete();
|
|
|
|
expect(showToast).toHaveBeenCalledWith({
|
|
variant: "success",
|
|
title: "",
|
|
message: "deletedAttachment",
|
|
});
|
|
});
|
|
});
|