1- import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service' ;
21import { waitForAsync , ComponentFixture , TestBed } from '@angular/core/testing' ;
32import { MockStore , provideMockStore } from '@ngrx/store/testing' ;
43import { NgxPaginationModule } from 'ngx-pagination' ;
@@ -7,28 +6,17 @@ import {
76 UserActionTypes ,
87 UserState ,
98 LoadUsers ,
10- GrantRoleUser ,
11- RevokeRoleUser ,
129 AddUserToGroup ,
1310 RemoveUserFromGroup ,
1411} from '../../store' ;
15- import { User } from '../../../user/models/user' ;
1612import { ActionsSubject } from '@ngrx/store' ;
1713import { 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' ;
2314
2415describe ( 'UsersListComponent' , ( ) => {
2516 let component : UsersListComponent ;
2617 let fixture : ComponentFixture < UsersListComponent > ;
2718 let store : MockStore < UserState > ;
2819 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 ;
3220
3321 const state : UserState = {
3422 data : [
@@ -48,19 +36,12 @@ describe('UsersListComponent', () => {
4836
4937 beforeEach (
5038 waitForAsync ( ( ) => {
51- fakeFeatureToggleProvider = new FeatureToggleProvider (
52- new AppConfigurationClient ( fakeAppConfigurationConnectionString ) ,
53- new FeatureFilterProvider ( new AzureAdB2CService ( ) )
54- ) ;
55- service = new FeatureManagerService ( fakeFeatureToggleProvider ) ;
56-
5739 TestBed . configureTestingModule ( {
5840 imports : [ NgxPaginationModule , DataTablesModule ] ,
5941 declarations : [ UsersListComponent ] ,
6042 providers : [
6143 provideMockStore ( { initialState : state } ) ,
6244 { provide : ActionsSubject , useValue : actionSub } ,
63- { provide : FeatureManagerService , useValue : service }
6445 ] ,
6546 } ) . compileComponents ( ) ;
6647 } )
@@ -98,27 +79,6 @@ describe('UsersListComponent', () => {
9879 expect ( component . users ) . toEqual ( state . data ) ;
9980 } ) ;
10081
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-
12282 const actionGroupParams = [
12383 { actionType : UserActionTypes . ADD_USER_TO_GROUP_SUCCESS } ,
12484 { actionType : UserActionTypes . REMOVE_USER_FROM_GROUP_SUCCESS } ,
@@ -140,26 +100,6 @@ describe('UsersListComponent', () => {
140100 } ) ;
141101 } ) ;
142102
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-
163103 const AddGroupTypes = [
164104 { groupName : 'time-tracker-admin' } ,
165105 { groupName : 'time-tracker-tester' }
@@ -176,7 +116,7 @@ describe('UsersListComponent', () => {
176116 id : 'id' ,
177117 tenant_id : 'tenant id' ,
178118 deleted : 'delete' ,
179- } ;
119+ } ;
180120
181121 spyOn ( store , 'dispatch' ) ;
182122
@@ -186,26 +126,6 @@ describe('UsersListComponent', () => {
186126 } ) ;
187127 } ) ;
188128
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-
209129 const removeGroupTypes = [
210130 { groupName : 'time-tracker-admin' , userGroups : [ 'time-tracker-admin' ] } ,
211131 { groupName : 'time-tracker-tester' , userGroups : [ 'time-tracker-tester' ] } ,
@@ -222,8 +142,7 @@ describe('UsersListComponent', () => {
222142 id : 'id' ,
223143 tenant_id : 'tenant id' ,
224144 deleted : 'delete' ,
225- } ;
226-
145+ } ;
227146
228147 spyOn ( store , 'dispatch' ) ;
229148
@@ -233,20 +152,6 @@ describe('UsersListComponent', () => {
233152 } ) ;
234153 } ) ;
235154
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-
250155 it ( 'on success load users, the data of groups should be an array' , ( ) => {
251156 const actionSubject = TestBed . inject ( ActionsSubject ) as ActionsSubject ;
252157 const action = {
@@ -274,27 +179,6 @@ describe('UsersListComponent', () => {
274179 expect ( component . dtElement . dtInstance . then ) . toHaveBeenCalled ( ) ;
275180 } ) ;
276181
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-
298182 afterEach ( ( ) => {
299183 component . dtTrigger . unsubscribe ( ) ;
300184 component . loadUsersSubscription . unsubscribe ( ) ;
0 commit comments