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';
configureTestBed({
declarations: [MgrModuleListComponent, MgrModuleDetailsComponent],
imports: [
+ BrowserAnimationsModule,
RouterTestingModule,
SharedModule,
HttpClientTestingModule,
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: '' }
+ }
});
});
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,
always_on: false
});
- component.selection.update();
component.updateModuleState();
tick(2000);
tick(2000);
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,
always_on: false
});
- component.selection.update();
component.updateModuleState();
tick(2000);
expect(mgrModuleService.disable).toHaveBeenCalledWith('bar');
name: 'dashboard'
}
];
- component.selection.update();
expect(component.isTableActionDisabled('enabled')).toBeTruthy();
});
always_on: true
}
];
- component.selection.update();
expect(component.isTableActionDisabled('enabled')).toBeTruthy();
});
});