1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-26 09:33:22 +00:00

adds and fixes tests

This commit is contained in:
Jackson Engstrom
2026-01-20 11:59:10 -08:00
parent 456d012d52
commit 9e59c23900
4 changed files with 41 additions and 2 deletions

View File

@@ -109,7 +109,7 @@ describe("AttachmentsV2Component", () => {
});
it("passes the submit button to the cipher attachments component", () => {
const submitBtn = fixture.debugElement.queryAll(By.directive(ButtonComponent))[1]
const submitBtn = fixture.debugElement.queryAll(By.directive(ButtonComponent))[0]
.componentInstance;
expect(cipherAttachment.submitBtn()).toEqual(submitBtn);

View File

@@ -51,6 +51,7 @@ describe("CipherAttachmentsComponent", () => {
username: "username",
password: "password",
},
edit: true,
} as CipherView;
const cipherDomain = {
@@ -197,6 +198,10 @@ describe("CipherAttachmentsComponent", () => {
let file: File;
beforeEach(() => {
const nonEditableCipherView = { ...cipherView, edit: false };
cipherServiceDecrypt.mockResolvedValue(nonEditableCipherView);
fixture.detectChanges();
submitBtnFixture.componentInstance.disabled.set(undefined as unknown as boolean);
file = new File([""], "attachment.txt", { type: "text/plain" });
@@ -371,6 +376,32 @@ describe("CipherAttachmentsComponent", () => {
expect(emitSpy).toHaveBeenCalled();
});
});
describe("close", () => {
async function setup(): Promise<void> {
fixture = TestBed.createComponent(CipherAttachmentsComponent);
component = fixture.componentInstance;
submitBtnFixture = TestBed.createComponent(ButtonComponent);
// Set organizationId BEFORE cipherId so the effect picks it up
fixture.componentRef.setInput("organizationId", organization.id);
fixture.componentRef.setInput("submitBtn", submitBtnFixture.componentInstance);
fixture.componentRef.setInput("cipherId", "5555-444-3333" as CipherId);
await waitForInitialization();
const nonEditableCipherView = { ...cipherView, edit: false };
cipherServiceDecrypt.mockResolvedValue(nonEditableCipherView);
fixture.detectChanges();
}
it('emits "onCloseButtonPress"', async () => {
await setup();
const emitSpy = jest.spyOn(component.onCloseButtonPress, "emit");
await component.submit();
expect(emitSpy).toHaveBeenCalled();
});
});
});
describe("removeAttachment", () => {

View File

@@ -195,7 +195,7 @@ export class CipherAttachmentsComponent {
/** Save the attachments to the cipher */
submit = async () => {
//user can't edit cipher and will close the bit-dialog
if (!this.cipher().edit) {
if (!(this.cipher()?.edit ?? false)) {
this.onCloseButtonPress.emit();
return;
}

View File

@@ -69,4 +69,12 @@ describe("AttachmentsV2Component", () => {
expect(dialogRefCloseSpy).toHaveBeenCalledWith({ action: AttachmentDialogResult.Removed });
});
it("closes the dialog with 'closed' result on closedButtonPressed", () => {
const dialogRefCloseSpy = jest.spyOn(component["dialogRef"], "close");
component.closeButtonPressed();
expect(dialogRefCloseSpy).toHaveBeenCalledWith({ action: AttachmentDialogResult.Closed });
});
});