(updateSelection)="updateSelection($event)">
<div class="table-actions btn-toolbar">
<cd-table-actions class="btn-group"
- [permission]="permissions.iscsi"
+ [permission]="permission"
[selection]="selection"
[tableActions]="tableActions">
</cd-table-actions>
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { TreeModule } from 'ng2-tree';
});
});
- 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.permissions.iscsi, () =>
- getTableActionComponent()
- );
- scenario = {
- fn: () => tableActions.getCurrentButton().name,
- single: 'Edit',
- empty: 'Create'
- };
- });
-
- describe('with all', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 1);
- });
-
- it(`shows 'Edit' for single selection else 'Create' as main action`, () => {
- permissionHelper.testScenarios(scenario);
- });
-
- it('shows all actions', () => {
- expect(tableActions.tableActions.length).toBe(3);
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and update', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 0);
- scenario.single = 'Edit';
- });
-
- it(`should always show 'Edit'`, () => {
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows all actions except for 'Delete'`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- component.tableActions.pop();
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 1);
- });
-
- it(`shows 'Delete' for single selection else 'Create' as main action`, () => {
- scenario.single = 'Delete';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Create' and 'Delete' actions`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[0],
- component.tableActions[2]
- ]);
- });
- });
-
- describe('with read, edit and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 1);
- });
-
- it(`shows always 'Edit' as main action`, () => {
- scenario.empty = 'Edit';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Edit' and 'Delete' actions`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[1],
- component.tableActions[2]
- ]);
- });
- });
-
- describe('with read and create', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 0);
- });
-
- it(`shows 'Create' for single selection and 'Create' as main action`, () => {
- scenario.single = 'Create';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Create' actions`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[0]]);
- });
- });
-
- describe('with read and edit', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 0);
- });
-
- it(`shows no actions`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[1]]);
- });
- });
-
- describe('with read and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 0, 1);
- });
-
- it(`shows always 'Delete' as main action`, () => {
- scenario.single = 'Delete';
- scenario.empty = 'Delete';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Delete' actions`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[2]]);
- });
- });
-
- 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: ['Create', 'Edit', 'Delete'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,update': {
+ actions: ['Create', 'Edit'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,delete': {
+ actions: ['Create', 'Delete'],
+ primary: { multiple: 'Create', executing: 'Delete', single: 'Delete', no: 'Create' }
+ },
+ create: {
+ actions: ['Create'],
+ primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
+ },
+ 'update,delete': {
+ actions: ['Edit', 'Delete'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ update: {
+ actions: ['Edit'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ delete: {
+ actions: ['Delete'],
+ primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
+ },
+ 'no-permissions': {
+ actions: [],
+ primary: { multiple: '', executing: '', single: '', no: '' }
+ }
});
});
});
import { CdTableColumn } from '../../../shared/models/cd-table-column';
import { CdTableSelection } from '../../../shared/models/cd-table-selection';
import { FinishedTask } from '../../../shared/models/finished-task';
-import { Permissions } from '../../../shared/models/permissions';
+import { Permission } from '../../../shared/models/permissions';
import { CephReleaseNamePipe } from '../../../shared/pipes/ceph-release-name.pipe';
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
import { SummaryService } from '../../../shared/services/summary.service';
columns: CdTableColumn[];
docsUrl: string;
modalRef: BsModalRef;
- permissions: Permissions;
+ permission: Permission;
selection = new CdTableSelection();
settings: any;
status: string;
private taskWrapper: TaskWrapperService,
public actionLabels: ActionLabelsI18n
) {
- this.permissions = this.authStorageService.getPermissions();
+ this.permission = this.authStorageService.getPermissions().iscsi;
this.tableActions = [
{
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { AlertModule } from 'ngx-bootstrap/alert';
PermissionHelper
} from '../../../../testing/unit-test-helper';
import { RbdService } from '../../../shared/api/rbd.service';
-import { ActionLabels } from '../../../shared/constants/app.constants';
import { TableActionsComponent } from '../../../shared/datatable/table-actions/table-actions.component';
import { ViewCacheStatus } from '../../../shared/enum/view-cache-status.enum';
import { ExecutingTask } from '../../../shared/models/executing-task';
});
});
- 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: ActionLabels.EDIT,
- empty: ActionLabels.CREATE
- };
- });
-
- describe('with all', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 1);
- });
-
- it(`shows 'Edit' for single selection else 'Add' as main action`, () =>
- permissionHelper.testScenarios(scenario));
-
- it('shows all actions', () => {
- expect(tableActions.tableActions.length).toBe(6);
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and update', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 0);
- });
-
- it(`shows 'Edit' for single selection else 'Add' as main action`, () =>
- permissionHelper.testScenarios(scenario));
-
- it(`shows all actions except for 'Delete' and 'Move'`, () => {
- expect(tableActions.tableActions.length).toBe(4);
- component.tableActions.pop();
- component.tableActions.pop();
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 1);
- });
-
- it(`shows 'Copy' for single selection else 'Add' as main action`, () => {
- scenario.single = 'Copy';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Add', 'Copy', 'Delete' and 'Move' action`, () => {
- expect(tableActions.tableActions.length).toBe(4);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[0],
- component.tableActions[2],
- component.tableActions[4],
- component.tableActions[5]
- ]);
- });
- });
-
- describe('with read, edit and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 1);
- });
-
- it(`shows always 'Edit' as main action`, () => {
- scenario.empty = 'Edit';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Edit', 'Flatten', 'Delete' and 'Move' action`, () => {
- expect(tableActions.tableActions.length).toBe(4);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[1],
- component.tableActions[3],
- component.tableActions[4],
- component.tableActions[5]
- ]);
- });
- });
-
- describe('with read and create', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 0);
- });
-
- it(`shows 'Copy' for single selection else 'Add' as main action`, () => {
- scenario.single = 'Copy';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Copy' and 'Add' actions`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[0],
- component.tableActions[2]
- ]);
- });
- });
-
- describe('with read and edit', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 0);
- });
-
- it(`shows always 'Edit' as main action`, () => {
- scenario.empty = 'Edit';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Edit' and 'Flatten' actions`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[1],
- component.tableActions[3]
- ]);
- });
- });
-
- describe('with read and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 0, 1);
- });
-
- it(`shows always 'Delete' as main action`, () => {
- scenario.single = 'Delete';
- scenario.empty = 'Delete';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Delete' and 'Move' actions`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[4],
- component.tableActions[5]
- ]);
- });
- });
-
- 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: ['Create', 'Edit', 'Copy', 'Flatten', 'Delete', 'Move to Trash'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,update': {
+ actions: ['Create', 'Edit', 'Copy', 'Flatten'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,delete': {
+ actions: ['Create', 'Copy', 'Delete', 'Move to Trash'],
+ primary: { multiple: 'Create', executing: 'Copy', single: 'Copy', no: 'Create' }
+ },
+ create: {
+ actions: ['Create', 'Copy'],
+ primary: { multiple: 'Create', executing: 'Copy', single: 'Copy', no: 'Create' }
+ },
+ 'update,delete': {
+ actions: ['Edit', 'Flatten', 'Delete', 'Move to Trash'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ update: {
+ actions: ['Edit', 'Flatten'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ delete: {
+ actions: ['Delete', 'Move to Trash'],
+ primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
+ },
+ 'no-permissions': {
+ actions: [],
+ primary: { multiple: '', executing: '', single: '', no: '' }
+ }
});
});
});
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
-import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { I18n } from '@ngx-translate/i18n-polyfill';
});
});
- 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: 'Rename',
- empty: 'Create'
- };
- });
-
- describe('with all', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 1);
- });
-
- it(`shows 'Rename' for single selection else 'Create' as main action`, () =>
- permissionHelper.testScenarios(scenario));
-
- it('shows all actions', () => {
- expect(tableActions.tableActions.length).toBe(8);
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and update', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 0);
- });
-
- it(`shows 'Rename' for single selection else 'Create' as main action`, () =>
- permissionHelper.testScenarios(scenario));
-
- it(`shows all actions except for 'Delete'`, () => {
- expect(tableActions.tableActions.length).toBe(7);
- component.tableActions.pop();
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 1);
- });
-
- it(`shows 'Clone' for single selection else 'Create' as main action`, () => {
- scenario.single = 'Clone';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Create', 'Clone', 'Copy' and 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(4);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[0],
- component.tableActions[4],
- component.tableActions[5],
- component.tableActions[7]
- ]);
- });
- });
-
- describe('with read, edit and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 1);
- });
-
- it(`shows always 'Rename' as main action`, () => {
- scenario.empty = 'Rename';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Rename', 'Protect', 'Unprotect', 'Rollback' and 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(5);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[1],
- component.tableActions[2],
- component.tableActions[3],
- component.tableActions[6],
- component.tableActions[7]
- ]);
- });
- });
-
- describe('with read and create', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 0);
- });
-
- it(`shows 'Clone' for single selection else 'Create' as main action`, () => {
- scenario.single = 'Clone';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Create', 'Clone' and 'Copy' actions`, () => {
- expect(tableActions.tableActions.length).toBe(3);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[0],
- component.tableActions[4],
- component.tableActions[5]
- ]);
- });
- });
-
- describe('with read and edit', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 0);
- });
-
- it(`shows always 'Rename' as main action`, () => {
- scenario.empty = 'Rename';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Rename', 'Protect', 'Unprotect' and 'Rollback' actions`, () => {
- expect(tableActions.tableActions.length).toBe(4);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[1],
- component.tableActions[2],
- component.tableActions[3],
- component.tableActions[6]
- ]);
- });
- });
-
- describe('with read and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 0, 1);
- });
-
- it(`shows always 'Delete' as main action`, () => {
- scenario.single = 'Delete';
- scenario.empty = 'Delete';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows only 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[7]]);
- });
- });
-
- 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([]);
- });
- });
-
- describe('test unprotected and protected action cases', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 0);
- });
-
- it(`shows none of them if nothing is selected`, () => {
- permissionHelper.setSelection([]);
- fixture.detectChanges();
- expect(tableActions.dropDownActions).toEqual([
- component.tableActions[1],
- component.tableActions[6]
- ]);
- });
-
- it(`shows 'Protect' of them if nothing is selected`, () => {
- permissionHelper.setSelection([{ is_protected: false }]);
- fixture.detectChanges();
- expect(tableActions.dropDownActions).toEqual([
- component.tableActions[1],
- component.tableActions[2],
- component.tableActions[6]
- ]);
- });
-
- it(`shows 'Unprotect' of them if nothing is selected`, () => {
- permissionHelper.setSelection([{ is_protected: true }]);
- fixture.detectChanges();
- expect(tableActions.dropDownActions).toEqual([
- component.tableActions[1],
- component.tableActions[3],
- component.tableActions[6]
- ]);
- });
+ 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: [
+ 'Create',
+ 'Rename',
+ 'Protect',
+ 'Unprotect',
+ 'Clone',
+ 'Copy',
+ 'Rollback',
+ 'Delete'
+ ],
+ primary: { multiple: 'Create', executing: 'Rename', single: 'Rename', no: 'Create' }
+ },
+ 'create,update': {
+ actions: ['Create', 'Rename', 'Protect', 'Unprotect', 'Clone', 'Copy', 'Rollback'],
+ primary: { multiple: 'Create', executing: 'Rename', single: 'Rename', no: 'Create' }
+ },
+ 'create,delete': {
+ actions: ['Create', 'Clone', 'Copy', 'Delete'],
+ primary: { multiple: 'Create', executing: 'Clone', single: 'Clone', no: 'Create' }
+ },
+ create: {
+ actions: ['Create', 'Clone', 'Copy'],
+ primary: { multiple: 'Create', executing: 'Clone', single: 'Clone', no: 'Create' }
+ },
+ 'update,delete': {
+ actions: ['Rename', 'Protect', 'Unprotect', 'Rollback', 'Delete'],
+ primary: { multiple: 'Rename', executing: 'Rename', single: 'Rename', no: 'Rename' }
+ },
+ update: {
+ actions: ['Rename', 'Protect', 'Unprotect', 'Rollback'],
+ primary: { multiple: 'Rename', executing: 'Rename', single: 'Rename', no: 'Rename' }
+ },
+ delete: {
+ actions: ['Delete'],
+ primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
+ },
+ 'no-permissions': {
+ actions: [],
+ primary: { multiple: '', executing: '', single: '', no: '' }
+ }
});
});
});
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
-import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { TabsModule } from 'ngx-bootstrap/tabs';
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: '' }
+ }
});
});
});
});
- describe('show table actions as defined', () => {
- let tableActions: TableActionsComponent;
- let scenario: { fn; empty; single };
- let permissionHelper: PermissionHelper;
-
- const getTableActionComponent = () => {
- fixture.detectChanges();
- return fixture.debugElement.query(By.css('#osd-actions')).componentInstance;
- };
-
- beforeEach(() => {
- permissionHelper = new PermissionHelper(component.permissions.osd, () =>
- getTableActionComponent()
- );
- scenario = {
- fn: () => tableActions.getCurrentButton().name,
- single: 'Scrub',
- empty: 'Scrub'
- };
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 1);
- });
-
- it('shows action button', () => permissionHelper.testScenarios(scenario));
+ it('should test all TableActions combinations', () => {
+ const permissionHelper: PermissionHelper = new PermissionHelper(component.permissions.osd);
+ const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions(
+ component.tableActions
+ );
- it('shows all actions', () => {
- expect(tableActions.tableActions.length).toBe(9);
- expect(tableActions.tableActions).toEqual(component.tableActions);
+ expect(tableActions).toEqual({
+ 'create,update,delete': {
+ actions: [
+ 'Scrub',
+ 'Deep Scrub',
+ 'Reweight',
+ 'Mark Out',
+ 'Mark In',
+ 'Mark Down',
+ 'Mark Lost',
+ 'Purge',
+ 'Destroy'
+ ],
+ primary: { multiple: 'Scrub', executing: 'Scrub', single: 'Scrub', no: 'Scrub' }
+ },
+ 'create,update': {
+ actions: ['Scrub', 'Deep Scrub', 'Reweight', 'Mark Out', 'Mark In', 'Mark Down'],
+ primary: { multiple: 'Scrub', executing: 'Scrub', single: 'Scrub', no: 'Scrub' }
+ },
+ 'create,delete': {
+ actions: ['Mark Lost', 'Purge', 'Destroy'],
+ primary: {
+ multiple: 'Mark Lost',
+ executing: 'Mark Lost',
+ single: 'Mark Lost',
+ no: 'Mark Lost'
+ }
+ },
+ create: { actions: [], primary: { multiple: '', executing: '', single: '', no: '' } },
+ 'update,delete': {
+ actions: [
+ 'Scrub',
+ 'Deep Scrub',
+ 'Reweight',
+ 'Mark Out',
+ 'Mark In',
+ 'Mark Down',
+ 'Mark Lost',
+ 'Purge',
+ 'Destroy'
+ ],
+ primary: { multiple: 'Scrub', executing: 'Scrub', single: 'Scrub', no: 'Scrub' }
+ },
+ update: {
+ actions: ['Scrub', 'Deep Scrub', 'Reweight', 'Mark Out', 'Mark In', 'Mark Down'],
+ primary: { multiple: 'Scrub', executing: 'Scrub', single: 'Scrub', no: 'Scrub' }
+ },
+ delete: {
+ actions: ['Mark Lost', 'Purge', 'Destroy'],
+ primary: {
+ multiple: 'Mark Lost',
+ executing: 'Mark Lost',
+ single: 'Mark Lost',
+ no: 'Mark Lost'
+ }
+ },
+ 'no-permissions': {
+ actions: [],
+ primary: { multiple: '', executing: '', single: '', no: '' }
+ }
});
});
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { TabsModule } from 'ngx-bootstrap/tabs';
import { PrometheusTabsComponent } from '../prometheus-tabs/prometheus-tabs.component';
import { AlertListComponent } from './alert-list.component';
-describe('PrometheusListComponent', () => {
+describe('AlertListComponent', () => {
let component: AlertListComponent;
let fixture: ComponentFixture<AlertListComponent>;
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;
- let combinations: number[][];
-
- 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: 'Create silence',
- empty: 'Create silence'
- };
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 1);
- });
-
- const permissionSwitch = (combination) => {
- tableActions = permissionHelper.setPermissionsAndGetActions(
- combination[0],
- combination[1],
- combination[2]
- );
- tableActions.tableActions = component.tableActions;
- tableActions.ngOnInit();
- };
-
- const testCombinations = (test: Function) => {
- combinations.forEach((combination) => {
- permissionSwitch(combination);
- test();
- });
- };
-
- describe('with every permission combination that includes create', () => {
- beforeEach(() => {
- combinations = [[1, 1, 1], [1, 1, 0], [1, 0, 1], [1, 0, 0]];
- });
-
- it(`always shows 'Create silence' as main action`, () => {
- testCombinations(() => permissionHelper.testScenarios(scenario));
- });
-
- it('shows all actions', () => {
- testCombinations(() => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
- });
-
- describe('with every permission combination that does not include create', () => {
- beforeEach(() => {
- combinations = [[0, 1, 1], [0, 1, 0], [0, 0, 1], [0, 0, 0]];
- });
-
- it(`won't show any action`, () => {
- testCombinations(() => {
- permissionHelper.testScenarios({
- fn: () => tableActions.getCurrentButton(),
- single: undefined,
- empty: undefined
- });
- });
- });
-
- it('shows no actions', () => {
- testCombinations(() => {
- expect(tableActions.tableActions.length).toBe(0);
- expect(tableActions.tableActions).toEqual([]);
- });
- });
+ it('should test all TableActions combinations', () => {
+ component.ngOnInit();
+ const permissionHelper: PermissionHelper = new PermissionHelper(component.permission);
+ const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions(
+ component.tableActions
+ );
+
+ expect(tableActions).toEqual({
+ 'create,update,delete': {
+ actions: ['Create silence'],
+ primary: {
+ multiple: 'Create silence',
+ executing: 'Create silence',
+ single: 'Create silence',
+ no: 'Create silence'
+ }
+ },
+ 'create,update': {
+ actions: ['Create silence'],
+ primary: {
+ multiple: 'Create silence',
+ executing: 'Create silence',
+ single: 'Create silence',
+ no: 'Create silence'
+ }
+ },
+ 'create,delete': {
+ actions: ['Create silence'],
+ primary: {
+ multiple: 'Create silence',
+ executing: 'Create silence',
+ single: 'Create silence',
+ no: 'Create silence'
+ }
+ },
+ create: {
+ actions: ['Create silence'],
+ primary: {
+ multiple: 'Create silence',
+ executing: 'Create silence',
+ single: 'Create silence',
+ no: 'Create silence'
+ }
+ },
+ 'update,delete': {
+ actions: [],
+ primary: { multiple: '', executing: '', single: '', no: '' }
+ },
+ update: { actions: [], primary: { multiple: '', executing: '', single: '', no: '' } },
+ delete: { actions: [], primary: { multiple: '', executing: '', single: '', no: '' } },
+ 'no-permissions': {
+ actions: [],
+ primary: { multiple: '', executing: '', single: '', no: '' }
+ }
});
});
});
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
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;
- let silenceState: string;
-
- const getTableActionComponent = (): TableActionsComponent => {
- fixture.detectChanges();
- return fixture.debugElement.query(By.directive(TableActionsComponent)).componentInstance;
- };
-
- const setSilenceState = (state) => {
- silenceState = state;
- };
-
- const testNonExpiredSilenceScenario = () => {
- setSilenceState('active');
- permissionHelper.testScenarios(scenario);
- setSilenceState('pending');
- permissionHelper.testScenarios(scenario);
- };
-
- beforeEach(() => {
- permissionHelper = new PermissionHelper(component.permission, () =>
- getTableActionComponent()
- );
- permissionHelper.createSelection = () => ({ status: { state: silenceState } });
- scenario = {
- fn: () => tableActions.getCurrentButton().name,
- single: 'Edit',
- empty: 'Create'
- };
- });
-
- describe('with all', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 1);
- });
-
- it(`shows 'Edit' for single non expired silence else 'Create' as main action`, () => {
- scenario.single = 'Edit';
- testNonExpiredSilenceScenario();
- });
-
- it(`shows 'Recreate' for single expired silence else 'Create' as main action`, () => {
- scenario.single = 'Recreate';
- setSilenceState('expired');
- permissionHelper.testScenarios(scenario);
- });
-
- it('can use all actions', () => {
- expect(tableActions.tableActions.length).toBe(4);
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and update', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 0);
- });
-
- it(`shows 'Edit' for single non expired silence else 'Create' as main action`, () => {
- scenario.single = 'Edit';
- testNonExpiredSilenceScenario();
- });
-
- it(`shows 'Recreate' for single expired silence else 'Create' as main action`, () => {
- scenario.single = 'Recreate';
- setSilenceState('expired');
- permissionHelper.testScenarios(scenario);
- });
-
- it(`can use all actions except for 'Expire'`, () => {
- expect(tableActions.tableActions.length).toBe(3);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[0],
- component.tableActions[1],
- component.tableActions[2]
- ]);
- });
- });
-
- describe('with read, create and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 1);
- });
-
- it(`shows 'Expire' for single non expired silence else 'Create' as main action`, () => {
- scenario.single = 'Expire';
- testNonExpiredSilenceScenario();
- });
-
- it(`shows 'Recreate' for single expired silence else 'Create' as main action`, () => {
- scenario.single = 'Recreate';
- setSilenceState('expired');
- permissionHelper.testScenarios(scenario);
- });
-
- it(`can use 'Create' and 'Expire' action`, () => {
- expect(tableActions.tableActions.length).toBe(3);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[0],
- component.tableActions[1],
- component.tableActions[3]
- ]);
- });
- });
-
- describe('with read, edit and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 1);
- });
-
- it(`shows always 'Edit' as main action for any state`, () => {
- scenario.single = 'Edit';
- scenario.empty = 'Edit';
- testNonExpiredSilenceScenario();
- setSilenceState('expired');
- permissionHelper.testScenarios(scenario);
- });
-
- it(`can use 'Edit' and 'Expire' action`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[2],
- component.tableActions[3]
- ]);
- });
- });
-
- describe('with read and create', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 0);
- });
-
- it(`shows always 'Create' as main action for single non expired silences`, () => {
- scenario.single = 'Create';
- testNonExpiredSilenceScenario();
- });
-
- it(`shows 'Recreate' for single expired silence else 'Create' as main action`, () => {
- scenario.single = 'Recreate';
- setSilenceState('expired');
- permissionHelper.testScenarios(scenario);
- });
-
- it(`can use 'Create' and 'Recreate' actions`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[0],
- component.tableActions[1]
- ]);
- });
- });
-
- describe('with read and edit', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 0);
- });
-
- it(`shows always 'Edit' as main action for any state`, () => {
- scenario.single = 'Edit';
- scenario.empty = 'Edit';
- testNonExpiredSilenceScenario();
- setSilenceState('expired');
- permissionHelper.testScenarios(scenario);
- });
-
- it(`can use 'Edit' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[2]]);
- });
- });
-
- describe('with read and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 0, 1);
- });
-
- it(`shows always 'Expire' as main action for any state`, () => {
- scenario.single = 'Expire';
- scenario.empty = 'Expire';
- testNonExpiredSilenceScenario();
- setSilenceState('expired');
- permissionHelper.testScenarios(scenario);
- });
-
- it(`can use 'Expire' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[3]]);
- });
- });
-
- 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('can use 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: ['Create', 'Recreate', 'Edit', 'Expire'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,update': {
+ actions: ['Create', 'Recreate', 'Edit'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,delete': {
+ actions: ['Create', 'Recreate', 'Expire'],
+ primary: { multiple: 'Create', executing: 'Expire', single: 'Expire', no: 'Create' }
+ },
+ create: {
+ actions: ['Create', 'Recreate'],
+ primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
+ },
+ 'update,delete': {
+ actions: ['Edit', 'Expire'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ update: {
+ actions: ['Edit'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ delete: {
+ actions: ['Expire'],
+ primary: { multiple: 'Expire', executing: 'Expire', single: 'Expire', no: 'Expire' }
+ },
+ 'no-permissions': {
+ actions: [],
+ primary: { multiple: '', executing: '', single: '', no: '' }
+ }
});
});
-import { Component, OnInit } from '@angular/core';
+import { Component } from '@angular/core';
import { I18n } from '@ngx-translate/i18n-polyfill';
import { SortDirection, SortPropDir } from '@swimlane/ngx-datatable';
templateUrl: './silence-list.component.html',
styleUrls: ['./silence-list.component.scss']
})
-export class SilenceListComponent implements OnInit {
+export class SilenceListComponent {
silences: AlertmanagerSilence[] = [];
columns: CdTableColumn[];
tableActions: CdTableAction[];
private succeededLabels: SucceededActionLabelsI18n
) {
this.permission = this.authStorageService.getPermissions().prometheus;
- }
-
- ngOnInit() {
const selectionExpired = (selection: CdTableSelection) =>
- selection.first() && selection.first().status.state === 'expired';
+ selection.first() && selection.first().status && selection.first().status.state === 'expired';
this.tableActions = [
{
permission: 'create',
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
-import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { TabsModule } from 'ngx-bootstrap/tabs';
});
});
- 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: 'Create'
- };
- });
-
- describe('with all', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 1);
- });
-
- it(`shows 'Edit' for single selection else 'Create' as main action`, () =>
- permissionHelper.testScenarios(scenario));
-
- it('shows all actions', () => {
- expect(tableActions.tableActions.length).toBe(3);
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and update', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 0);
- });
-
- it(`shows 'Edit' for single selection else 'Create' as main action`, () =>
- permissionHelper.testScenarios(scenario));
-
- it(`shows all actions except for 'Delete'`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- component.tableActions.pop();
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 1);
- });
-
- it(`shows 'Delete' for single selection else 'Create' as main action`, () => {
- scenario.single = 'Delete';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Create', and 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[0],
- component.tableActions[2]
- ]);
- });
- });
-
- describe('with read, edit and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 1);
- });
-
- it(`shows always 'Edit' as main action`, () => {
- scenario.empty = 'Edit';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Edit' and 'Delete' actions`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[1],
- component.tableActions[2]
- ]);
- });
- });
-
- describe('with read and create', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 0);
- });
-
- it(`always shows 'Create' as main action`, () => {
- scenario.single = 'Create';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Create' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[0]]);
- });
- });
-
- describe('with read and edit', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 0);
- });
-
- it(`shows always 'Edit' as main action`, () => {
- scenario.empty = 'Edit';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Edit' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[1]]);
- });
- });
-
- describe('with read and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 0, 1);
- });
-
- it(`shows always 'Delete' as main action`, () => {
- scenario.single = 'Delete';
- scenario.empty = 'Delete';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[2]]);
- });
- });
-
- 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: ['Create', 'Edit', 'Delete'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,update': {
+ actions: ['Create', 'Edit'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,delete': {
+ actions: ['Create', 'Delete'],
+ primary: { multiple: 'Create', executing: 'Delete', single: 'Delete', no: 'Create' }
+ },
+ create: {
+ actions: ['Create'],
+ primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
+ },
+ 'update,delete': {
+ actions: ['Edit', 'Delete'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ update: {
+ actions: ['Edit'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ delete: {
+ actions: ['Delete'],
+ primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
+ },
+ 'no-permissions': {
+ actions: [],
+ primary: { multiple: '', executing: '', single: '', no: '' }
+ }
});
});
});
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { ModalModule } from 'ngx-bootstrap/modal';
i18nProviders,
PermissionHelper
} from '../../../../testing/unit-test-helper';
-import { ActionLabels } from '../../../shared/constants/app.constants';
import { TableActionsComponent } from '../../../shared/datatable/table-actions/table-actions.component';
import { SharedModule } from '../../../shared/shared.module';
import { RgwBucketDetailsComponent } from '../rgw-bucket-details/rgw-bucket-details.component';
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: ActionLabels.EDIT,
- empty: ActionLabels.CREATE
- };
- });
-
- describe('with all', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 1);
- });
-
- it(`shows 'Edit' for single selection else 'Add' as main action`, () =>
- permissionHelper.testScenarios(scenario));
-
- it('shows all actions', () => {
- expect(tableActions.tableActions.length).toBe(3);
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and update', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 0);
- });
-
- it(`shows 'Edit' for single selection else 'Add' as main action`, () =>
- permissionHelper.testScenarios(scenario));
-
- it(`shows 'Add' and 'Edit' action`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- component.tableActions.pop();
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 1);
- });
-
- it(`shows 'Delete' for single selection else 'Add' as main action`, () => {
- scenario.single = 'Delete';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Add' and 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[0],
- component.tableActions[2]
- ]);
- });
- });
-
- describe('with read, edit and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 1);
- });
-
- it(`shows always 'Edit' as main action`, () => {
- scenario.empty = ActionLabels.EDIT;
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Edit' and 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[1],
- component.tableActions[2]
- ]);
- });
- });
-
- describe('with read and create', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 0);
- });
-
- it(`shows always 'Add' as main action`, () => {
- scenario.single = ActionLabels.CREATE;
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows only 'Add' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[0]]);
- });
- });
-
- describe('with read and update', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 0);
- });
-
- it(`shows always 'Edit' as main action`, () => {
- scenario.empty = ActionLabels.EDIT;
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows only 'Edit' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[1]]);
- });
- });
-
- describe('with read and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 0, 1);
- });
-
- it(`shows always 'Delete' as main action`, () => {
- scenario.single = 'Delete';
- scenario.empty = 'Delete';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows only 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[2]]);
- });
- });
-
- 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: ['Create', 'Edit', 'Delete'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,update': {
+ actions: ['Create', 'Edit'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,delete': {
+ actions: ['Create', 'Delete'],
+ primary: { multiple: 'Create', executing: 'Delete', single: 'Delete', no: 'Create' }
+ },
+ create: {
+ actions: ['Create'],
+ primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
+ },
+ 'update,delete': {
+ actions: ['Edit', 'Delete'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ update: {
+ actions: ['Edit'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ delete: {
+ actions: ['Delete'],
+ primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
+ },
+ 'no-permissions': {
+ actions: [],
+ primary: { multiple: '', executing: '', single: '', no: '' }
+ }
});
});
});
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { ModalModule } from 'ngx-bootstrap/modal';
i18nProviders,
PermissionHelper
} from '../../../../testing/unit-test-helper';
-import { ActionLabels } from '../../../shared/constants/app.constants';
import { TableActionsComponent } from '../../../shared/datatable/table-actions/table-actions.component';
import { SharedModule } from '../../../shared/shared.module';
import { RgwUserListComponent } from './rgw-user-list.component';
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: ActionLabels.EDIT,
- empty: ActionLabels.CREATE
- };
- });
-
- describe('with all', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 1);
- });
-
- it(`shows 'Edit' for single selection else 'Add' as main action`, () =>
- permissionHelper.testScenarios(scenario));
-
- it('shows all actions', () => {
- expect(tableActions.tableActions.length).toBe(3);
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and update', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 0);
- });
-
- it(`shows 'Edit' for single selection else 'Add' as main action`, () =>
- permissionHelper.testScenarios(scenario));
-
- it(`shows 'Add' and 'Edit' action`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- component.tableActions.pop();
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 1);
- });
-
- it(`shows 'Delete' for single selection else 'Add' as main action`, () => {
- scenario.single = 'Delete';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Add' and 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[0],
- component.tableActions[2]
- ]);
- });
- });
-
- describe('with read, edit and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 1);
- });
-
- it(`shows always 'Edit' as main action`, () => {
- scenario.empty = ActionLabels.EDIT;
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Edit' and 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[1],
- component.tableActions[2]
- ]);
- });
- });
-
- describe('with read and create', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 0);
- });
-
- it(`shows always 'Add' as main action`, () => {
- scenario.single = ActionLabels.CREATE;
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows only 'Add' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[0]]);
- });
- });
-
- describe('with read and update', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 0);
- });
-
- it(`shows always 'Edit' as main action`, () => {
- scenario.empty = ActionLabels.EDIT;
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows only 'Edit' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[1]]);
- });
- });
-
- describe('with read and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 0, 1);
- });
-
- it(`shows always 'Delete' as main action`, () => {
- scenario.single = 'Delete';
- scenario.empty = 'Delete';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows only 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[2]]);
- });
- });
-
- 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: ['Create', 'Edit', 'Delete'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,update': {
+ actions: ['Create', 'Edit'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,delete': {
+ actions: ['Create', 'Delete'],
+ primary: { multiple: 'Create', executing: 'Delete', single: 'Delete', no: 'Create' }
+ },
+ create: {
+ actions: ['Create'],
+ primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
+ },
+ 'update,delete': {
+ actions: ['Edit', 'Delete'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ update: {
+ actions: ['Edit'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ delete: {
+ actions: ['Delete'],
+ primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
+ },
+ 'no-permissions': {
+ actions: [],
+ primary: { multiple: '', executing: '', single: '', no: '' }
+ }
});
});
});
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { TabsModule } from 'ngx-bootstrap/tabs';
i18nProviders,
PermissionHelper
} from '../../../../testing/unit-test-helper';
-import { ActionLabels } from '../../../shared/constants/app.constants';
import { TableActionsComponent } from '../../../shared/datatable/table-actions/table-actions.component';
import { SharedModule } from '../../../shared/shared.module';
import { RoleDetailsComponent } from '../role-details/role-details.component';
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: ActionLabels.EDIT,
- empty: ActionLabels.CREATE
- };
- });
-
- describe('with all', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 1);
- });
-
- it(`shows 'Edit' for single selection else 'Add' as main action`, () =>
- permissionHelper.testScenarios(scenario));
-
- it('shows all actions', () => {
- expect(tableActions.tableActions.length).toBe(3);
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and update', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 0);
- });
-
- it(`shows 'Edit' for single selection else 'Add' as main action`, () =>
- permissionHelper.testScenarios(scenario));
-
- it(`shows 'Add' and 'Edit' action`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- component.tableActions.pop();
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 1);
- });
-
- it(`shows 'Delete' for single selection else 'Add' as main action`, () => {
- scenario.single = 'Delete';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Add' and 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[0],
- component.tableActions[2]
- ]);
- });
- });
-
- describe('with read, edit and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 1);
- });
-
- it(`shows always 'Edit' as main action`, () => {
- scenario.empty = ActionLabels.EDIT;
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Edit' and 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[1],
- component.tableActions[2]
- ]);
- });
- });
-
- describe('with read and create', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 0);
- });
-
- it(`shows always 'Add' as main action`, () => {
- scenario.single = ActionLabels.CREATE;
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows only 'Add' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[0]]);
- });
- });
-
- describe('with read and update', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 0);
- });
-
- it(`shows always 'Edit' as main action`, () => {
- scenario.empty = ActionLabels.EDIT;
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows only 'Edit' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[1]]);
- });
- });
-
- describe('with read and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 0, 1);
- });
-
- it(`shows always 'Delete' as main action`, () => {
- scenario.single = 'Delete';
- scenario.empty = 'Delete';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows only 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[2]]);
- });
- });
-
- 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: ['Create', 'Edit', 'Delete'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,update': {
+ actions: ['Create', 'Edit'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,delete': {
+ actions: ['Create', 'Delete'],
+ primary: { multiple: 'Create', executing: 'Delete', single: 'Delete', no: 'Create' }
+ },
+ create: {
+ actions: ['Create'],
+ primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
+ },
+ 'update,delete': {
+ actions: ['Edit', 'Delete'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ update: {
+ actions: ['Edit'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ delete: {
+ actions: ['Delete'],
+ primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
+ },
+ 'no-permissions': {
+ actions: [],
+ primary: { multiple: '', executing: '', single: '', no: '' }
+ }
});
});
});
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { TabsModule } from 'ngx-bootstrap/tabs';
i18nProviders,
PermissionHelper
} from '../../../../testing/unit-test-helper';
-import { ActionLabels } from '../../../shared/constants/app.constants';
import { TableActionsComponent } from '../../../shared/datatable/table-actions/table-actions.component';
import { SharedModule } from '../../../shared/shared.module';
import { UserTabsComponent } from '../user-tabs/user-tabs.component';
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: ActionLabels.EDIT,
- empty: ActionLabels.CREATE
- };
- });
-
- describe('with all', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 1);
- });
-
- it(`shows 'Edit' for single selection else 'Add' as main action`, () =>
- permissionHelper.testScenarios(scenario));
-
- it('shows all actions', () => {
- expect(tableActions.tableActions.length).toBe(3);
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and update', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 0);
- });
-
- it(`shows 'Edit' for single selection else 'Add' as main action`, () =>
- permissionHelper.testScenarios(scenario));
-
- it(`shows 'Add' and 'Edit' action`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- component.tableActions.pop();
- expect(tableActions.tableActions).toEqual(component.tableActions);
- });
- });
-
- describe('with read, create and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 1);
- });
-
- it(`shows 'Delete' for single selection else 'Add' as main action`, () => {
- scenario.single = 'Delete';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Add' and 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[0],
- component.tableActions[2]
- ]);
- });
- });
-
- describe('with read, edit and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 1);
- });
-
- it(`shows always 'Edit' as main action`, () => {
- scenario.empty = ActionLabels.EDIT;
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows 'Edit' and 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(2);
- expect(tableActions.tableActions).toEqual([
- component.tableActions[1],
- component.tableActions[2]
- ]);
- });
- });
-
- describe('with read and create', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 0);
- });
-
- it(`shows always 'Add' as main action`, () => {
- scenario.single = ActionLabels.CREATE;
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows only 'Add' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[0]]);
- });
- });
-
- describe('with read and update', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 0);
- });
-
- it(`shows always 'Edit' as main action`, () => {
- scenario.empty = 'Edit';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows only 'Edit' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[1]]);
- });
- });
-
- describe('with read and delete', () => {
- beforeEach(() => {
- tableActions = permissionHelper.setPermissionsAndGetActions(0, 0, 1);
- });
-
- it(`shows always 'Delete' as main action`, () => {
- scenario.single = 'Delete';
- scenario.empty = 'Delete';
- permissionHelper.testScenarios(scenario);
- });
-
- it(`shows only 'Delete' action`, () => {
- expect(tableActions.tableActions.length).toBe(1);
- expect(tableActions.tableActions).toEqual([component.tableActions[2]]);
- });
- });
-
- 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: ['Create', 'Edit', 'Delete'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,update': {
+ actions: ['Create', 'Edit'],
+ primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
+ },
+ 'create,delete': {
+ actions: ['Create', 'Delete'],
+ primary: { multiple: 'Create', executing: 'Delete', single: 'Delete', no: 'Create' }
+ },
+ create: {
+ actions: ['Create'],
+ primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
+ },
+ 'update,delete': {
+ actions: ['Edit', 'Delete'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ update: {
+ actions: ['Edit'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ delete: {
+ actions: ['Delete'],
+ primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
+ },
+ 'no-permissions': {
+ actions: [],
+ primary: { multiple: '', executing: '', single: '', no: '' }
+ }
});
});
});
let unprotectAction: CdTableAction;
let deleteAction: CdTableAction;
let copyAction: CdTableAction;
- let scenario;
let permissionHelper: PermissionHelper;
- const getTableActionComponent = (): TableActionsComponent => {
- component.tableActions = [
- addAction,
- editAction,
- protectAction,
- unprotectAction,
- copyAction,
- deleteAction
- ];
- component.ngOnInit();
- return component;
- };
-
configureTestBed({
declarations: [TableActionsComponent],
imports: [ComponentsModule, RouterTestingModule]
component.selection = new CdTableSelection();
component.permission = new Permission();
component.permission.read = true;
- permissionHelper = new PermissionHelper(component.permission, () => getTableActionComponent());
- permissionHelper.setPermissionsAndGetActions(1, 1, 1);
+ component.tableActions = [
+ addAction,
+ editAction,
+ protectAction,
+ unprotectAction,
+ copyAction,
+ deleteAction
+ ];
+ permissionHelper = new PermissionHelper(component.permission);
+ permissionHelper.setPermissionsAndGetActions(component.tableActions);
});
it('should create', () => {
expect(component).toBeTruthy();
});
- it('should ngInit should be called with no permissions', () => {
+ it('should call ngInit without permissions', () => {
component.permission = undefined;
component.ngOnInit();
expect(component.tableActions).toEqual([]);
});
});
- describe('disableSelectionAction', () => {
- beforeEach(() => {
- scenario = {
- fn: () => null,
- multiple: false,
- singleExecuting: false,
- single: false,
- empty: false
- };
- });
-
- it('tests disabling addAction', () => {
- scenario.fn = () => component.disableSelectionAction(addAction);
- permissionHelper.testScenarios(scenario);
- });
-
- it('tests disabling editAction', () => {
- scenario.fn = () => component.disableSelectionAction(editAction);
- scenario.multiple = true;
- scenario.empty = true;
- scenario.singleExecuting = true;
- permissionHelper.testScenarios(scenario);
- });
-
- it('tests disabling deleteAction', () => {
- scenario.fn = () => component.disableSelectionAction(deleteAction);
- scenario.multiple = false;
- scenario.empty = true;
- scenario.singleExecuting = true;
- permissionHelper.testScenarios(scenario);
- });
-
- it('tests disabling copyAction', () => {
- scenario.fn = () => component.disableSelectionAction(copyAction);
- scenario.multiple = true;
- scenario.empty = true;
- scenario.singleExecuting = true;
- permissionHelper.testScenarios(scenario);
- });
- });
-
- describe('get current button', () => {
- const hiddenScenario = () => {
- scenario.multiple = undefined;
- scenario.empty = undefined;
- scenario.singleExecuting = undefined;
- scenario.single = undefined;
- };
-
- const setScenario = (defaultAction, selectionAction) => {
- scenario.single = selectionAction;
- scenario.singleExecuting = selectionAction;
- scenario.multiple = defaultAction;
- scenario.empty = defaultAction;
- };
-
- beforeEach(() => {
- scenario = {
- fn: () => component.getCurrentButton(),
- singleExecuting: copyAction,
- single: copyAction,
- empty: addAction
- };
- });
-
- it('gets add for no, edit for single and delete for multiple selections', () => {
- setScenario(addAction, editAction);
- scenario.multiple = deleteAction;
- permissionHelper.setPermissionsAndGetActions(1, 1, 1);
- permissionHelper.testScenarios(scenario);
- });
-
- it('gets add action except for selections where it shows edit action', () => {
- setScenario(addAction, editAction);
- permissionHelper.setPermissionsAndGetActions(1, 1, 0);
- permissionHelper.testScenarios(scenario);
- });
-
- it('gets add for no, copy for single and delete for multiple selections', () => {
- setScenario(addAction, copyAction);
- scenario.multiple = deleteAction;
- permissionHelper.setPermissionsAndGetActions(1, 0, 1);
- permissionHelper.testScenarios(scenario);
- });
-
- it('gets add action except for selections where it shows copy action', () => {
- setScenario(addAction, copyAction);
- permissionHelper.setPermissionsAndGetActions(1, 0, 0);
- permissionHelper.testScenarios(scenario);
- });
-
- it('should always get edit action except delete for multiple items', () => {
- setScenario(editAction, editAction);
- scenario.multiple = deleteAction;
- permissionHelper.setPermissionsAndGetActions(0, 1, 1);
- permissionHelper.testScenarios(scenario);
- });
-
- it('should always get edit action', () => {
- setScenario(editAction, editAction);
- permissionHelper.setPermissionsAndGetActions(0, 1, 0);
- permissionHelper.testScenarios(scenario);
- });
-
- it('should always get delete action', () => {
- setScenario(deleteAction, deleteAction);
- permissionHelper.setPermissionsAndGetActions(0, 0, 1);
- permissionHelper.testScenarios(scenario);
- });
-
- it('should not get any button with no permissions, except the true action', () => {
- hiddenScenario();
- permissionHelper.setPermissionsAndGetActions(0, 0, 0);
- permissionHelper.testScenarios(scenario);
- });
-
- it('should not get any button if only a drop down should be shown', () => {
- hiddenScenario();
- component.dropDownOnly = 'Drop down label that is shown';
- permissionHelper.setPermissionsAndGetActions(1, 1, 1);
- permissionHelper.testScenarios(scenario);
- });
- });
-
- describe('show drop down', () => {
- const testShowDropDownActions = (perms, expected) => {
- permissionHelper.setPermissionsAndGetActions(perms[0], perms[1], perms[2]);
- expect(`${perms} ${component.showDropDownActions()}`).toBe(`${perms} ${expected}`);
- };
-
- it('is shown if multiple items are found depending on the permissions', () => {
- [[1, 0, 0], [1, 1, 1], [1, 1, 0], [1, 0, 1], [0, 1, 1], [0, 1, 0]].forEach((perms) => {
- testShowDropDownActions(perms, true);
- });
- });
-
- it('is not shown if only 1 or less items are found depending on the permissions', () => {
- [[0, 0, 1], [0, 0, 0]].forEach((perms) => {
- testShowDropDownActions(perms, false);
- });
- });
- });
-
- describe('all visible actions with all different permissions', () => {
- it('with create, update and delete', () => {
- permissionHelper.setPermissionsAndGetActions(1, 1, 1);
- expect(component.dropDownActions).toEqual([
- addAction,
- editAction,
- unprotectAction,
- copyAction,
- deleteAction
- ]);
- });
-
- it('with create and delete', () => {
- permissionHelper.setPermissionsAndGetActions(1, 0, 1);
- expect(component.dropDownActions).toEqual([addAction, copyAction, deleteAction]);
- });
-
- it('with create and update', () => {
- permissionHelper.setPermissionsAndGetActions(1, 1, 0);
- expect(component.dropDownActions).toEqual([
- addAction,
- editAction,
- unprotectAction,
- copyAction
- ]);
- });
-
- it('with create', () => {
- permissionHelper.setPermissionsAndGetActions(1, 0, 0);
- expect(component.dropDownActions).toEqual([addAction, copyAction]);
- });
-
- it('with update and delete', () => {
- permissionHelper.setPermissionsAndGetActions(0, 1, 1);
- expect(component.dropDownActions).toEqual([editAction, unprotectAction, deleteAction]);
- });
-
- it('with update', () => {
- permissionHelper.setPermissionsAndGetActions(0, 1, 0);
- expect(component.dropDownActions).toEqual([editAction, unprotectAction]);
- });
-
- it('with delete', () => {
- permissionHelper.setPermissionsAndGetActions(0, 0, 1);
- expect(component.dropDownActions).toEqual([deleteAction]);
- });
-
- it('without any', () => {
- permissionHelper.setPermissionsAndGetActions(0, 0, 0);
- expect(component.dropDownActions).toEqual([]);
+ it('should test all TableActions combinations', () => {
+ const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions(
+ component.tableActions
+ );
+ expect(tableActions).toEqual({
+ 'create,update,delete': {
+ actions: ['Add', 'Edit', 'Protect', 'Unprotect', 'Copy', 'Delete'],
+ primary: { multiple: 'Delete', executing: 'Edit', single: 'Edit', no: 'Add' }
+ },
+ 'create,update': {
+ actions: ['Add', 'Edit', 'Protect', 'Unprotect', 'Copy'],
+ primary: { multiple: 'Add', executing: 'Edit', single: 'Edit', no: 'Add' }
+ },
+ 'create,delete': {
+ actions: ['Add', 'Copy', 'Delete'],
+ primary: { multiple: 'Delete', executing: 'Copy', single: 'Copy', no: 'Add' }
+ },
+ create: {
+ actions: ['Add', 'Copy'],
+ primary: { multiple: 'Add', executing: 'Copy', single: 'Copy', no: 'Add' }
+ },
+ 'update,delete': {
+ actions: ['Edit', 'Protect', 'Unprotect', 'Delete'],
+ primary: { multiple: 'Delete', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ update: {
+ actions: ['Edit', 'Protect', 'Unprotect'],
+ primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
+ },
+ delete: {
+ actions: ['Delete'],
+ primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
+ },
+ 'no-permissions': {
+ actions: [],
+ primary: { multiple: '', executing: '', single: '', no: '' }
+ }
});
});
import { By } from '@angular/platform-browser';
import { I18n } from '@ngx-translate/i18n-polyfill';
-import * as _ from 'lodash';
import { TableActionsComponent } from '../app/shared/datatable/table-actions/table-actions.component';
import { Icons } from '../app/shared/enum/icons.enum';
import { CdFormGroup } from '../app/shared/forms/cd-form-group';
+import { CdTableAction } from '../app/shared/models/cd-table-action';
+import { CdTableSelection } from '../app/shared/models/cd-table-selection';
import { Permission } from '../app/shared/models/permissions';
import {
AlertmanagerAlert,
}
export class PermissionHelper {
- tableActions: TableActionsComponent;
+ tac: TableActionsComponent;
permission: Permission;
- getTableActionComponent: () => TableActionsComponent;
- constructor(permission: Permission, getTableActionComponent: () => TableActionsComponent) {
+ constructor(permission: Permission) {
this.permission = permission;
- this.getTableActionComponent = getTableActionComponent;
}
- setPermissionsAndGetActions(
- createPerm: number | boolean,
- updatePerm: number | boolean,
- deletePerm: number | boolean
- ): TableActionsComponent {
- this.permission.create = Boolean(createPerm);
- this.permission.update = Boolean(updatePerm);
- this.permission.delete = Boolean(deletePerm);
- this.tableActions = this.getTableActionComponent();
- return this.tableActions;
- }
+ setPermissionsAndGetActions(tableActions: CdTableAction[]): any {
+ const result = {};
+ [true, false].forEach((create) => {
+ [true, false].forEach((update) => {
+ [true, false].forEach((deleteP) => {
+ this.permission.create = create;
+ this.permission.update = update;
+ this.permission.delete = deleteP;
+
+ this.tac = new TableActionsComponent();
+ this.tac.selection = new CdTableSelection();
+ this.tac.tableActions = [...tableActions];
+ this.tac.permission = this.permission;
+ this.tac.ngOnInit();
+
+ const perms = [];
+ if (create) {
+ perms.push('create');
+ }
+ if (update) {
+ perms.push('update');
+ }
+ if (deleteP) {
+ perms.push('delete');
+ }
+ const permissionText = perms.join(',');
+
+ result[permissionText !== '' ? permissionText : 'no-permissions'] = {
+ actions: this.tac.tableActions.map((action) => action.name),
+ primary: this.testScenarios()
+ };
+ });
+ });
+ });
- // Overwrite if needed
- createSelection(): object {
- return {};
+ return result;
}
- testScenarios({
- fn,
- empty,
- single,
- singleExecuting,
- multiple
- }: {
- fn: () => any;
- empty: any;
- single: any;
- singleExecuting?: any; // uses 'single' if not defined
- multiple?: any; // uses 'empty' if not defined
- }) {
- this.testScenario(
- // 'multiple selections'
- [this.createSelection(), this.createSelection()],
- fn,
- _.isUndefined(multiple) ? empty : multiple
- );
- const executing = this.createSelection();
- executing['cdExecuting'] = 'someAction';
- this.testScenario(
- // 'select executing item'
- [executing],
- fn,
- _.isUndefined(singleExecuting) ? single : singleExecuting
- );
- this.testScenario([this.createSelection()], fn, single); // 'select non-executing item'
- this.testScenario([], fn, empty); // 'no selection'
+ testScenarios() {
+ const result: any = {};
+ // 'multiple selections'
+ result.multiple = this.testScenario([{}, {}]);
+ // 'select executing item'
+ result.executing = this.testScenario([{ cdExecuting: 'someAction' }]);
+ // 'select non-executing item'
+ result.single = this.testScenario([{}]);
+ // 'no selection'
+ result.no = this.testScenario([]);
+
+ return result;
}
- private testScenario(selection: object[], fn: () => any, expected: any) {
+ private testScenario(selection: object[]) {
this.setSelection(selection);
- expect(fn()).toBe(expected);
+ const btn = this.tac.getCurrentButton();
+ return btn ? btn.name : '';
}
setSelection(selection: object[]) {
- this.tableActions.selection.selected = selection;
- this.tableActions.selection.update();
+ this.tac.selection.selected = selection;
+ this.tac.selection.update();
}
}