Skip to content

Commit a16ff59

Browse files
authored
fix: TT-143 Add a loadUsers action after grant or revoke user role (#634)
1 parent f462603 commit a16ff59

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/app/modules/users/components/users-list/users-list.component.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,27 @@ describe('UsersListComponent', () => {
7070
expect(component.users).toEqual(state.data);
7171
});
7272

73+
const actionsParams = [
74+
{ actionType: UserActionTypes.GRANT_USER_ROLE_SUCCESS },
75+
{ actionType: UserActionTypes.REVOKE_USER_ROLE_SUCCESS },
76+
];
77+
78+
actionsParams.map((param) => {
79+
it(`When action ${param.actionType} is dispatched should triggered load Users action`, () => {
80+
spyOn(store, 'dispatch');
81+
82+
const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject;
83+
const action = {
84+
type: param.actionType,
85+
payload: state.data,
86+
};
87+
88+
actionSubject.next(action);
89+
90+
expect(store.dispatch).toHaveBeenCalledWith(new LoadUsers());
91+
});
92+
});
93+
7394
const grantRoleTypes = [
7495
{ roleId: 'admin', roleValue: 'time-tracker-admin' },
7596
{ roleId: 'test', roleValue: 'time-tracker-tester' },

src/app/modules/users/components/users-list/users-list.component.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
3434
this.users = action.payload;
3535
this.rerenderDataTable();
3636
});
37+
38+
this.switchRoleSubscription = this.actionsSubject$
39+
.pipe(
40+
filter(
41+
(action: any) =>
42+
action.type === UserActionTypes.GRANT_USER_ROLE_SUCCESS ||
43+
action.type === UserActionTypes.REVOKE_USER_ROLE_SUCCESS
44+
)
45+
)
46+
.subscribe((action) => {
47+
this.store.dispatch(new LoadUsers());
48+
});
3749
}
3850

3951
ngAfterViewInit(): void {

0 commit comments

Comments
 (0)