]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/mgr-modules/mgr-module-list/mgr-module-list.component.spec.ts
import 15.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / mgr-modules / mgr-module-list / mgr-module-list.component.spec.ts
index 252bd67e2085a40563d4c2335356631fc2eb9a0e..1072a9e449e81871d4bf115d3e3eaab31c585805 100644 (file)
@@ -1,6 +1,6 @@
 import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
-import { By } from '@angular/platform-browser';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
 import { RouterTestingModule } from '@angular/router/testing';
 
 import { TabsModule } from 'ngx-bootstrap/tabs';
@@ -29,6 +29,7 @@ describe('MgrModuleListComponent', () => {
   configureTestBed({
     declarations: [MgrModuleListComponent, MgrModuleDetailsComponent],
     imports: [
+      BrowserAnimationsModule,
       RouterTestingModule,
       SharedModule,
       HttpClientTestingModule,
@@ -50,57 +51,39 @@ describe('MgrModuleListComponent', () => {
     expect(component).toBeTruthy();
   });
 
-  describe('show action buttons and drop down actions depending on permissions', () => {
-    let tableActions: TableActionsComponent;
-    let scenario: { fn; empty; single };
-    let permissionHelper: PermissionHelper;
-
-    const getTableActionComponent = (): TableActionsComponent => {
-      fixture.detectChanges();
-      return fixture.debugElement.query(By.directive(TableActionsComponent)).componentInstance;
-    };
-
-    beforeEach(() => {
-      permissionHelper = new PermissionHelper(component.permission, () =>
-        getTableActionComponent()
-      );
-      scenario = {
-        fn: () => tableActions.getCurrentButton().name,
-        single: 'Edit',
-        empty: 'Edit'
-      };
-    });
-
-    describe('with read and update', () => {
-      beforeEach(() => {
-        tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 0);
-      });
-
-      it('shows action button', () => permissionHelper.testScenarios(scenario));
-
-      it('shows all actions', () => {
-        expect(tableActions.tableActions.length).toBe(3);
-        expect(tableActions.tableActions).toEqual(component.tableActions);
-      });
-    });
-
-    describe('with only read', () => {
-      beforeEach(() => {
-        tableActions = permissionHelper.setPermissionsAndGetActions(0, 0, 0);
-      });
-
-      it('shows no main action', () => {
-        permissionHelper.testScenarios({
-          fn: () => tableActions.getCurrentButton(),
-          single: undefined,
-          empty: undefined
-        });
-      });
-
-      it('shows no actions', () => {
-        expect(tableActions.tableActions.length).toBe(0);
-        expect(tableActions.tableActions).toEqual([]);
-      });
+  it('should test all TableActions combinations', () => {
+    const permissionHelper: PermissionHelper = new PermissionHelper(component.permission);
+    const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions(
+      component.tableActions
+    );
+
+    expect(tableActions).toEqual({
+      'create,update,delete': {
+        actions: ['Edit', 'Enable', 'Disable'],
+        primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+      },
+      'create,update': {
+        actions: ['Edit', 'Enable', 'Disable'],
+        primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+      },
+      'create,delete': {
+        actions: [],
+        primary: { multiple: '', executing: '', single: '', no: '' }
+      },
+      create: { actions: [], primary: { multiple: '', executing: '', single: '', no: '' } },
+      'update,delete': {
+        actions: ['Edit', 'Enable', 'Disable'],
+        primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+      },
+      update: {
+        actions: ['Edit', 'Enable', 'Disable'],
+        primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+      },
+      delete: { actions: [], primary: { multiple: '', executing: '', single: '', no: '' } },
+      'no-permissions': {
+        actions: [],
+        primary: { multiple: '', executing: '', single: '', no: '' }
+      }
     });
   });
 
@@ -116,11 +99,11 @@ describe('MgrModuleListComponent', () => {
     it('should enable module', fakeAsync(() => {
       spyOn(mgrModuleService, 'enable').and.returnValue(observableThrowError('y'));
       spyOn(mgrModuleService, 'list').and.returnValues(observableThrowError('z'), observableOf([]));
-      component.selection.selected.push({
+      component.selection.add({
         name: 'foo',
-        enabled: false
+        enabled: false,
+        always_on: false
       });
-      component.selection.update();
       component.updateModuleState();
       tick(2000);
       tick(2000);
@@ -135,11 +118,11 @@ describe('MgrModuleListComponent', () => {
     it('should disable module', fakeAsync(() => {
       spyOn(mgrModuleService, 'disable').and.returnValue(observableThrowError('x'));
       spyOn(mgrModuleService, 'list').and.returnValue(observableOf([]));
-      component.selection.selected.push({
+      component.selection.add({
         name: 'bar',
-        enabled: true
+        enabled: true,
+        always_on: false
       });
-      component.selection.update();
       component.updateModuleState();
       tick(2000);
       expect(mgrModuleService.disable).toHaveBeenCalledWith('bar');
@@ -149,5 +132,24 @@ describe('MgrModuleListComponent', () => {
       expect(component.blockUI.stop).toHaveBeenCalled();
       expect(component.table.refreshBtn).toHaveBeenCalled();
     }));
+
+    it('should not disable module (1)', () => {
+      component.selection.selected = [
+        {
+          name: 'dashboard'
+        }
+      ];
+      expect(component.isTableActionDisabled('enabled')).toBeTruthy();
+    });
+
+    it('should not disable module (2)', () => {
+      component.selection.selected = [
+        {
+          name: 'bar',
+          always_on: true
+        }
+      ];
+      expect(component.isTableActionDisabled('enabled')).toBeTruthy();
+    });
   });
 });