diff --git a/src/app/modules/users/components/users-list/users-list.component.html b/src/app/modules/users/components/users-list/users-list.component.html index 71aa110da..b13c0206f 100644 --- a/src/app/modules/users/components/users-list/users-list.component.html +++ b/src/app/modules/users/components/users-list/users-list.component.html @@ -1,22 +1,23 @@ - - - + + + - + - - - + +
User EmailNamesRolesUser EmailNamesRoles
{{ user.email }}{{ user.name }} + {{ user.email }}{{ user.name }}
{ let component: UsersListComponent; let fixture: ComponentFixture; let store: MockStore; - let featureManagerService: FeatureManagerService; const actionSub: ActionsSubject = new ActionsSubject(); const state: UserState = { @@ -39,7 +36,6 @@ describe('UsersListComponent', () => { declarations: [UsersListComponent], providers: [provideMockStore({ initialState: state }), { provide: ActionsSubject, useValue: actionSub }], }).compileComponents(); - featureManagerService = TestBed.inject(FeatureManagerService); }) ); @@ -75,36 +71,6 @@ describe('UsersListComponent', () => { expect(component.users).toEqual(state.data); }); - it('When Component is created, should call the feature toggle method', () => { - spyOn(component, 'isFeatureToggleActivated').and.returnValue(of(true)); - - component.ngOnInit(); - - expect(component.isFeatureToggleActivated).toHaveBeenCalled(); - expect(component.isUserRoleToggleOn).toBe(true); - }); - - const actionsParams = [ - { actionType: UserActionTypes.GRANT_USER_ROLE_SUCCESS }, - { actionType: UserActionTypes.REVOKE_USER_ROLE_SUCCESS }, - ]; - - actionsParams.map((param) => { - it(`When action ${param.actionType} is dispatched should triggered load Users action`, () => { - spyOn(store, 'dispatch'); - - const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject; - const action = { - type: param.actionType, - payload: state.data, - }; - - actionSubject.next(action); - - expect(store.dispatch).toHaveBeenCalledWith(new LoadUsers()); - }); - }); - const grantRoleTypes = [ { roleId: 'admin', roleValue: 'time-tracker-admin' }, { roleId: 'test', roleValue: 'time-tracker-tester' }, @@ -190,23 +156,7 @@ describe('UsersListComponent', () => { }); }); - const toggleValues = [true, false]; - toggleValues.map((toggleValue) => { - it(`when FeatureToggle is ${toggleValue} should return ${toggleValue}`, () => { - spyOn(featureManagerService, 'isToggleEnabledForUser').and.returnValue(of(toggleValue)); - - const isFeatureToggleActivated: Observable = component.isFeatureToggleActivated(); - - expect(featureManagerService.isToggleEnabledForUser).toHaveBeenCalled(); - isFeatureToggleActivated.subscribe((value) => expect(value).toEqual(toggleValue)); - }); - }); - - /* - TODO: block commented on purpose so that when the tests pass and the Feature toggle is removed, - the table will be rendered again with dtInstance and not with dtOptions - - it('on success load users, the datatable should be reloaded', async () => { + it('on success load users, the datatable should be reloaded', async () => { const actionSubject = TestBed.inject(ActionsSubject); const action = { type: UserActionTypes.LOAD_USERS_SUCCESS, @@ -217,7 +167,7 @@ describe('UsersListComponent', () => { actionSubject.next(action); expect(component.dtElement.dtInstance.then).toHaveBeenCalled(); - });*/ + }); afterEach(() => { component.dtTrigger.unsubscribe(); diff --git a/src/app/modules/users/components/users-list/users-list.component.ts b/src/app/modules/users/components/users-list/users-list.component.ts index 91cfc2e23..bf4df91c4 100644 --- a/src/app/modules/users/components/users-list/users-list.component.ts +++ b/src/app/modules/users/components/users-list/users-list.component.ts @@ -2,11 +2,10 @@ import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular import { ActionsSubject, select, Store } from '@ngrx/store'; import { DataTableDirective } from 'angular-datatables'; import { Observable, Subject, Subscription } from 'rxjs'; -import { delay, filter, map } from 'rxjs/operators'; +import { delay, filter } from 'rxjs/operators'; import { User } from '../../models/users'; import { GrantRoleUser, LoadUsers, RevokeRoleUser, UserActionTypes } from '../../store/user.actions'; import { getIsLoading } from '../../store/user.selectors'; -import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service'; @Component({ selector: 'app-users-list', @@ -22,20 +21,12 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { @ViewChild(DataTableDirective, { static: false }) dtElement: DataTableDirective; dtOptions: any = {}; - isUserRoleToggleOn; - constructor( - private store: Store, - private actionsSubject$: ActionsSubject, - private featureManagerService: FeatureManagerService - ) { + constructor(private store: Store, private actionsSubject$: ActionsSubject) { this.isLoading$ = store.pipe(delay(0), select(getIsLoading)); } ngOnInit(): void { - this.isFeatureToggleActivated().subscribe((flag) => { - this.isUserRoleToggleOn = flag; - }); this.store.dispatch(new LoadUsers()); this.loadUsersSubscription = this.actionsSubject$ .pipe(filter((action: any) => action.type === UserActionTypes.LOAD_USERS_SUCCESS)) @@ -43,19 +34,6 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { this.users = action.payload; this.rerenderDataTable(); }); - - this.switchRoleSubscription = this.actionsSubject$ - .pipe( - filter( - (action: any) => - action.type === UserActionTypes.GRANT_USER_ROLE_SUCCESS || - action.type === UserActionTypes.REVOKE_USER_ROLE_SUCCESS - ) - ) - .subscribe((action) => { - this.store.dispatch(new LoadUsers()); - this.rerenderDataTable(); - }); } ngAfterViewInit(): void { @@ -83,12 +61,4 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { ? this.store.dispatch(new RevokeRoleUser(userId, roleId)) : this.store.dispatch(new GrantRoleUser(userId, roleId)); } - - isFeatureToggleActivated() { - return this.featureManagerService.isToggleEnabledForUser('ui-list-test-users').pipe( - map((enabled) => { - return enabled === true ? true : false; - }) - ); - } }