]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts
import 15.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / hosts / hosts.component.spec.ts
index 69ed5df199647f9f8e22ab03668ead469cfdfd7e..05f3d962f0e4047ac3b71af59f9d42d50f0c3c62 100644 (file)
@@ -3,6 +3,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
 import { RouterTestingModule } from '@angular/router/testing';
 
+import * as _ from 'lodash';
 import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
 import { TabsModule } from 'ngx-bootstrap/tabs';
 import { ToastrModule } from 'ngx-toastr';
@@ -11,6 +12,8 @@ import { of } from 'rxjs';
 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
 import { CoreModule } from '../../../core/core.module';
 import { HostService } from '../../../shared/api/host.service';
+import { ActionLabels } from '../../../shared/constants/app.constants';
+import { CdTableAction } from '../../../shared/models/cd-table-action';
 import { Permissions } from '../../../shared/models/permissions';
 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
 import { SharedModule } from '../../../shared/shared.module';
@@ -92,4 +95,41 @@ describe('HostsComponent', () => {
       expect(spans[0].textContent).toBe(hostname);
     });
   }));
+
+  describe('test edit button', () => {
+    let tableAction: CdTableAction;
+
+    beforeEach(() => {
+      tableAction = _.find(component.tableActions, { name: ActionLabels.EDIT });
+    });
+
+    it('should disable button and return message (not managed by Orchestrator)', () => {
+      component.selection.add({
+        sources: {
+          ceph: true,
+          orchestrator: false
+        }
+      });
+      expect(tableAction.disable(component.selection)).toBeTruthy();
+      expect(component.getEditDisableDesc(component.selection)).toBe(
+        'Host editing is disabled because the host is not managed by Orchestrator.'
+      );
+    });
+
+    it('should disable button and return undefined (no selection)', () => {
+      expect(tableAction.disable(component.selection)).toBeTruthy();
+      expect(component.getEditDisableDesc(component.selection)).toBeUndefined();
+    });
+
+    it('should enable button and return undefined (managed by Orchestrator)', () => {
+      component.selection.add({
+        sources: {
+          ceph: false,
+          orchestrator: true
+        }
+      });
+      expect(tableAction.disable(component.selection)).toBeFalsy();
+      expect(component.getEditDisableDesc(component.selection)).toBeUndefined();
+    });
+  });
 });