From 7af3e1859ef70aafe6af748d04918f72a043c4f6 Mon Sep 17 00:00:00 2001 From: Syed Ali Ul Hasan Date: Sat, 28 Mar 2026 16:49:07 +0530 Subject: [PATCH] test: completed TODO's for rbd-snapshot - Enabled the disabled test cases - Refactored them accordingly Signed-off-by: Syed Ali Ul Hasan --- .../rbd-snapshot-list.component.spec.ts | 62 ++++++++----------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.spec.ts index f42a1f7ede91..394abc79f26d 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.spec.ts @@ -107,16 +107,14 @@ describe('RbdSnapshotListComponent', () => { }); describe('api delete request', () => { - let called: boolean; let rbdService: RbdService; let notificationService: NotificationService; let authStorageService: AuthStorageService; beforeEach(() => { fixture.detectChanges(); - const modalService = TestBed.inject(ModalCdsService); + modalService = TestBed.inject(ModalCdsService); const actionLabelsI18n = TestBed.inject(ActionLabelsI18n); - called = false; rbdService = new RbdService(null, null); notificationService = new NotificationService(null, null, null); authStorageService = new AuthStorageService(); @@ -139,20 +137,20 @@ describe('RbdSnapshotListComponent', () => { spyOn(modalService, 'stopLoadingSpinner').and.stub(); }); - // @TODO: fix this later. fails with the new cds modal. - // disabling this for now. - it.skip('should call stopLoadingSpinner if the request fails', fakeAsync(() => { - // expect(container.querySelector('cds-placeholder')).not.toBeNull(); + it('should call stopLoadingSpinner if the request fails', fakeAsync(() => { + const modalRef: any = { snapshotForm: 'deletionForm' }; + spyOn(modalService, 'show').and.callFake((_modalComp: any, config: any) => { + modalRef.submitAction = config.submitAction; + return modalRef; + }); + component.updateSelection(new CdTableSelection([{ name: 'someName' }])); - expect(called).toBe(false); component.deleteSnapshotModal(); - component.modalRef.snapshotForm = { value: { snapName: 'someName' } }; - component.modalRef.submitAction(); - tick(500); - spyOn(modalService, 'stopLoadingSpinner').and.callFake(() => { - called = true; - }); - expect(called).toBe(true); + + modalRef.submitAction(); + tick(); + + expect(modalService.stopLoadingSpinner).toHaveBeenCalledWith('deletionForm'); })); }); @@ -219,38 +217,32 @@ describe('RbdSnapshotListComponent', () => { }); }); - // cds-modal opening fails in the unit tests. since e2e is already there, disabling this. - // @TODO: should be fixed later on - describe.skip('snapshot modal dialog', () => { + describe('snapshot modal dialog', () => { + let modalRef: any; + beforeEach(() => { component.poolName = 'pool01'; component.rbdName = 'image01'; - spyOn(TestBed.inject(ModalService), 'show').and.callFake(() => { - const ref: any = {}; - ref.componentInstance = new RbdSnapshotFormModalComponent( - null, - null, - null, - null, - TestBed.inject(ActionLabelsI18n), - null, - component.poolName - ); - ref.componentInstance.onSubmit = new Subject(); - return ref; - }); + modalRef = { + setEditing: jasmine.createSpy('setEditing'), + setSnapName: jasmine.createSpy('setSnapName'), + onSubmit: new Subject() + }; + spyOn(TestBed.inject(ModalCdsService), 'show').and.returnValue(modalRef); }); it('should display old snapshot name', () => { component.selection.selected = [{ name: 'oldname' }]; component.openEditSnapshotModal(); - expect(component.modalRef.componentInstance.snapName).toBe('oldname'); - expect(component.modalRef.componentInstance.editing).toBeTruthy(); + expect(modalRef.setEditing).toHaveBeenCalled(); + expect(modalRef.setSnapName).toHaveBeenCalledWith('oldname'); }); it('should display suggested snapshot name', () => { component.openCreateSnapshotModal(); - expect(component.modalRef.componentInstance.snapName).toMatch( + expect(modalRef.setEditing).not.toHaveBeenCalled(); + expect(modalRef.setSnapName).toHaveBeenCalled(); + expect(modalRef.setSnapName.calls.mostRecent().args[0]).toMatch( RegExp(`^${component.rbdName}_[\\d-]+T[\\d.:]+[\\+-][\\d:]+$`) ); }); -- 2.47.3