Skip to content

Commit 5eda405

Browse files
authored
fix: TT-132 Remove Feature Toggle from User list (#630)
1 parent d198dd0 commit 5eda405

File tree

3 files changed

+13
-92
lines changed

3 files changed

+13
-92
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
<table
2-
*ngIf="users && (isLoading$ | async) === false"
2+
*ngIf="users"
33
class="table table-sm table-bordered table-striped mb-0"
44
datatable
5+
[dtTrigger]="dtTrigger"
56
[dtOptions]="dtOptions"
67
>
78
<thead class="thead-blue">
89
<tr class="d-flex">
9-
<th class="col">User Email</th>
10-
<th class="col">Names</th>
11-
<th class="col" *ngIf="isUserRoleToggleOn">Roles</th>
10+
<th class="col-4">User Email</th>
11+
<th class="col-5">Names</th>
12+
<th class="col-3">Roles</th>
1213
</tr>
1314
</thead>
1415
<app-loading-bar *ngIf="isLoading$ | async"></app-loading-bar>
15-
<tbody *ngIf="(isLoading$ | async) === false">
16+
<tbody>
1617
<tr class="d-flex" *ngFor="let user of users">
17-
<td class="col">{{ user.email }}</td>
18-
<td class="col">{{ user.name }}</td>
19-
<td class="col text-center" *ngIf="isUserRoleToggleOn">
18+
<td class="col-4">{{ user.email }}</td>
19+
<td class="col-5">{{ user.name }}</td>
20+
<td class="col-3 text-center">
2021
<div>
2122
<ui-switch
2223
size="small"

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

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ import { MockStore, provideMockStore } from '@ngrx/store/testing';
44
import { NgxPaginationModule } from 'ngx-pagination';
55
import { UsersListComponent } from './users-list.component';
66
import { UserActionTypes, UserState, LoadUsers, GrantRoleUser, RevokeRoleUser } from '../../store';
7-
import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service';
87
import { ActionsSubject } from '@ngrx/store';
98
import { DataTablesModule } from 'angular-datatables';
10-
import { Observable, of } from 'rxjs';
119

1210
describe('UsersListComponent', () => {
1311
let component: UsersListComponent;
1412
let fixture: ComponentFixture<UsersListComponent>;
1513
let store: MockStore<UserState>;
16-
let featureManagerService: FeatureManagerService;
1714
const actionSub: ActionsSubject = new ActionsSubject();
1815

1916
const state: UserState = {
@@ -39,7 +36,6 @@ describe('UsersListComponent', () => {
3936
declarations: [UsersListComponent],
4037
providers: [provideMockStore({ initialState: state }), { provide: ActionsSubject, useValue: actionSub }],
4138
}).compileComponents();
42-
featureManagerService = TestBed.inject(FeatureManagerService);
4339
})
4440
);
4541

@@ -75,36 +71,6 @@ describe('UsersListComponent', () => {
7571
expect(component.users).toEqual(state.data);
7672
});
7773

78-
it('When Component is created, should call the feature toggle method', () => {
79-
spyOn(component, 'isFeatureToggleActivated').and.returnValue(of(true));
80-
81-
component.ngOnInit();
82-
83-
expect(component.isFeatureToggleActivated).toHaveBeenCalled();
84-
expect(component.isUserRoleToggleOn).toBe(true);
85-
});
86-
87-
const actionsParams = [
88-
{ actionType: UserActionTypes.GRANT_USER_ROLE_SUCCESS },
89-
{ actionType: UserActionTypes.REVOKE_USER_ROLE_SUCCESS },
90-
];
91-
92-
actionsParams.map((param) => {
93-
it(`When action ${param.actionType} is dispatched should triggered load Users action`, () => {
94-
spyOn(store, 'dispatch');
95-
96-
const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject;
97-
const action = {
98-
type: param.actionType,
99-
payload: state.data,
100-
};
101-
102-
actionSubject.next(action);
103-
104-
expect(store.dispatch).toHaveBeenCalledWith(new LoadUsers());
105-
});
106-
});
107-
10874
const grantRoleTypes = [
10975
{ roleId: 'admin', roleValue: 'time-tracker-admin' },
11076
{ roleId: 'test', roleValue: 'time-tracker-tester' },
@@ -190,23 +156,7 @@ describe('UsersListComponent', () => {
190156
});
191157
});
192158

