]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
c6bb981d0a339dcd5e8fe249a1c8575c1940c379
[ceph.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { By } from '@angular/platform-browser';
4 import { RouterTestingModule } from '@angular/router/testing';
5
6 import { ModalModule } from 'ngx-bootstrap/modal';
7 import { TabsModule } from 'ngx-bootstrap/tabs';
8
9 import {
10   configureTestBed,
11   i18nProviders,
12   PermissionHelper
13 } from '../../../../testing/unit-test-helper';
14 import { TableActionsComponent } from '../../../shared/datatable/table-actions/table-actions.component';
15 import { SharedModule } from '../../../shared/shared.module';
16 import { RgwBucketDetailsComponent } from '../rgw-bucket-details/rgw-bucket-details.component';
17 import { RgwBucketListComponent } from './rgw-bucket-list.component';
18
19 describe('RgwBucketListComponent', () => {
20   let component: RgwBucketListComponent;
21   let fixture: ComponentFixture<RgwBucketListComponent>;
22
23   configureTestBed({
24     declarations: [RgwBucketListComponent, RgwBucketDetailsComponent],
25     imports: [
26       RouterTestingModule,
27       ModalModule.forRoot(),
28       SharedModule,
29       TabsModule.forRoot(),
30       HttpClientTestingModule
31     ],
32     providers: i18nProviders
33   });
34
35   beforeEach(() => {
36     fixture = TestBed.createComponent(RgwBucketListComponent);
37     component = fixture.componentInstance;
38   });
39
40   it('should create', () => {
41     fixture.detectChanges();
42     expect(component).toBeTruthy();
43   });
44
45   describe('show action buttons and drop down actions depending on permissions', () => {
46     let tableActions: TableActionsComponent;
47     let scenario: { fn; empty; single };
48     let permissionHelper: PermissionHelper;
49
50     const getTableActionComponent = (): TableActionsComponent => {
51       fixture.detectChanges();
52       return fixture.debugElement.query(By.directive(TableActionsComponent)).componentInstance;
53     };
54
55     beforeEach(() => {
56       permissionHelper = new PermissionHelper(component.permission, () =>
57         getTableActionComponent()
58       );
59       scenario = {
60         fn: () => tableActions.getCurrentButton().name,
61         single: 'Edit',
62         empty: 'Add'
63       };
64     });
65
66     describe('with all', () => {
67       beforeEach(() => {
68         tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 1);
69       });
70
71       it(`shows 'Edit' for single selection else 'Add' as main action`, () =>
72         permissionHelper.testScenarios(scenario));
73
74       it('shows all actions', () => {
75         expect(tableActions.tableActions.length).toBe(3);
76         expect(tableActions.tableActions).toEqual(component.tableActions);
77       });
78     });
79
80     describe('with read, create and update', () => {
81       beforeEach(() => {
82         tableActions = permissionHelper.setPermissionsAndGetActions(1, 1, 0);
83       });
84
85       it(`shows 'Edit' for single selection else 'Add' as main action`, () =>
86         permissionHelper.testScenarios(scenario));
87
88       it(`shows 'Add' and 'Edit' action`, () => {
89         expect(tableActions.tableActions.length).toBe(2);
90         component.tableActions.pop();
91         expect(tableActions.tableActions).toEqual(component.tableActions);
92       });
93     });
94
95     describe('with read, create and delete', () => {
96       beforeEach(() => {
97         tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 1);
98       });
99
100       it(`shows 'Delete' for single selection else 'Add' as main action`, () => {
101         scenario.single = 'Delete';
102         permissionHelper.testScenarios(scenario);
103       });
104
105       it(`shows 'Add' and 'Delete' action`, () => {
106         expect(tableActions.tableActions.length).toBe(2);
107         expect(tableActions.tableActions).toEqual([
108           component.tableActions[0],
109           component.tableActions[2]
110         ]);
111       });
112     });
113
114     describe('with read, edit and delete', () => {
115       beforeEach(() => {
116         tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 1);
117       });
118
119       it(`shows always 'Edit' as main action`, () => {
120         scenario.empty = 'Edit';
121         permissionHelper.testScenarios(scenario);
122       });
123
124       it(`shows 'Edit' and 'Delete' action`, () => {
125         expect(tableActions.tableActions.length).toBe(2);
126         expect(tableActions.tableActions).toEqual([
127           component.tableActions[1],
128           component.tableActions[2]
129         ]);
130       });
131     });
132
133     describe('with read and create', () => {
134       beforeEach(() => {
135         tableActions = permissionHelper.setPermissionsAndGetActions(1, 0, 0);
136       });
137
138       it(`shows always 'Add' as main action`, () => {
139         scenario.single = 'Add';
140         permissionHelper.testScenarios(scenario);
141       });
142
143       it(`shows only 'Add' action`, () => {
144         expect(tableActions.tableActions.length).toBe(1);
145         expect(tableActions.tableActions).toEqual([component.tableActions[0]]);
146       });
147     });
148
149     describe('with read and update', () => {
150       beforeEach(() => {
151         tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 0);
152       });
153
154       it(`shows always 'Edit' as main action`, () => {
155         scenario.empty = 'Edit';
156         permissionHelper.testScenarios(scenario);
157       });
158
159       it(`shows only 'Edit' action`, () => {
160         expect(tableActions.tableActions.length).toBe(1);
161         expect(tableActions.tableActions).toEqual([component.tableActions[1]]);
162       });
163     });
164
165     describe('with read and delete', () => {
166       beforeEach(() => {
167         tableActions = permissionHelper.setPermissionsAndGetActions(0, 0, 1);
168       });
169
170       it(`shows always 'Delete' as main action`, () => {
171         scenario.single = 'Delete';
172         scenario.empty = 'Delete';
173         permissionHelper.testScenarios(scenario);
174       });
175
176       it(`shows only 'Delete' action`, () => {
177         expect(tableActions.tableActions.length).toBe(1);
178         expect(tableActions.tableActions).toEqual([component.tableActions[2]]);
179       });
180     });
181
182     describe('with only read', () => {
183       beforeEach(() => {
184         tableActions = permissionHelper.setPermissionsAndGetActions(0, 0, 0);
185       });
186
187       it('shows no main action', () => {
188         permissionHelper.testScenarios({
189           fn: () => tableActions.getCurrentButton(),
190           single: undefined,
191           empty: undefined
192         });
193       });
194
195       it('shows no actions', () => {
196         expect(tableActions.tableActions.length).toBe(0);
197         expect(tableActions.tableActions).toEqual([]);
198       });
199     });
200   });
201 });