Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down