1- import { HttpClient } from '@angular/common/http' ;
21import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service' ;
3- < < < << << HEAD
4- import { waitForAsync , ComponentFixture , TestBed , inject } from '@angular / core / testing ';
5- === === =
62import { waitForAsync , ComponentFixture , TestBed } from '@angular/core/testing' ;
7- >>> >>> > feat : TT - 190 mock test
83import { MockStore , provideMockStore } from '@ngrx/store/testing' ;
94import { NgxPaginationModule } from 'ngx-pagination' ;
105import { UsersListComponent } from './users-list.component' ;
@@ -19,28 +14,20 @@ import {
1914} from '../../store' ;
2015import { ActionsSubject } from '@ngrx/store' ;
2116import { DataTablesModule } from 'angular-datatables' ;
22- import { of } from 'rxjs' ;
23- << << << < HEAD
17+ import { Observable , of } from 'rxjs' ;
2418import { FeatureToggleProvider } from 'src/app/modules/shared/feature-toggles/feature-toggle-provider.service' ;
2519import { AppConfigurationClient } from '@azure/app-configuration' ;
2620import { FeatureFilterProvider } from '../../../shared/feature-toggles/filters/feature-filter-provider.service' ;
2721import { AzureAdB2CService } from '../../../login/services/azure.ad.b2c.service' ;
28- import { FeatureToggleModel } from 'src/app/modules/shared/feature-toggles/feature-toggle.model' ;
29- === === =
30- >>> >>> > feat : TT - 190 mock test
3122
3223describe ( 'UsersListComponent' , ( ) => {
3324 let component : UsersListComponent ;
3425 let fixture : ComponentFixture < UsersListComponent > ;
3526 let store : MockStore < UserState > ;
3627 const actionSub : ActionsSubject = new ActionsSubject ( ) ;
37- < < < << << HEAD
3828 const fakeAppConfigurationConnectionString = 'Endpoint=http://fake.foo;Id=fake.id;Secret=fake.secret' ;
3929 let service : FeatureManagerService ;
4030 let fakeFeatureToggleProvider ;
41- = === ===
42- let featureManagerService : FeatureManagerService ;
43- > >>> >>> feat: TT - 190 mock test
4431
4532 const state : UserState = {
4633 data : [
@@ -60,22 +47,21 @@ describe('UsersListComponent', () => {
6047
6148 beforeEach (
6249 waitForAsync ( ( ) => {
63-
6450 fakeFeatureToggleProvider = new FeatureToggleProvider (
6551 new AppConfigurationClient ( fakeAppConfigurationConnectionString ) ,
6652 new FeatureFilterProvider ( new AzureAdB2CService ( ) )
6753 ) ;
68- //spyOn(fakeFeatureToggleProvider, 'getFeatureToggle').and.returnValue(of(aFeatureToggle));
6954 service = new FeatureManagerService ( fakeFeatureToggleProvider ) ;
7055
7156 TestBed . configureTestingModule ( {
7257 imports : [ NgxPaginationModule , DataTablesModule ] ,
7358 declarations : [ UsersListComponent ] ,
74- providers : [ provideMockStore ( { initialState : state } ) ,
59+ providers : [
60+ provideMockStore ( { initialState : state } ) ,
7561 { provide : ActionsSubject , useValue : actionSub } ,
76- { provide : FeatureManagerService , useValue : service } ] ,
62+ { provide : FeatureManagerService , useValue : service }
63+ ] ,
7764 } ) . compileComponents ( ) ;
78- featureManagerService = TestBed . inject ( FeatureManagerService ) ;
7965 } )
8066 ) ;
8167
@@ -218,7 +204,7 @@ describe('UsersListComponent', () => {
218204 ] ;
219205
220206 removeGroupTypes . map ( ( param ) => {
221- it ( `When user switchGroup to ${ param . groupName } and belongs to group, should remove ${ param . groupName } group to user` , ( ) => {
207+ it ( `When user switchGroup to ${ param . groupName } and belongs to group, should remove ${ param . groupName } group from user` , ( ) => {
222208 const groupName = param . groupName ;
223209 const userGroups = param . userGroups ;
224210 const userId = 'userId' ;
@@ -245,7 +231,7 @@ describe('UsersListComponent', () => {
245231 } ) ;
246232 } ) ;
247233
248- fit ( 'on success load users, the data of groups should be an array' , ( ) => {
234+ it ( 'on success load users, the data of groups should be an array' , ( ) => {
249235 const actionSubject = TestBed . inject ( ActionsSubject ) as ActionsSubject ;
250236 const action = {
251237 type : UserActionTypes . LOAD_USERS_SUCCESS ,
@@ -259,7 +245,7 @@ describe('UsersListComponent', () => {
259245 } ) ;
260246 } ) ;
261247
262- fit ( 'on success load users, the datatable should be reloaded' , async ( ) => {
248+ it ( 'on success load users, the datatable should be reloaded' , async ( ) => {
263249 const actionSubject = TestBed . inject ( ActionsSubject ) ;
264250 const action = {
265251 type : UserActionTypes . LOAD_USERS_SUCCESS ,
@@ -272,32 +258,30 @@ describe('UsersListComponent', () => {
272258 expect ( component . dtElement . dtInstance . then ) . toHaveBeenCalled ( ) ;
273259 } ) ;
274260
275- < < < << << HEAD
276- fit ( 'When Component is created, should call the feature toggle method' , ( ) => {
261+ it ( 'When Component is created, should call the feature toggle method' , ( ) => {
277262 spyOn ( component , 'isFeatureToggleActivated' ) . and . returnValue ( of ( true ) ) ;
278- === = ===
279-
280- fit ( 'When Component is created, should call the feature toggle method' , ( ) => {
281-
282- // spyOn(service, 'getAll').and.callFake( () => {
283- // return of(mockUser);
284- // });
285-
286- spyOn ( component , 'isFeatureToggleActivated' ) . and . callFake ( ( ) => {
287- return of ( true ) ;
288- } ) ;
289- > >>> >>> feat: TT - 190 mock test
290263
291264 component . ngOnInit ( ) ;
292265
293266 expect ( component . isFeatureToggleActivated ) . toHaveBeenCalled ( ) ;
294267 expect ( component . isUserGroupsToggleOn ) . toBe ( true ) ;
295268 } ) ;
296269
270+ const toggleValues = [ true , false ] ;
271+ toggleValues . map ( ( toggleValue ) => {
272+ it ( `when FeatureToggle is ${ toggleValue } should return ${ toggleValue } ` , ( ) => {
273+ spyOn ( service , 'isToggleEnabledForUser' ) . and . returnValue ( of ( toggleValue ) ) ;
274+
275+ const isFeatureToggleActivated : Observable < boolean > = component . isFeatureToggleActivated ( ) ;
276+
277+ expect ( service . isToggleEnabledForUser ) . toHaveBeenCalled ( ) ;
278+ isFeatureToggleActivated . subscribe ( ( value ) => expect ( value ) . toEqual ( toggleValue ) ) ;
279+ } ) ;
280+ } ) ;
281+
297282 afterEach ( ( ) => {
298283 component . dtTrigger . unsubscribe ( ) ;
299284 component . loadUsersSubscription . unsubscribe ( ) ;
300285 fixture . destroy ( ) ;
301286 } ) ;
302-
303287} ) ;
0 commit comments