Skip to content

Commit c97a58a

Browse files
committed
fix: #569 fix PR comments by Rene
1 parent dd8a73c commit c97a58a

File tree

6 files changed

+28
-26
lines changed

6 files changed

+28
-26
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
<table *ngIf="users" class="table table-sm table-bordered table-striped mb-0" datatable [dtTrigger]="dtTrigger">
22
<thead class="thead-blue">
33
<tr class="d-flex">
4-
<th class="col-3">User Email</th>
5-
<th class="col-3">Names</th>
6-
<th class="col-3">Role</th>
7-
<th class="col-3 text-center">Options</th>
4+
<th class="col-4">User Email</th>
5+
<th class="col-4">Names</th>
6+
<th class="col-4 text-center">Admin Role</th>
87
</tr>
98
</thead>
109
<app-loading-bar *ngIf="isLoading$ | async"></app-loading-bar>
1110
<tbody *ngIf="(isLoading$ | async) === false">
1211
<tr class="d-flex" *ngFor="let user of users">
13-
<td class="col-sm-3">{{ user.email }}</td>
14-
<td class="col-sm-3">{{ user.name }}</td>
15-
<td class="col-sm-3">{{ user.role }}</td>
16-
<td class="col-sm-3 text-center custom-control custom-switch">
17-
<input type="checkbox" class="custom-control-input" id="{{ user.id }}" />
12+
<td class="col-sm-4">{{ user.email }}</td>
13+
<td class="col-sm-4">{{ user.name }}</td>
14+
<td class="col-sm-4 text-center custom-control custom-switch">
15+
<input
16+
type="checkbox"
17+
class="custom-control-input"
18+
id="{{ user.id }}"
19+
[(ngModel)]="user.role"
20+
(change)="switchToAdmin(user.id)"
21+
/>
1822
<label class="custom-control-label" for="{{ user.id }}"></label>
1923
</td>
2024
</tr>

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ import { UsersListComponent } from './users-list.component';
66
import { UserActionTypes, UserState, LoadUsers } from '../../store';
77
import { ActionsSubject } from '@ngrx/store';
88
import { DataTablesModule } from 'angular-datatables';
9-
import { act } from '@ngrx/effects';
109

1110
describe('UsersListComponent', () => {
1211
let component: UsersListComponent;
1312
let fixture: ComponentFixture<UsersListComponent>;
1413
let store: MockStore<UserState>;
1514
const actionSub: ActionsSubject = new ActionsSubject();
1615

17-
const state = {
18-
data: [{ name: 'name', email: 'email', role: 'role', id: 'id', tenand_id: 'tenand id', deleted: 'delete' }],
16+
const state: UserState = {
17+
data: [{ name: 'name', email: 'email', role: 'role', id: 'id', tenant_id: 'tenant id', deleted: 'delete' }],
1918
isLoading: false,
2019
message: '',
2120
};

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AfterViewInit, Component, EventEmitter, Input, OnDestroy, OnInit, Output, ViewChild } from '@angular/core';
1+
import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
22
import { ActionsSubject, select, Store } from '@ngrx/store';
33
import { DataTableDirective } from 'angular-datatables';
44
import { Observable, Subject, Subscription } from 'rxjs';
@@ -52,4 +52,8 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
5252
this.dtTrigger.next();
5353
}
5454
}
55+
56+
switchToAdmin(userId: string) {
57+
console.log('Upcoming change to' + userId);
58+
}
5559
}
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component } from '@angular/core';
22

33
@Component({
44
selector: 'app-users',
55
templateUrl: './users.component.html',
6-
styleUrls: ['./users.component.css']
6+
styleUrls: ['./users.component.css'],
77
})
8-
export class UsersComponent implements OnInit {
9-
10-
constructor() { }
11-
12-
ngOnInit(): void {
13-
}
14-
8+
export class UsersComponent {
9+
constructor() {}
1510
}

src/app/modules/users/store/user.effects.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('UserEffects', () => {
1212
let actions$: Observable<Action>;
1313
let effects: UserEffects;
1414
let service: UsersService;
15-
let toastrService;
15+
let toastrService: ToastrService;
1616
const user = { id: 'id', name: 'name', email: 'email' };
1717

1818
beforeEach(() => {
@@ -30,7 +30,7 @@ describe('UserEffects', () => {
3030
expect(effects).toBeTruthy();
3131
});
3232

33-
it('should return a list of users when the action LOAD_USERS call succeeds', async () => {
33+
it('action type is LOAD_USER_SUCCESS when service is executed sucessfully', async () => {
3434
actions$ = of({ type: UserActionTypes.LOAD_USERS });
3535
const serviceSpy = spyOn(service, 'loadUsers');
3636
serviceSpy.and.returnValue(of(user));
@@ -40,7 +40,7 @@ describe('UserEffects', () => {
4040
});
4141
});
4242

43-
it('should return an error when the action LOAD_USERS call fails', async () => {
43+
it('action type is LOAD_USER_FAIL when service fail in execution', async () => {
4444
actions$ = of({ type: UserActionTypes.LOAD_USERS });
4545
const serviceSpy = spyOn(service, 'loadUsers');
4646
serviceSpy.and.returnValue(throwError({ error: { message: 'fail!' } }));

src/app/modules/users/store/user.reducer.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('userReducer', () => {
1111
expect(state.isLoading).toEqual(true);
1212
});
1313

14-
it('on LoadUserSucess, isLoading is false and state has data', () => {
14+
it('on LoadUserSuccess, isLoading is false and state has data', () => {
1515
const data = [];
1616
const action = new actions.LoadUsersSuccess(data);
1717
const state = userReducer(initialState, action);

0 commit comments

Comments
 (0)