1
- import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service' ;
2
1
import { waitForAsync , ComponentFixture , TestBed } from '@angular/core/testing' ;
3
2
import { MockStore , provideMockStore } from '@ngrx/store/testing' ;
4
3
import { NgxPaginationModule } from 'ngx-pagination' ;
@@ -7,28 +6,17 @@ import {
7
6
UserActionTypes ,
8
7
UserState ,
9
8
LoadUsers ,
10
- GrantRoleUser ,
11
- RevokeRoleUser ,
12
9
AddUserToGroup ,
13
10
RemoveUserFromGroup ,
14
11
} from '../../store' ;
15
- import { User } from '../../../user/models/user' ;
16
12
import { ActionsSubject } from '@ngrx/store' ;
17
13
import { DataTablesModule } from 'angular-datatables' ;
18
- import { Observable , of } from 'rxjs' ;
19
- import { FeatureToggleProvider } from 'src/app/modules/shared/feature-toggles/feature-toggle-provider.service' ;
20
- import { AppConfigurationClient } from '@azure/app-configuration' ;
21
- import { FeatureFilterProvider } from '../../../shared/feature-toggles/filters/feature-filter-provider.service' ;
22
- import { AzureAdB2CService } from '../../../login/services/azure.ad.b2c.service' ;
23
14
24
15
describe ( 'UsersListComponent' , ( ) => {
25
16
let component : UsersListComponent ;
26
17
let fixture : ComponentFixture < UsersListComponent > ;
27
18
let store : MockStore < UserState > ;
28
19
const actionSub : ActionsSubject = new ActionsSubject ( ) ;
29
- const fakeAppConfigurationConnectionString = 'Endpoint=http://fake.foo;Id=fake.id;Secret=fake.secret' ;
30
- let service : FeatureManagerService ;
31
- let fakeFeatureToggleProvider ;
32
20
33
21
const state : UserState = {
34
22
data : [
@@ -48,19 +36,12 @@ describe('UsersListComponent', () => {
48
36
49
37
beforeEach (
50
38
waitForAsync ( ( ) => {
51
- fakeFeatureToggleProvider = new FeatureToggleProvider (
52
- new AppConfigurationClient ( fakeAppConfigurationConnectionString ) ,
53
- new FeatureFilterProvider ( new AzureAdB2CService ( ) )
54
- ) ;
55
- service = new FeatureManagerService ( fakeFeatureToggleProvider ) ;
56
-
57
39
TestBed . configureTestingModule ( {
58
40
imports : [ NgxPaginationModule , DataTablesModule ] ,
59
41
declarations : [ UsersListComponent ] ,
60
42
providers : [
61
43
provideMockStore ( { initialState : state } ) ,
62
44
{ provide : ActionsSubject , useValue : actionSub } ,
63
- { provide : FeatureManagerService , useValue : service }
64
45
] ,
65
46
} ) . compileComponents ( ) ;
66
47
} )
@@ -98,27 +79,6 @@ describe('UsersListComponent', () => {
98
79
expect ( component . users ) . toEqual ( state . data ) ;
99
80
} ) ;
100
81
101
- const actionsParams = [
102
- { actionType : UserActionTypes . GRANT_USER_ROLE_SUCCESS } ,
103
- { actionType : UserActionTypes . REVOKE_USER_ROLE_SUCCESS } ,
104
- ] ;
105
-
106
- actionsParams . map ( ( param ) => {
107
- it ( `When action ${ param . actionType } is dispatched should triggered load Users action` , ( ) => {
108
- spyOn ( store , 'dispatch' ) ;
109
-
110
- const actionSubject = TestBed . inject ( ActionsSubject ) as ActionsSubject ;
111
- const action = {
112
- type : param . actionType ,
113
- payload : state . data ,
114
- } ;
115
-
116
- actionSubject . next ( action ) ;
117
-
118
- expect ( store . dispatch ) . toHaveBeenCalledWith ( new LoadUsers ( ) ) ;
119
- } ) ;
120
- } ) ;
121
-
122
82
const actionGroupParams = [
123
83
{ actionType : UserActionTypes . ADD_USER_TO_GROUP_SUCCESS } ,
124
84
{ actionType : UserActionTypes . REMOVE_USER_FROM_GROUP_SUCCESS } ,
@@ -140,26 +100,6 @@ describe('UsersListComponent', () => {
140
100
} ) ;
141
101
} ) ;
142
102
143
- const grantRoleTypes = [
144
- { roleId : 'admin' , roleValue : 'time-tracker-admin' } ,
145
- { roleId : 'test' , roleValue : 'time-tracker-tester' } ,
146
- ] ;
147
-
148
- grantRoleTypes . map ( ( param ) => {
149
- it ( `When user switchRole to ${ param . roleId } and don't have any role, should grant ${ param . roleValue } Role` , ( ) => {
150
- const roleId = param . roleId ;
151
- const roleValue = param . roleValue ;
152
- const userRoles = [ ] ;
153
- const userId = 'userId' ;
154
-
155
- spyOn ( store , 'dispatch' ) ;
156
-
157
- component . switchRole ( userId , userRoles , roleId , roleValue ) ;
158
-
159
- expect ( store . dispatch ) . toHaveBeenCalledWith ( new GrantRoleUser ( userId , roleId ) ) ;
160
- } ) ;
161
- } ) ;
162
-
163
103
const AddGroupTypes = [
164
104
{ groupName : 'time-tracker-admin' } ,
165
105
{ groupName : 'time-tracker-tester' }
@@ -176,7 +116,7 @@ describe('UsersListComponent', () => {
176
116
id : 'id' ,
177
117
tenant_id : 'tenant id' ,
178
118
deleted : 'delete' ,
179
- } ;
119
+ } ;
180
120
181
121
spyOn ( store , 'dispatch' ) ;
182
122
@@ -186,26 +126,6 @@ describe('UsersListComponent', () => {
186
126
} ) ;
187
127
} ) ;
188
128
189
- const revokeRoleTypes = [
190
- { roleId : 'admin' , roleValue : 'time-tracker-admin' , userRoles : [ 'time-tracker-admin' ] } ,
191
- { roleId : 'test' , roleValue : 'time-tracker-tester' , userRoles : [ 'time-tracker-tester' ] } ,
192
- ] ;
193
-
194
- revokeRoleTypes . map ( ( param ) => {
195
- it ( `When user switchRole to ${ param . roleId } and have that rol asigned, should revoke ${ param . roleValue } Role` , ( ) => {
196
- const roleId = param . roleId ;
197
- const roleValue = param . roleValue ;
198
- const userRoles = param . userRoles ;
199
- const userId = 'userId' ;
200
-
201
- spyOn ( store , 'dispatch' ) ;
202
-
203
- component . switchRole ( userId , userRoles , roleId , roleValue ) ;
204
-
205
- expect ( store . dispatch ) . toHaveBeenCalledWith ( new RevokeRoleUser ( userId , roleId ) ) ;
206
- } ) ;
207
- } ) ;
208
-
209
129
const removeGroupTypes = [
210
130
{ groupName : 'time-tracker-admin' , userGroups : [ 'time-tracker-admin' ] } ,
211
131
{ groupName : 'time-tracker-tester' , userGroups : [ 'time-tracker-tester' ] } ,
@@ -222,8 +142,7 @@ describe('UsersListComponent', () => {
222
142
id : 'id' ,
223
143
tenant_id : 'tenant id' ,
224
144
deleted : 'delete' ,
225
- } ;
226
-
145
+ } ;
227
146
228
147
spyOn ( store , 'dispatch' ) ;
229
148
@@ -233,20 +152,6 @@ describe('UsersListComponent', () => {
233
152
} ) ;
234
153
} ) ;
235
154
236
- it ( 'on success load users, the data of roles should be an array' , ( ) => {
237
- const actionSubject = TestBed . inject ( ActionsSubject ) as ActionsSubject ;
238
- const action = {
239
- type : UserActionTypes . LOAD_USERS_SUCCESS ,
240
- payload : state . data ,
241
- } ;
242
-
243
- actionSubject . next ( action ) ;
244
-
245
- component . users . map ( ( user ) => {
246
- expect ( user . roles ) . toEqual ( [ 'admin' , 'test' ] ) ;
247
- } ) ;
248
- } ) ;
249
-
250
155
it ( 'on success load users, the data of groups should be an array' , ( ) => {
251
156
const actionSubject = TestBed . inject ( ActionsSubject ) as ActionsSubject ;
252
157
const action = {
@@ -274,27 +179,6 @@ describe('UsersListComponent', () => {
274
179
expect ( component . dtElement . dtInstance . then ) . toHaveBeenCalled ( ) ;
275
180
} ) ;
276
181
277
- it ( 'When Component is created, should call the feature toggle method' , ( ) => {
278
- spyOn ( component , 'isFeatureToggleActivated' ) . and . returnValue ( of ( true ) ) ;
279
-
280
- component . ngOnInit ( ) ;
281
-
282
- expect ( component . isFeatureToggleActivated ) . toHaveBeenCalled ( ) ;
283
- expect ( component . isUserGroupsToggleOn ) . toBe ( true ) ;
284
- } ) ;
285
-
286
- const toggleValues = [ true , false ] ;
287
- toggleValues . map ( ( toggleValue ) => {
288
- it ( `when FeatureToggle is ${ toggleValue } should return ${ toggleValue } ` , ( ) => {
289
- spyOn ( service , 'isToggleEnabledForUser' ) . and . returnValue ( of ( toggleValue ) ) ;
290
-
291
- const isFeatureToggleActivated : Observable < boolean > = component . isFeatureToggleActivated ( ) ;
292
-
293
- expect ( service . isToggleEnabledForUser ) . toHaveBeenCalled ( ) ;
294
- isFeatureToggleActivated . subscribe ( ( value ) => expect ( value ) . toEqual ( toggleValue ) ) ;
295
- } ) ;
296
- } ) ;
297
-
298
182
afterEach ( ( ) => {
299
183
component . dtTrigger . unsubscribe ( ) ;
300
184
component . loadUsersSubscription . unsubscribe ( ) ;
0 commit comments