[updateSelectionOnRefresh]="'never'">
<div class="table-actions btn-toolbar"
*ngIf="permission.update">
- <div class="btn-group"
- dropdown>
- <button dropdownToggle
- type="button"
- class="btn btn-sm btn-primary dropdown-toggle tc_scrub_toggle"
- [ngClass]="{disabled: !tableComponent.selection.hasSelection}">
- <ng-container i18n>Perform Task </ng-container>
- <span class="caret"></span>
- </button>
- <ul *dropdownMenu
- class="dropdown-menu"
- role="menu">
- <li role="menuitem"
- (click)="scrubAction(false)">
- <a>
- <i class="fa fa-fw fa-stethoscope"></i>
- <ng-container i18n>Scrub</ng-container>
- </a>
- </li>
- <li role="menuitem"
- (click)="scrubAction(true)">
- <a>
- <i class="fa fa-fw fa-stethoscope"></i>
- <ng-container i18n>Deep Scrub</ng-container>
- </a>
- </li>
- </ul>
- </div>
+ <cd-table-actions [permission]="permission"
+ [selection]="selection"
+ onlyDropDown="Perform Task"
+ class="btn-group"
+ [tableActions]="tableActions">
+ </cd-table-actions>
<button class="btn btn-sm btn-default btn-label tc_configureCluster"
type="button"
import { HttpClientModule } from '@angular/common/http';
import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
import { TabsModule } from 'ngx-bootstrap/tabs';
-import { configureTestBed } from '../../../../../testing/unit-test-helper';
+import { configureTestBed, PermissionHelper } from '../../../../../testing/unit-test-helper';
import { ComponentsModule } from '../../../../shared/components/components.module';
import { DataTableModule } from '../../../../shared/datatable/datatable.module';
+import { TableActionsComponent } from '../../../../shared/datatable/table-actions/table-actions.component';
import { Permissions } from '../../../../shared/models/permissions';
import { DimlessPipe } from '../../../../shared/pipes/dimless.pipe';
import { AuthStorageService } from '../../../../shared/services/auth-storage.service';
});
it('should create', () => {
+ fixture.detectChanges();
expect(component).toBeTruthy();
});
+
+ 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.directive(TableActionsComponent)).componentInstance;
+ };
+
+ beforeEach(() => {
+ permissionHelper = new PermissionHelper(component.permission, () =>
+ getTableActionComponent()
+ );
+ scenario = {
+ fn: () => tableActions.getCurrentButton(),
+ single: undefined,
+ empty: undefined
+ };
+ tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 1);
+ });
+
+ it('shows no action button', () => permissionHelper.testScenarios(scenario));
+
+ it('shows all actions', () => {
+ expect(tableActions.tableActions.length).toBe(2);
+ expect(tableActions.tableActions).toEqual(component.tableActions);
+ });
+
+ it(`shows 'Perform task' as drop down`, () => {
+ expect(
+ fixture.debugElement.query(By.directive(TableActionsComponent)).query(By.css('button'))
+ .nativeElement.textContent
+ ).toBe('Perform Task');
+ });
+ });
});
import { OsdService } from '../../../../shared/api/osd.service';
import { TableComponent } from '../../../../shared/datatable/table/table.component';
import { CellTemplate } from '../../../../shared/enum/cell-template.enum';
+import { CdTableAction } from '../../../../shared/models/cd-table-action';
import { CdTableColumn } from '../../../../shared/models/cd-table-column';
import { CdTableSelection } from '../../../../shared/models/cd-table-selection';
import { Permission } from '../../../../shared/models/permissions';
tableComponent: TableComponent;
permission: Permission;
+ tableActions: CdTableAction[];
bsModalRef: BsModalRef;
osds = [];
columns: CdTableColumn[];
private modalService: BsModalService
) {
this.permission = this.authStorageService.getPermissions().osd;
+ const scrubAction: CdTableAction = {
+ permission: 'update',
+ icon: 'fa-stethoscope',
+ click: () => this.scrubAction(false),
+ name: 'Scrub'
+ };
+ const deleteAction: CdTableAction = {
+ permission: 'update',
+ icon: 'fa-cog',
+ click: () => this.scrubAction(true),
+ name: 'Deep Scrub'
+ };
+ this.tableActions = [scrubAction, deleteAction];
}
ngOnInit() {