193-
const toggleValues = [true, false];
194-
toggleValues.map((toggleValue) => {
195-
it(`when FeatureToggle is ${toggleValue} should return ${toggleValue}`, () => {
196-
spyOn(featureManagerService, 'isToggleEnabledForUser').and.returnValue(of(toggleValue));
197-
198-
const isFeatureToggleActivated: Observable<boolean> = component.isFeatureToggleActivated();
199-
200-
expect(featureManagerService.isToggleEnabledForUser).toHaveBeenCalled();
201-
isFeatureToggleActivated.subscribe((value) => expect(value).toEqual(toggleValue));
202-
});
203-
});
204-
205-
/*
206-
TODO: block commented on purpose so that when the tests pass and the Feature toggle is removed,
207-
the table will be rendered again with dtInstance and not with dtOptions
208-
209-
it('on success load users, the datatable should be reloaded', async () => {
159+
it('on success load users, the datatable should be reloaded', async () => {
210160
const actionSubject = TestBed.inject(ActionsSubject);
211161
const action = {
212162
type: UserActionTypes.LOAD_USERS_SUCCESS,
@@ -217,7 +167,7 @@ describe('UsersListComponent', () => {
217167
actionSubject.next(action);
218168

219169
expect(component.dtElement.dtInstance.then).toHaveBeenCalled();
220-
});*/
170+
});
221171

222172
afterEach(() => {
223173
component.dtTrigger.unsubscribe();

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

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular
22
import { ActionsSubject, select, Store } from '@ngrx/store';
33
import { DataTableDirective } from 'angular-datatables';
44
import { Observable, Subject, Subscription } from 'rxjs';
5-
import { delay, filter, map } from 'rxjs/operators';
5+
import { delay, filter } from 'rxjs/operators';
66
import { User } from '../../models/users';
77
import { GrantRoleUser, LoadUsers, RevokeRoleUser, UserActionTypes } from '../../store/user.actions';
88
import { getIsLoading } from '../../store/user.selectors';
9-
import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service';
109

1110
@Component({
1211
selector: 'app-users-list',
@@ -22,40 +21,19 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
2221
@ViewChild(DataTableDirective, { static: false })
2322
dtElement: DataTableDirective;
2423
dtOptions: any = {};
25-
isUserRoleToggleOn;
2624

27-
constructor(
28-
private store: Store<User>,
29-
private actionsSubject$: ActionsSubject,
30-
private featureManagerService: FeatureManagerService
31-
) {
25+
constructor(private store: Store<User>, private actionsSubject$: ActionsSubject) {
3226
this.isLoading$ = store.pipe(delay(0), select(getIsLoading));
3327
}
3428

3529
ngOnInit(): void {
36-
this.isFeatureToggleActivated().subscribe((flag) => {
37-
this.isUserRoleToggleOn = flag;
38-
});
3930
this.store.dispatch(new LoadUsers());
4031
this.loadUsersSubscription = this.actionsSubject$
4132
.pipe(filter((action: any) => action.type === UserActionTypes.LOAD_USERS_SUCCESS))
4233
.subscribe((action) => {
4334
this.users = action.payload;
4435
this.rerenderDataTable();
4536
});
46-
47-
this.switchRoleSubscription = this.actionsSubject$
48-
.pipe(
49-
filter(
50-
(action: any) =>
51-
action.type === UserActionTypes.GRANT_USER_ROLE_SUCCESS ||
52-
action.type === UserActionTypes.REVOKE_USER_ROLE_SUCCESS
53-
)
54-
)
55-
.subscribe((action) => {
56-
this.store.dispatch(new LoadUsers());
57-
this.rerenderDataTable();
58-
});
5937
}
6038

6139
ngAfterViewInit(): void {
@@ -83,12 +61,4 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
8361
? this.store.dispatch(new RevokeRoleUser(userId, roleId))
8462
: this.store.dispatch(new GrantRoleUser(userId, roleId));
8563
}
86-
87-
isFeatureToggleActivated() {
88-
return this.featureManagerService.isToggleEnabledForUser('ui-list-test-users').pipe(
89-
map((enabled) => {
90-
return enabled === true ? true : false;
91-
})
92-
);
93-
}
9464
}

0 commit comments

Comments
 (0)