diff --git a/src/app/modules/users/components/users-list/users-list.component.spec.ts b/src/app/modules/users/components/users-list/users-list.component.spec.ts index 1eff7f73a..53441835c 100644 --- a/src/app/modules/users/components/users-list/users-list.component.spec.ts +++ b/src/app/modules/users/components/users-list/users-list.component.spec.ts @@ -70,6 +70,27 @@ describe('UsersListComponent', () => { expect(component.users).toEqual(state.data); }); + 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' }, 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 bf4df91c4..8ac50f8b4 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 @@ -34,6 +34,18 @@ 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()); + }); } ngAfterViewInit(): void {