Skip to content

Commit

Permalink
[PM-17443] Navigation After Deletion (#13023)
Browse files Browse the repository at this point in the history
* navigate to vault tab after cipher deletion

* fix type issues in tests
  • Loading branch information
nick-livefront authored Jan 23, 2025
1 parent d30a105 commit 92aabe7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentFixture, fakeAsync, TestBed, tick } from "@angular/core/testing";
import { ActivatedRoute, Router } from "@angular/router";
import { mock, MockProxy } from "jest-mock-extended";
import { BehaviorSubject } from "rxjs";
import { BehaviorSubject, Observable } from "rxjs";

import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
import { EventType } from "@bitwarden/common/enums";
Expand Down Expand Up @@ -42,7 +42,7 @@ describe("AddEditV2Component", () => {

const buildConfigResponse = { originalCipher: {} } as CipherFormConfig;
const buildConfig = jest.fn((mode: CipherFormMode) =>
Promise.resolve({ mode, ...buildConfigResponse }),
Promise.resolve({ ...buildConfigResponse, mode }),
);
const queryParams$ = new BehaviorSubject({});
const disable = jest.fn();
Expand All @@ -57,9 +57,10 @@ describe("AddEditV2Component", () => {
back.mockClear();
collect.mockClear();

addEditCipherInfo$ = new BehaviorSubject(null);
addEditCipherInfo$ = new BehaviorSubject<AddEditCipherInfo | null>(null);
cipherServiceMock = mock<CipherService>();
cipherServiceMock.addEditCipherInfo$ = addEditCipherInfo$.asObservable();
cipherServiceMock.addEditCipherInfo$ =
addEditCipherInfo$.asObservable() as Observable<AddEditCipherInfo>;

await TestBed.configureTestingModule({
imports: [AddEditV2Component],
Expand Down Expand Up @@ -101,7 +102,7 @@ describe("AddEditV2Component", () => {

tick();

expect(buildConfig.mock.lastCall[0]).toBe("add");
expect(buildConfig.mock.lastCall![0]).toBe("add");
expect(component.config.mode).toBe("add");
}));

Expand All @@ -110,7 +111,7 @@ describe("AddEditV2Component", () => {

tick();

expect(buildConfig.mock.lastCall[0]).toBe("clone");
expect(buildConfig.mock.lastCall![0]).toBe("clone");
expect(component.config.mode).toBe("clone");
}));

Expand All @@ -120,7 +121,7 @@ describe("AddEditV2Component", () => {

tick();

expect(buildConfig.mock.lastCall[0]).toBe("edit");
expect(buildConfig.mock.lastCall![0]).toBe("edit");
expect(component.config.mode).toBe("edit");
}));

Expand All @@ -130,7 +131,7 @@ describe("AddEditV2Component", () => {

tick();

expect(buildConfig.mock.lastCall[0]).toBe("edit");
expect(buildConfig.mock.lastCall![0]).toBe("edit");
expect(component.config.mode).toBe("partial-edit");
}));
});
Expand Down Expand Up @@ -227,7 +228,7 @@ describe("AddEditV2Component", () => {

tick();

expect(component.config.initialValues.username).toBe("identity-username");
expect(component.config.initialValues!.username).toBe("identity-username");
}));

it("overrides query params with `addEditCipherInfo` values", fakeAsync(() => {
Expand All @@ -240,7 +241,7 @@ describe("AddEditV2Component", () => {

tick();

expect(component.config.initialValues.name).toBe("AddEditCipherName");
expect(component.config.initialValues!.name).toBe("AddEditCipherName");
}));

it("clears `addEditCipherInfo` after initialization", fakeAsync(() => {
Expand Down Expand Up @@ -353,5 +354,12 @@ describe("AddEditV2Component", () => {
await component.delete();
expect(deleteCipherSpy).toHaveBeenCalled();
});

it("navigates to vault tab after deletion", async () => {
jest.spyOn(component["dialogService"], "openSimpleDialog").mockResolvedValue(true);
await component.delete();

expect(navigate).toHaveBeenCalledWith(["/tabs/vault"]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ export class AddEditV2Component implements OnInit {
return false;

Check warning on line 377 in apps/browser/src/vault/popup/components/vault-v2/add-edit/add-edit-v2.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/vault/popup/components/vault-v2/add-edit/add-edit-v2.component.ts#L376-L377

Added lines #L376 - L377 were not covered by tests
}

await this.router.navigate([""]);
await this.router.navigate(["/tabs/vault"]);

this.toastService.showToast({
variant: "success",
Expand Down

0 comments on commit 92aabe7

Please sign in to comment.